Skip to content

Commit

Permalink
Implement multi-platform container images
Browse files Browse the repository at this point in the history
  • Loading branch information
mtneug committed Jan 26, 2024
1 parent 25e5a9b commit 4a3d01f
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 89 deletions.
28 changes: 14 additions & 14 deletions .github/workflows/container-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ on:
push:
branches:
- main
- dev
pull_request:
branches:
- main

jobs:
build-and-push-images:
Expand All @@ -18,26 +20,24 @@ jobs:
- uses: actions/checkout@v4

- uses: docker/login-action@v3
if: ${{ github.event_name == 'push' }}
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: set up Docker buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3
with:
# TODO: build multi-plattform container images
platforms: linux/amd64
platforms: linux/amd64,linux/arm,linux/arm64,linux/ppc64le,linux/s390x

- name: build and push container images
run: |
make image OS=linux ARCH=amd64
docker push ghcr.io/nagare-media/engine/function-mmsys-test-encode:dev
docker push ghcr.io/nagare-media/engine/function-noop:dev
docker push ghcr.io/nagare-media/engine/function-sleep:dev
docker push ghcr.io/nagare-media/engine/gateway-nbmp:dev
docker push ghcr.io/nagare-media/engine/workflow-manager:dev
docker push ghcr.io/nagare-media/engine/workflow-manager-helper:dev
docker push ghcr.io/nagare-media/engine/workflow-opentelemetry-adapter:dev
docker push ghcr.io/nagare-media/engine/workflow-vacuum:dev
case "${{ github.event_name }}" in
push) BUILDX_OUTPUT='--push' ;;
*) BUILDX_OUTPUT='' ;;
esac
make image \
IMAGE_PLATFORMS=linux/amd64,linux/arm,linux/arm64,linux/ppc64le,linux/s390x \
BUILDX_OUTPUT="${BUILDX_OUTPUT}"
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ GIT_COMMIT ?= $(shell git rev-parse --short HEAD || echo "unknown")
GIT_TREE_STATE ?= $(shell sh -c 'if test -z "$$(git status --porcelain 2>/dev/null)"; then echo clean; else echo dirty; fi')
BUILD_DATE ?= $(shell date -u +"%Y-%m-%dT%TZ")

IMAGE_REGISTRY ?= $(shell cat build/package/image/IMAGE_REGISTRY)
IMAGE_TAG ?= $(VERSION)
IMAGE_REGISTRY ?= $(shell cat build/package/image/IMAGE_REGISTRY)
IMAGE_TAG ?= $(VERSION)
IMAGE_PLATFORMS ?= "" # by default only ${OS}/${ARCH} is built
BUILDX_OUTPUT ?= "--load"

TESTENV_K8S_VERSION ?= 1.28.0
TESTENV_INGRESS_NGINX_VERSION ?= 4.7.1 # Helm chart versions
Expand Down Expand Up @@ -215,10 +217,12 @@ image-%:
GOVERSION="$(GOVERSION)" \
OS="$(OS)" \
ARCH="$(ARCH)" \
PLATFORMS="$(IMAGE_PLATFORMS)" \
VERSION="$(VERSION)" \
GIT_COMMIT="$(GIT_COMMIT)" \
GIT_TREE_STATE="$(GIT_TREE_STATE)" \
BUILD_DATE="$(BUILD_DATE)" \
BUILDX_OUTPUT="$(BUILDX_OUTPUT)" \
scripts/exec-local image

##@ Deployment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
COPY . .

# BUILD_DATE changes ofter so move this section down to allow for caching
ARG OS \
ARCH \
ARG TARGETOS \
TARGETARCH \
VERSION \
GIT_COMMIT \
GIT_TREE_STATE \
Expand All @@ -24,15 +24,15 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/app/tmp \
make build-task-shim \
"OS=${OS}" \
"ARCH=${ARCH}" \
"OS=${TARGETOS}" \
"ARCH=${TARGETARCH}" \
"VERSION=${VERSION}" \
"GIT_COMMIT=${GIT_COMMIT}" \
"GIT_TREE_STATE=${GIT_TREE_STATE}" \
"BUILD_DATE=${BUILD_DATE}" \
&& make build-functions \
"OS=${OS}" \
"ARCH=${ARCH}" \
"OS=${TARGETOS}" \
"ARCH=${TARGETARCH}" \
"VERSION=${VERSION}" \
"GIT_COMMIT=${GIT_COMMIT}" \
"GIT_TREE_STATE=${GIT_TREE_STATE}" \
Expand All @@ -51,8 +51,8 @@ RUN apt-get update \

ENV GOTRACEBACK=all

ARG OS \
ARCH \
ARG TARGETOS \
TARGETARCH \
VERSION \
GIT_COMMIT \
BUILD_DATE
Expand All @@ -72,8 +72,8 @@ LABEL maintainer="Matthias Neugebauer <mtneug@mailbox.org>" \
org.opencontainers.image.base.name="docker.io/ubuntu:23.04"

