ci: Fix pushing multiplatform image #135
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Docker Image CI | |
| on: | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| branches: [ main ] | |
| schedule: | |
| - cron: '0 3 1,15 * *' | |
| jobs: | |
| build: | |
| runs-on: ${{ matrix.runner }} | |
| strategy: | |
| matrix: | |
| runner: [ ubuntu-24.04-arm, ubuntu-latest ] | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - | |
| name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - | |
| name: Cache Docker layers | |
| uses: actions/cache@v4 | |
| with: | |
| path: /tmp/.buildx-cache | |
| key: ${{ runner.os }}-${{ runner.arch }}-buildx-${{ github.sha }} | |
| restore-keys: | | |
| ${{ runner.os }}-${{ runner.arch }}-buildx- | |
| - | |
| name: Build and export to Docker | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| load: true | |
| tags: misp-modules:latest | |
| cache-from: type=local,src=/tmp/.buildx-cache/amd64 | |
| cache-to: type=local,dest=/tmp/.buildx-cache-new/amd64,mode=max | |
| - | |
| name: Show image details | |
| run: | | |
| docker image inspect misp-modules:latest | |
| docker image history misp-modules:latest | |
| - | |
| name: Test | |
| run: | | |
| docker run --name misp-modules --rm -p 127.0.0.1:6666:6666 misp-modules:latest & | |
| sleep 5 # Wait until container is ready | |
| curl --fail http://localhost:6666/modules | jq | |
| docker stop misp-modules | |
| - | |
| # Temp fix | |
| # https://github.com/docker/build-push-action/issues/252 | |
| # https://github.com/moby/buildkit/issues/1896 | |
| name: Move cache | |
| run: | | |
| rm -rf /tmp/.buildx-cache | |
| mv /tmp/.buildx-cache-new /tmp/.buildx-cache | |
| du -sh /tmp/.buildx-cache | |
| - name: Save image to file | |
| run: | | |
| docker tag misp-modules:latest misp-modules-${{ runner.arch == 'X64' && 'amd64' || 'arm64' }}:latest | |
| docker save misp-modules-${{ runner.arch == 'X64' && 'amd64' || 'arm64' }}:latest | zstd > misp-modules.tar.zstd | |
| - name: Upload image artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: misp-modules-${{ runner.arch == 'X64' && 'amd64' || 'arm64' }} | |
| path: misp-modules.tar.zstd | |
| retention-days: 1 | |
| compression-level: 0 | |
| push: | |
| runs-on: ubuntu-latest | |
| needs: build | |
| steps: | |
| - name: Download images from artifact | |
| run: gh run download --repo "$GITHUB_REPOSITORY" --pattern "misp-modules-*" "$GITHUB_RUN_ID" | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| - name: Load and merge images | |
| run: | | |
| ls -la | |
| docker image load -i misp-modules-amd64.tar.zstd | |
| docker image load -i misp-modules-arm64.tar.zstd | |
| docker buildx imagetools create --append misp-modules-arm64:latest --tag misp-modules:latest misp-modules-amd64:latest | |
| docker image ls | |
| docker image inspect misp-modules:latest | |
| - | |
| name: Login to GitHub Container Registry | |
| if: github.event_name != 'pull_request' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.repository_owner }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - | |
| name: Login to DockerHub | |
| if: github.event_name != 'pull_request' | |
| uses: docker/login-action@v3 | |
| with: | |
| username: nukib | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - | |
| name: Push | |
| if: github.event_name != 'pull_request' | |
| uses: docker/build-push-action@v6 | |
| with: | |
| push: true | |
| platforms: linux/${{ runner.arch == 'X64' && 'amd64' || 'arm64' }} | |
| tags: | | |
| nukib/misp-modules:latest | |
| ghcr.io/nukib/misp-modules:latest | |