Skip to content

Commit

Permalink
Add support for ARM docker images generation
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Turrado <jorge.turrado@docplanner.com>
  • Loading branch information
Jorge Turrado committed Jan 11, 2022
1 parent a592153 commit 19fafe3
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 32 deletions.
1 change: 1 addition & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ RUN apt-get update \
&& add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/$(lsb_release -is | tr '[:upper:]' '[:lower:]') $(lsb_release -cs) stable" \
&& apt-get update \
&& apt-get install -y docker-ce-cli \
&& docker buildx create --use \
#
# Install pip & pre-commit
&& apt-get -y install python3-pip \
Expand Down
48 changes: 36 additions & 12 deletions .github/workflows/main-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ on:
push:
branches:
- main
concurrency: e2e-tests
jobs:
validate-upgrade:
uses: kedacore/keda/.github/workflows/upgrade-validation-template.yml@main
Expand All @@ -12,8 +11,8 @@ jobs:
secrets:
registryPAT: ${{ secrets.GHCR_AUTH_PAT }}

validate:
name: Validate
build:
name: build
runs-on: ubuntu-latest
# build-tools is built from ../../tools/build-tools.Dockerfile
container: ghcr.io/kedacore/build-tools:main
Expand Down Expand Up @@ -56,17 +55,21 @@ jobs:
# Server address of Docker registry. If not set then will default to Docker Hub
registry: ghcr.io

- name: Login to Docker Hub
env:
DOCKER_HUB_ACCESS_TOKEN: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
run: echo $DOCKER_HUB_ACCESS_TOKEN | docker login -u $DOCKER_HUB_USERNAME --password-stdin

- name: Publish on GitHub Container Registry
run: make publish
run: make publish-multiarch

- name: Publish on Docker Hub
run: make publish-dockerhub
validate:
needs: build
name: validate
runs-on: ubuntu-latest
# build-tools is built from ../../tools/build-tools.Dockerfile
container: ghcr.io/kedacore/build-tools:main
concurrency: e2e-tests
steps:
- name: Check out code
uses: actions/checkout@v2
with:
fetch-depth: 1

- name: Run end to end tests
env:
Expand All @@ -93,3 +96,24 @@ jobs:
TEST_LOG_ANALYTICS_WORKSPACE_ID: ${{ secrets.TEST_LOG_ANALYTICS_WORKSPACE_ID }}
TEST_STORAGE_CONNECTION_STRING: ${{ secrets.TEST_STORAGE_CONNECTION_STRING }}
run: make e2e-test

validate-arm64:
needs: build
name: validate-arm64
runs-on: ARM64
container: arm64v8/ubuntu:focal
steps:
- name: Check out code
uses: actions/checkout@v2
with:
fetch-depth: 1

- name: Create k8s v1.23 Kind Cluster
uses: helm/kind-action@v1.2.0
with:
node_image: kindest/node:v1.23.0@sha256:49824ab1727c04e56a21a5d8372a402fcd32ea51ac96a2706a12af38934f81ac

- name: Deploy current version
run : make deploy

# Add smoke test here
2 changes: 1 addition & 1 deletion .github/workflows/pr-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
registry: ghcr.io

- name: Publish on GitHub Container Registry
run: make publish
run: make publish-multiarch
env:
E2E_IMAGE_TAG: "pr-${{ steps.checkout.outputs.pr_num }}"

Expand Down
13 changes: 1 addition & 12 deletions .github/workflows/release-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@ jobs:
# Server address of Docker registry. If not set then will default to Docker Hub
registry: ghcr.io

- name: Login to Docker Hub
env:
DOCKER_HUB_ACCESS_TOKEN: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
run: echo $DOCKER_HUB_ACCESS_TOKEN | docker login -u $DOCKER_HUB_USERNAME --password-stdin

- name: Get the version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/v}
Expand All @@ -61,12 +55,7 @@ jobs:
VERSION: ${{ steps.get_version.outputs.VERSION }}

- name: Publish KEDA images on GitHub Container Registry
run: make publish
env:
VERSION: ${{ steps.get_version.outputs.VERSION }}