WORKDIR /
COPY --from=build "/app/bin/task-shim-${VERSION}-${OS}-${ARCH}" /task-shim
COPY --from=build "/app/bin/functions-${VERSION}-${OS}-${ARCH}" /mmsys-test-encode
COPY --from=build "/app/bin/task-shim-${VERSION}-${TARGETOS}-${TARGETARCH}" /task-shim
COPY --from=build "/app/bin/functions-${VERSION}-${TARGETOS}-${TARGETARCH}" /mmsys-test-encode
USER 65532:65532

COPY <<EOF /config/task-shim.yaml
Expand Down
20 changes: 10 additions & 10 deletions build/package/image/function-noop/Dockerfile.generic.generic
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
COPY . .

# BUILD_DATE changes ofter so move this section down to allow for caching
ARG OS \
ARCH \
ARG TARGETOS \
TARGETARCH \
VERSION \
GIT_COMMIT \
GIT_TREE_STATE \
Expand All @@ -24,15 +24,15 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/app/tmp \
make build-task-shim \
"OS=${OS}" \
"ARCH=${ARCH}" \
"OS=${TARGETOS}" \
"ARCH=${TARGETARCH}" \
"VERSION=${VERSION}" \
"GIT_COMMIT=${GIT_COMMIT}" \
"GIT_TREE_STATE=${GIT_TREE_STATE}" \
"BUILD_DATE=${BUILD_DATE}" \
&& make build-functions \
"OS=${OS}" \
"ARCH=${ARCH}" \
"OS=${TARGETOS}" \
"ARCH=${TARGETARCH}" \
"VERSION=${VERSION}" \
"GIT_COMMIT=${GIT_COMMIT}" \
"GIT_TREE_STATE=${GIT_TREE_STATE}" \
Expand All @@ -42,8 +42,8 @@ FROM gcr.io/distroless/static:latest

ENV GOTRACEBACK=all

ARG OS \
ARCH \
ARG TARGETOS \
TARGETARCH \
VERSION \
GIT_COMMIT \
BUILD_DATE
Expand All @@ -63,8 +63,8 @@ LABEL maintainer="Matthias Neugebauer <mtneug@mailbox.org>" \
org.opencontainers.image.base.name="gcr.io/distroless/static:latest"

WORKDIR /
COPY --from=build "/app/bin/task-shim-${VERSION}-${OS}-${ARCH}" /task-shim
COPY --from=build "/app/bin/functions-${VERSION}-${OS}-${ARCH}" /noop
COPY --from=build "/app/bin/task-shim-${VERSION}-${TARGETOS}-${TARGETARCH}" /task-shim
COPY --from=build "/app/bin/functions-${VERSION}-${TARGETOS}-${TARGETARCH}" /noop
USER 65532:65532

COPY <<EOF /config/task-shim.yaml
Expand Down
20 changes: 10 additions & 10 deletions build/package/image/function-sleep/Dockerfile.generic.generic
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
COPY . .

# BUILD_DATE changes ofter so move this section down to allow for caching
ARG OS \
ARCH \
ARG TARGETOS \
TARGETARCH \
VERSION \
GIT_COMMIT \
GIT_TREE_STATE \
Expand All @@ -24,15 +24,15 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/app/tmp \
make build-task-shim \
"OS=${OS}" \
"ARCH=${ARCH}" \
"OS=${TARGETOS}" \
"ARCH=${TARGETARCH}" \
"VERSION=${VERSION}" \
"GIT_COMMIT=${GIT_COMMIT}" \
"GIT_TREE_STATE=${GIT_TREE_STATE}" \
"BUILD_DATE=${BUILD_DATE}" \
&& make build-functions \
"OS=${OS}" \
"ARCH=${ARCH}" \
"OS=${TARGETOS}" \
"ARCH=${TARGETARCH}" \
"VERSION=${VERSION}" \
"GIT_COMMIT=${GIT_COMMIT}" \
"GIT_TREE_STATE=${GIT_TREE_STATE}" \
Expand All @@ -42,8 +42,8 @@ FROM gcr.io/distroless/static:latest

ENV GOTRACEBACK=all

ARG OS \
ARCH \
ARG TARGETOS \
TARGETARCH \
VERSION \
GIT_COMMIT \
BUILD_DATE
Expand All @@ -63,8 +63,8 @@ LABEL maintainer="Matthias Neugebauer <mtneug@mailbox.org>" \
org.opencontainers.image.base.name="gcr.io/distroless/static:latest"

WORKDIR /
COPY --from=build "/app/bin/task-shim-${VERSION}-${OS}-${ARCH}" /task-shim
COPY --from=build "/app/bin/functions-${VERSION}-${OS}-${ARCH}" /sleep
COPY --from=build "/app/bin/task-shim-${VERSION}-${TARGETOS}-${TARGETARCH}" /task-shim
COPY --from=build "/app/bin/functions-${VERSION}-${TARGETOS}-${TARGETARCH}" /sleep
USER 65532:65532

