Skip to content

Commit

Permalink
Multi stage build
Browse files Browse the repository at this point in the history
  • Loading branch information
snh committed Sep 7, 2024
1 parent 46cb9d9 commit 0386190
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 25 deletions.
94 changes: 69 additions & 25 deletions .github/workflows/container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,50 +10,94 @@ on:
workflow_dispatch:

jobs:
main:
build:
runs-on: ubuntu-latest
strategy:
matrix:
platform: [linux/amd64, linux/386, linux/arm64, linux/arm/v6, linux/arm/v7]
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Declare platform
run: |
platform=${{ matrix.platform }}
echo "PLATFORM=${platform//\//-}" >> $GITHUB_ENV
- name: Calculate Container Metadata
- name: Calculate container metadata
id: meta
uses: docker/metadata-action@v4
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}

- name: Setup QEMU
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3

- name: Setup Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
if: ${{ github.event_name != 'pull_request' }}
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build Images
if: ${{ github.event_name == 'pull_request' }}
uses: docker/build-push-action@v3
- name: Build images and push by digest
id: build
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64, linux/386, linux/arm64, linux/arm/v6, linux/arm/v7
cache-from: type=registry,ref=ghcr.io/${{ github.repository }}:buildcache
tags: ${{ steps.meta.outputs.tags }}
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}

- name: Build and Push Images
outputs: type=image,name=ghcr.io/${{ github.repository }},push-by-digest=true,name-canonical=true,push=${{ github.event_name != 'pull_request' && 'true' || 'false' }}

- name: Export digest
if: ${{ github.event_name != 'pull_request' }}
uses: docker/build-push-action@v3
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
if: ${{ github.event_name != 'pull_request' }}
uses: actions/upload-artifact@v4
with:
context: .
platforms: linux/amd64, linux/386, linux/arm64, linux/arm/v6, linux/arm/v7
cache-from: type=registry,ref=ghcr.io/${{ github.repository }}:buildcache
cache-to: type=registry,ref=ghcr.io/${{ github.repository }}:buildcache,mode=max
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
name: digests-${{ env.PLATFORM }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1

merge:
if: ${{ github.event_name != 'pull_request' }}
runs-on: ubuntu-latest
needs: [build]
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true

- name: Calculate container metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}

- name: Setup Buildx
uses: docker/setup-buildx-action@v2

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Create and push manifest
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf 'ghcr.io/${{ github.repository }}@sha256:%s ' *)
- name: Inspect container image
run: |
docker buildx imagetools inspect ghcr.io/${{ github.repository }}:${{ steps.meta.outputs.version }}
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ COPY auto_rx/requirements.txt \

# Install Python packages.
RUN pip3 install \
--extra-index-url https://www.piwheels.org/simple \
--user --break-system-packages --no-warn-script-location --ignore-installed \
-r /root/radiosonde_auto_rx/auto_rx/requirements.txt

Expand Down

0 comments on commit 0386190

Please sign in to comment.