Skip to content

Commit

Permalink
Support for multi-arch (x86 + ARM64) images
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeChannings committed Feb 13, 2024
1 parent 58d38d5 commit eb212bf
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 42 deletions.
83 changes: 42 additions & 41 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,91 +6,92 @@ jobs:
build-bin:
name: bin
runs-on: ubuntu-22.04-xl
services:
# Docker save / load does not support multi-arch images.
# This sets up a local registry that I can push the images to.
registry:
image: registry:2
ports:
- 5000:5000
env:
REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY: /var/lib/registry
volumes:
# The images pushed to the local registry will be persisted for this workflow.
- ${{github.workspace}}/registry:/var/lib/registry
steps:
- name: Clone repository
uses: actions/checkout@v4

- name: Build and export image
run: |
docker build -f bin.dockerfile -t bin .
docker save bin -o /tmp/bin-image.tar
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: bin-image
path: /tmp/bin-image.tar
- name: Build image
run: |
docker buildx build -f bin.dockerfile --platform=linux/amd64,linux/arm64 -t registry:5000/bin --push .
build:
needs: build-bin
name: ${{ matrix.kind }}
runs-on: ubuntu-22.04-xl
services:
# Service containers are spun up for each job, so it needs to be run again.
registry:
image: registry:2
ports:
- 5000:5000
env:
REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY: /var/lib/registry
volumes:
- ${{github.workspace}}/registry:/var/lib/registry
strategy:
matrix:
kind: ["alpine", "centos", "debian", "distroless", "ubuntu"]
steps:
- name: Clone repository
uses: actions/checkout@v4

- name: Download bin image artifact
uses: actions/download-artifact@v4
with:
name: bin-image
path: /tmp

- name: Load bin image
run: |
docker load --input /tmp/bin-image.tar
docker inspect bin
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build image
run: |
docker build -f ${{ matrix.kind }}.dockerfile --build-arg BIN_IMAGE=bin -t ${{ matrix.kind }} .
docker buildx build -f ${{ matrix.kind }}.dockerfile --platform=linux/amd64,linux/arm64 --build-arg BIN_IMAGE=registry:5000/bin -t registry:5000/${{ matrix.kind }} --push .
- name: Test default CMD
run: |
docker run -t ${{ matrix.kind }}
docker run -t registry:5000/${{ matrix.kind }}
- name: Test if entry script forwards to deno binary
run: |
docker run -t ${{ matrix.kind }} eval "console.log('Welcome to Deno!')"
docker run -t registry:5000/${{ matrix.kind }} eval "console.log('Welcome to Deno!')"
# if typescript is present in the output, then probably deno --version worked
docker run -t ${{ matrix.kind }} --version | grep typescript
docker run -t registry:5000/${{ matrix.kind }} --version | grep typescript
- name: Test if entry script forwards to other binaries
if: ${{ matrix.kind != 'distroless' }}
run: |
docker run -t ${{ matrix.kind }} deno eval "console.log('Welcome to Deno!')"
docker run -t ${{ matrix.kind }} echo 'test entry script'
docker run -t registry:5000/${{ matrix.kind }} deno eval "console.log('Welcome to Deno!')"
docker run -t registry:5000/${{ matrix.kind }} echo 'test entry script'
- name: Login to Docker Hub
if: github.repository == 'denoland/deno_docker' && startsWith(github.ref, 'refs/tags/')
if: github.repository == 'denoland/deno_docker' && github.ref_type == 'tag'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Push named images
if: github.repository == 'denoland/deno_docker' && startsWith(github.ref, 'refs/tags/')
if: github.repository == 'denoland/deno_docker' && github.ref_type == 'tag'
run: |
docker tag ${{ matrix.kind }} denoland/deno:${{ matrix.kind }}-${GITHUB_REF#refs/*/}
docker tag ${{ matrix.kind }} denoland/deno:${{ matrix.kind }}
docker push denoland/deno:${{ matrix.kind }}-${GITHUB_REF#refs/*/}
docker push denoland/deno:${{ matrix.kind }}
docker buildx imagetools create registry:8000/${{ matrix.kind }} -t denoland/deno:${{ matrix.kind }}-${GITHUB_REF#refs/*/} -t denoland/deno:${{ matrix.kind }}
- name: Push bin image
if: github.repository == 'denoland/deno_docker' && startsWith(github.ref, 'refs/tags/') && matrix.kind == 'debian'
if: github.repository == 'denoland/deno_docker' && github.ref_type == 'tag' && matrix.kind == 'debian'
run: |
docker tag bin denoland/deno:bin-${GITHUB_REF#refs/*/}
docker tag bin denoland/deno:bin
docker push denoland/deno:bin-${GITHUB_REF#refs/*/}
docker push denoland/deno:bin
docker buildx imagetools create registry:8000/bin -t denoland/deno:bin-${GITHUB_REF#refs/*/} -t denoland/deno:bin
- name: Push default image
if: github.repository == 'denoland/deno_docker' && startsWith(github.ref, 'refs/tags/') && matrix.kind == 'debian'
if: github.repository == 'denoland/deno_docker' && github.ref_type == 'tag' && matrix.kind == 'debian'
run: |
docker tag ${{ matrix.kind }} denoland/deno:${GITHUB_REF#refs/*/}
docker tag ${{ matrix.kind }} denoland/deno:latest
docker push denoland/deno:${GITHUB_REF#refs/*/}
docker push denoland/deno:latest
docker buildx imagetools create registry:8000/${{ matrix.kind }} -t denoland/deno:${{ matrix.kind }}-${GITHUB_REF#refs/*/} -t denoland/deno:latest
4 changes: 3 additions & 1 deletion bin.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ RUN export DEBIAN_FRONTEND=noninteractive \
&& rm -rf /var/lib/apt/lists/*

ARG DENO_VERSION
RUN curl -fsSL https://github.com/denoland/deno/releases/download/v${DENO_VERSION}/deno-x86_64-unknown-linux-gnu.zip \
ARG TARGETARCH

RUN curl -fsSL https://github.com/denoland/deno/releases/download/v${DENO_VERSION}/deno-$(echo $TARGETARCH | sed -e 's/arm64/aarch64/' -e 's/amd64/x86_64/')-unknown-linux-gnu.zip \
--output deno.zip \
&& unzip deno.zip \
&& rm deno.zip \
Expand Down

0 comments on commit eb212bf

Please sign in to comment.