COPY <<EOF /config/task-shim.yaml
Expand Down
14 changes: 7 additions & 7 deletions build/package/image/gateway-nbmp/Dockerfile.generic.generic
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
COPY . .

# BUILD_DATE changes ofter so move this section down to allow for caching
ARG OS \
ARCH \
ARG TARGETOS \
TARGETARCH \
VERSION \
GIT_COMMIT \
GIT_TREE_STATE \
Expand All @@ -22,8 +22,8 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/app/tmp \
make build-gateway-nbmp \
"OS=${OS}" \
"ARCH=${ARCH}" \
"OS=${TARGETOS}" \
"ARCH=${TARGETARCH}" \
"VERSION=${VERSION}" \
"GIT_COMMIT=${GIT_COMMIT}" \
"GIT_TREE_STATE=${GIT_TREE_STATE}" \
Expand All @@ -33,8 +33,8 @@ FROM gcr.io/distroless/static:latest

ENV GOTRACEBACK=all

ARG OS \
ARCH \
ARG TARGETOS \
TARGETARCH \
VERSION \
GIT_COMMIT \
BUILD_DATE
Expand All @@ -54,7 +54,7 @@ LABEL maintainer="Matthias Neugebauer <mtneug@mailbox.org>" \
org.opencontainers.image.base.name="gcr.io/distroless/static:latest"

WORKDIR /
COPY --from=build "/app/bin/gateway-nbmp-${VERSION}-${OS}-${ARCH}" /gateway-nbmp
COPY --from=build "/app/bin/gateway-nbmp-${VERSION}-${TARGETOS}-${TARGETARCH}" /gateway-nbmp
USER 65532:65532

# NBMP Workflow API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
COPY . .

# BUILD_DATE changes ofter so move this section down to allow for caching
ARG OS \
ARCH \
ARG TARGETOS \
TARGETARCH \
VERSION \
GIT_COMMIT \
GIT_TREE_STATE \
Expand All @@ -24,8 +24,8 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/app/tmp \
make build-workflow-manager-helper \
"OS=${OS}" \
"ARCH=${ARCH}" \
"OS=${TARGETOS}" \
"ARCH=${TARGETARCH}" \
"VERSION=${VERSION}" \
"GIT_COMMIT=${GIT_COMMIT}" \
"GIT_TREE_STATE=${GIT_TREE_STATE}" \
Expand All @@ -35,8 +35,8 @@ FROM gcr.io/distroless/static:latest

ENV GOTRACEBACK=all

ARG OS \
ARCH \
ARG TARGETOS \
TARGETARCH \
VERSION \
GIT_COMMIT \
BUILD_DATE
Expand All @@ -56,7 +56,7 @@ LABEL maintainer="Matthias Neugebauer <mtneug@mailbox.org>" \
org.opencontainers.image.base.name="gcr.io/distroless/static:latest"

WORKDIR /
COPY --from=build "/app/bin/workflow-manager-helper-${VERSION}-${OS}-${ARCH}" /workflow-manager-helper
COPY --from=build "/app/bin/workflow-manager-helper-${VERSION}-${TARGETOS}-${TARGETARCH}" /workflow-manager-helper
USER 65532:65532

COPY <<EOF /config/workflow-manager-helper.yaml
Expand Down
14 changes: 7 additions & 7 deletions build/package/image/workflow-manager/Dockerfile.generic.generic
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
COPY . .

# BUILD_DATE changes ofter so move this section down to allow for caching
ARG OS \
ARCH \
ARG TARGETOS \
TARGETARCH \
VERSION \
GIT_COMMIT \
GIT_TREE_STATE \
Expand All @@ -22,8 +22,8 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/app/tmp \
make build-workflow-manager \
"OS=${OS}" \
"ARCH=${ARCH}" \
"OS=${TARGETOS}" \
"ARCH=${TARGETARCH}" \
"VERSION=${VERSION}" \
"GIT_COMMIT=${GIT_COMMIT}" \
"GIT_TREE_STATE=${GIT_TREE_STATE}" \
Expand All @@ -33,8 +33,8 @@ FROM gcr.io/distroless/static:latest

ENV GOTRACEBACK=all

ARG OS \
ARCH \
ARG TARGETOS \
TARGETARCH \
VERSION \
GIT_COMMIT \
BUILD_DATE
Expand All @@ -54,7 +54,7 @@ LABEL maintainer="Matthias Neugebauer <mtneug@mailbox.org>" \
org.opencontainers.image.base.name="gcr.io/distroless/static:latest"

WORKDIR /
COPY --from=build "/app/bin/workflow-manager-${VERSION}-${OS}-${ARCH}" /workflow-manager
COPY --from=build "/app/bin/workflow-manager-${VERSION}-${TARGETOS}-${TARGETARCH}" /workflow-manager
USER 65532:65532

# metrics
Expand Down
Loading

0 comments on commit 4a3d01f

Please sign in to comment.