ci: refactor Docker build workflow to consolidate build steps and improve image tagging
This commit is contained in:
138
.github/workflows/build-docker.yml
vendored
138
.github/workflows/build-docker.yml
vendored
@@ -23,7 +23,7 @@ jobs:
|
||||
outputs:
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
version: ${{ steps.meta.outputs.version }}
|
||||
version: ${{ steps.args.outputs.version }}
|
||||
git_commit: ${{ steps.args.outputs.git_commit }}
|
||||
build_time: ${{ steps.args.outputs.build_time }}
|
||||
|
||||
@@ -48,20 +48,23 @@ jobs:
|
||||
echo "git_commit=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
|
||||
echo "build_time=$(git show -s --format=%cI)" >> "$GITHUB_OUTPUT"
|
||||
|
||||
build-default:
|
||||
runs-on: ubuntu-latest
|
||||
build:
|
||||
needs: prepare
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
strategy:
|
||||
matrix:
|
||||
arch: [amd64, arm64]
|
||||
type: [default, micro, pico]
|
||||
fail-fast: false
|
||||
|
||||
runs-on: ${{ matrix.arch == 'amd64' && 'ubuntu-latest' || 'ubuntu-24.04-arm' }}
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
@@ -72,110 +75,39 @@ jobs:
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Set Dockerfile path
|
||||
id: dockerfile
|
||||
run: |
|
||||
if [ "${{ matrix.type }}" == "default" ]; then
|
||||
echo "DOCKERFILE=./Dockerfile" >> "$GITHUB_OUTPUT"
|
||||
elif [ "${{ matrix.type }}" == "micro" ]; then
|
||||
echo "DOCKERFILE=./Dockerfile.micro" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo "DOCKERFILE=./Dockerfile.pico" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Set image tags
|
||||
id: tags
|
||||
run: |
|
||||
if [ "${{ matrix.type }}" == "default" ]; then
|
||||
TAGS="${{ needs.prepare.outputs.tags }}"
|
||||
elif [ "${{ matrix.type }}" == "micro" ]; then
|
||||
TAGS="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:micro,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:micro-latest,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:micro-${{ needs.prepare.outputs.version }}"
|
||||
else
|
||||
TAGS="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:pico,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:pico-latest,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:pico-${{ needs.prepare.outputs.version }}"
|
||||
fi
|
||||
echo "TAGS=$TAGS" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Build and push Docker image
|
||||
id: build-and-push
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile
|
||||
platforms: linux/amd64,linux/arm64
|
||||
file: ${{ steps.dockerfile.outputs.DOCKERFILE }}
|
||||
platforms: ${{ matrix.arch == 'amd64' && 'linux/amd64' || 'linux/arm64' }}
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: ${{ needs.prepare.outputs.tags }}
|
||||
tags: ${{ steps.tags.outputs.TAGS }}
|
||||
labels: ${{ needs.prepare.outputs.labels }}
|
||||
cache-from: |
|
||||
type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
|
||||
type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
build-args: |
|
||||
VERSION=${{ needs.prepare.outputs.version }}
|
||||
GitCommit=${{ needs.prepare.outputs.git_commit }}
|
||||
BuildTime=${{ needs.prepare.outputs.build_time }}
|
||||
|
||||
build-micro:
|
||||
runs-on: ubuntu-latest
|
||||
needs: prepare
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Login to GitHub Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Build and push micro Docker image
|
||||
id: build-and-push-micro
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile.micro
|
||||
platforms: linux/amd64,linux/arm64
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: |
|
||||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:micro
|
||||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:micro-latest
|
||||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:micro-${{ needs.prepare.outputs.version }}
|
||||
labels: ${{ needs.prepare.outputs.labels }}
|
||||
cache-from: |
|
||||
type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:micro-latest
|
||||
type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
build-args: |
|
||||
VERSION=${{ needs.prepare.outputs.version }}
|
||||
GitCommit=${{ needs.prepare.outputs.git_commit }}
|
||||
BuildTime=${{ needs.prepare.outputs.build_time }}
|
||||
|
||||
build-pico:
|
||||
runs-on: ubuntu-latest
|
||||
needs: prepare
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Login to GitHub Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Build and push pico Docker image
|
||||
id: build-and-push-pico
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile.pico
|
||||
platforms: linux/amd64,linux/arm64
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: |
|
||||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:pico
|
||||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:pico-latest
|
||||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:pico-${{ needs.prepare.outputs.version }}
|
||||
labels: ${{ needs.prepare.outputs.labels }}
|
||||
cache-from: |
|
||||
type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:pico-latest
|
||||
type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.type }}-latest
|
||||
type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
build-args: |
|
||||
|
||||
Reference in New Issue
Block a user