Skip to content

Commit

Permalink
Merge pull request #2 from cybernop/feature/restructure-build-process
Browse files Browse the repository at this point in the history
reduce unnessecary images and build-steps, also provide all changes t…
  • Loading branch information
cybernop authored Oct 10, 2024
2 parents 1efeb15 + 6e592aa commit ded5bd8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 148 deletions.
161 changes: 27 additions & 134 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,130 +16,18 @@ env:
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
SUSHI_VERSION: "3.11.0"
TARGET_PLATFORMS: linux/amd64,linux/arm64
LATEST_SUSHI: "3.11.0"
MAIN_OS: "alpine"

jobs:
node-base:
name: Node Base
runs-on: ubuntu-latest
strategy:
matrix:
base: [alpine, ubuntu]
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Adds static libs for multi-platform builds
- name: Setup QEMU
uses: docker/setup-qemu-action@v3

- name: Setup Docker buildx
uses: docker/setup-buildx-action@v3
with:
platforms: ${{ env.TARGET_PLATFORMS }}

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/node
tags: |
${{ matrix.base }}
# Build and push Docker image with Buildx (push on tag)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v4
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
target: node-${{ matrix.base }}

pub-base:
name: IG Publisher Base
needs: node-base
runs-on: ubuntu-latest
strategy:
matrix:
base: [alpine, ubuntu]
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Adds static libs for multi-platform builds
- name: Setup QEMU
uses: docker/setup-qemu-action@v3

- name: Setup Docker buildx
uses: docker/setup-buildx-action@v3
with:
platforms: ${{ env.TARGET_PLATFORMS }}

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/pub-base
tags: |
${{ matrix.base }}
# Build and push Docker image with Buildx (push on tag)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v4
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
target: pub-base-${{ matrix.base }}

sushi:
name: FSH Sushi
needs: node-base
runs-on: ubuntu-latest
strategy:
matrix:
base: [alpine, ubuntu]
os: [alpine, ubuntu]
sushi: ["2.10.2", "3.0.0", "3.5.0", "3.10.0", "3.11.0", "3.11.1"]
permissions:
contents: read
packages: write
Expand All @@ -149,7 +37,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

# Adds static libs for multi-platform builds
- name: Setup QEMU
Expand All @@ -163,7 +51,7 @@ jobs:
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
Expand All @@ -173,31 +61,34 @@ jobs:
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v4
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/fsh-sushi
tags: |
${{ env.SUSHI_VERSION }}-${{ matrix.base }}
type=raw,value=${{ matrix.sushi }}-${{ matrix.os }}
type=raw,value=${{ matrix.os }},enable=${{ matrix.sushi == env.LATEST_SUSHI }}
type=raw,value=latest,enable=${{ matrix.sushi == env.LATEST_SUSHI && matrix.os == env.MAIN_OS }}
# Build and push Docker image with Buildx (push on tag)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
push: true
push: ${{ github.ref_name == 'main'}}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
target: fsh-sushi-${{ matrix.base }}
build-args: SUSHI_VERSION=${{ env.SUSHI_VERSION }}
target: fsh-sushi-${{ matrix.os }}
build-args: SUSHI_VERSION=${{ matrix.sushi }}

ig-publisher:
name: IG Publisher
needs: [node-base, pub-base]
needs: sushi
runs-on: ubuntu-latest
strategy:
matrix:
base: [alpine, ubuntu]
os: [alpine, ubuntu]
sushi: ["2.10.2", "3.0.0", "3.5.0", "3.10.0", "3.11.0", "3.11.1"]
permissions:
contents: read
packages: write
Expand All @@ -207,7 +98,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

# Adds static libs for multi-platform builds
- name: Setup QEMU
Expand All @@ -221,7 +112,7 @@ jobs:
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
Expand All @@ -231,20 +122,22 @@ jobs:
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v4
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/ig-publisher
tags: |
${{ env.SUSHI_VERSION }}-${{ matrix.base }}
type=raw,value=${{ matrix.sushi }}-${{ matrix.os }}
type=raw,value=${{ matrix.os }},enable=${{ matrix.sushi == env.LATEST_SUSHI }}
type=raw,value=latest,enable=${{ matrix.sushi == env.LATEST_SUSHI && matrix.os == env.MAIN_OS }}
# Build and push Docker image with Buildx (push on tag)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
push: true
push: ${{ github.ref_name == 'main'}}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
target: ig-publisher-${{ matrix.base }}
build-args: SUSHI_VERSION=${{ env.SUSHI_VERSION }}
target: ig-publisher-${{ matrix.os }}
build-args: SUSHI_VERSION=${{ matrix.sushi }}
24 changes: 10 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
### NODE ALPINE
FROM mcr.microsoft.com/devcontainers/base:alpine as node-alpine
ARG SUSHI_VERSION=

### SUSHI ALPINE
FROM mcr.microsoft.com/devcontainers/base:alpine as fsh-sushi-alpine
RUN apk update \
&& apk add nodejs npm
# Update sources for nodejs
# RUN curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
# RUN apt update \
# && apt install -y \
# nodejs
ARG SUSHI_VERSION=
RUN npm install -g fsh-sushi@${SUSHI_VERSION}

### NODE UBUNTU
FROM mcr.microsoft.com/devcontainers/base:ubuntu as node-ubuntu
### SUSHI UBUNTU
FROM mcr.microsoft.com/devcontainers/base:ubuntu as fsh-sushi-ubuntu
# Update sources for nodejs
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
RUN apt update \
&& apt install -y \
nodejs

### SUSHI ALPINE
FROM ghcr.io/cybernop/vscode-fhir-devcontainer/node:alpine as fsh-sushi-alpine
ARG SUSHI_VERSION=
RUN npm install -g fsh-sushi@${SUSHI_VERSION}

### SUSHI UBUNTU
FROM ghcr.io/cybernop/vscode-fhir-devcontainer/node:ubuntu as fsh-sushi-ubuntu
ARG SUSHI_VERSION=
RUN npm install -g fsh-sushi@${SUSHI_VERSION}

### PUB BASE ALPINE
FROM ghcr.io/cybernop/vscode-fhir-devcontainer/node:alpine AS pub-base-alpine
FROM ghcr.io/cybernop/vscode-fhir-devcontainer/fsh-sushi:${SUSHI_VERSION}-alpine AS pub-base-alpine
RUN apk update \
&& apk add --no-cache \
linux-headers \
Expand All @@ -44,7 +40,7 @@ RUN wget -q -P /workspaces https://github.com/hapifhir/org.hl7.fhir.core/release
&& chmod a+x /workspaces/validate.sh

### RUB BASE UBUNTU
FROM ghcr.io/cybernop/vscode-fhir-devcontainer/node:ubuntu AS pub-base-ubuntu
FROM ghcr.io/cybernop/vscode-fhir-devcontainer/fsh-sushi:${SUSHI_VERSION}-ubuntu AS pub-base-ubuntu
RUN apt update \
&& apt install -y \
openjdk-17-jdk \
Expand Down

0 comments on commit ded5bd8

Please sign in to comment.