- name: Publish KEDA images on Docker Hub
run: make publish-dockerhub
run: make publish-multiarch
env:
VERSION: ${{ steps.get_version.outputs.VERSION }}

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
- ScaledJob: introduce `RolloutStrategy` ([#2164](https://github.com/kedacore/keda/pull/2164))
- Add ScalersCache to reuse scalers unless they need changing ([#2187](https://github.com/kedacore/keda/pull/2187))
- Cache metric names provided by KEDA Metrics Server ([#2279](https://github.com/kedacore/keda/pull/2279))
- Automatically release container image for ARM ([#2457](https://github.com/kedacore/keda/pull/2457))

### Improvements

Expand Down
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Build the manager binary
FROM golang:1.17.3 as builder
FROM --platform=$BUILDPLATFORM golang:1.17.3 AS builder

ARG BUILD_VERSION=main
ARG GIT_COMMIT=HEAD
Expand All @@ -26,7 +25,9 @@ COPY controllers/ controllers/
COPY pkg/ pkg/

# Build
RUN VERSION=${BUILD_VERSION} GIT_COMMIT=${GIT_COMMIT} GIT_VERSION=${GIT_VERSION} make manager
# https://www.docker.com/blog/faster-multi-platform-builds-dockerfile-cross-compilation-guide/
ARG TARGETOS TARGETARCH
RUN VERSION=${BUILD_VERSION} GIT_COMMIT=${GIT_COMMIT} GIT_VERSION=${GIT_VERSION} TARGET_OS=$TARGETOS ARCH=$TARGETARCH make manager

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
Expand Down
8 changes: 5 additions & 3 deletions Dockerfile.adapter
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the adapter binary
FROM golang:1.17.3 as builder
FROM --platform=$BUILDPLATFORM golang:1.17.3 as builder

ARG BUILD_VERSION=main
ARG GIT_COMMIT=HEAD
Expand Down Expand Up @@ -28,11 +28,13 @@ COPY pkg/ pkg/
RUN mkdir -p /apiserver.local.config/certificates && chmod -R 777 /apiserver.local.config

# Build
RUN VERSION=${BUILD_VERSION} GIT_COMMIT=${GIT_COMMIT} GIT_VERSION=${GIT_VERSION} make adapter
# https://www.docker.com/blog/faster-multi-platform-builds-dockerfile-cross-compilation-guide/
ARG TARGETOS TARGETARCH
RUN VERSION=${BUILD_VERSION} GIT_COMMIT=${GIT_COMMIT} GIT_VERSION=${GIT_VERSION} TARGET_OS=$TARGETOS ARCH=$TARGETARCH make adapter

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot
FROM --platform=$BUILDPLATFORM gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=builder --chown=nonroot:nonroot /apiserver.local.config /apiserver.local.config
COPY --from=builder /workspace/bin/keda-adapter .
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ publish-dockerhub: ## Mirror images on Docker Hub.
docker push docker.io/$(IMAGE_REPO)/keda:$(VERSION)
docker push docker.io/$(IMAGE_REPO)/keda-metrics-apiserver:$(VERSION)

publish-multiarch:
docker buildx build --push --platform=linux/amd64,linux/arm64 . -t ${IMAGE_CONTROLLER} --build-arg BUILD_VERSION=${VERSION} --build-arg GIT_VERSION=${GIT_VERSION} --build-arg GIT_COMMIT=${GIT_COMMIT}
docker buildx build --push --platform=linux/amd64,linux/arm64 -f Dockerfile.adapter -t ${IMAGE_ADAPTER} . --build-arg BUILD_VERSION=${VERSION} --build-arg GIT_VERSION=${GIT_VERSION} --build-arg GIT_COMMIT=${GIT_COMMIT}

release: manifests kustomize set-version ## Produce new KEDA release in keda-$(VERSION).yaml file.
cd config/manager && \
$(KUSTOMIZE) edit set image ghcr.io/kedacore/keda=${IMAGE_CONTROLLER}
Expand Down
3 changes: 2 additions & 1 deletion tools/build-tools.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ RUN curl -LO https://download.docker.com/linux/static/stable/x86_64/docker-19.03
echo "$docker_sha256 docker-19.03.2.tgz" | sha256sum -c - && \
tar xvzf docker-19.03.2.tgz && \
mv docker/* /usr/local/bin && \
rm -rf docker docker-19.03.2.tgz
rm -rf docker docker-19.03.2.tgz && \
docker buildx create --use

# Install golang
RUN GO_VERSION=1.17.3 && \
Expand Down

0 comments on commit 19fafe3

Please sign in to comment.