|
1 | | -name: Create and publish image to ghcr |
| 1 | +name: Publish Container Image |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
5 | | - branches: ['main'] |
6 | | - |
7 | | -concurrency: |
8 | | - group: ${{ github.workflow }}-${{ github.ref }} |
9 | | - cancel-in-progress: false |
10 | | - |
11 | | -env: |
12 | | - REGISTRY: ghcr.io |
13 | | - IMAGE_NAME: ${{ github.repository }} |
| 5 | + branches: [main] |
| 6 | + pull_request: |
14 | 7 |
|
15 | 8 | jobs: |
16 | | - build-and-push-image: |
17 | | - runs-on: ${{ matrix.os }} |
18 | | - strategy: |
19 | | - matrix: |
20 | | - include: |
21 | | - - os: ubuntu-24.04 |
22 | | - arch: amd64 |
23 | | - - os: ubuntu-24.04-arm |
24 | | - arch: arm64 |
25 | | - outputs: |
26 | | - image-tag: ${{ steps.image-tag.outputs.tag }} |
27 | | - permissions: |
28 | | - contents: read |
29 | | - packages: write |
30 | | - id-token: write |
31 | | - steps: |
32 | | - - name: Checkout repository |
33 | | - uses: actions/checkout@v5 |
34 | | - - name: Install nix |
35 | | - uses: DeterminateSystems/nix-installer-action@v20 |
36 | | - - name: Log in to the Container registry |
37 | | - uses: docker/login-action@v3.6.0 |
38 | | - with: |
39 | | - registry: ${{ env.REGISTRY }} |
40 | | - username: ${{ github.actor }} |
41 | | - password: ${{ secrets.GITHUB_TOKEN }} |
42 | | - - name: Build container image |
43 | | - run: nix build -L .#containerImage |
44 | | - - name: Load image |
45 | | - run: | |
46 | | - ./result | docker load |
47 | | - - name: Get image tag |
48 | | - id: image-tag |
49 | | - run: | |
50 | | - export IMAGE_TAG="`nix eval --raw .#containerImage.imageTag`" |
51 | | - echo "tag=$IMAGE_TAG" >> $GITHUB_OUTPUT |
52 | | - - name: Push architecture-specific image |
53 | | - run: | |
54 | | - export IMAGE_TAG="${{ steps.image-tag.outputs.tag }}" |
55 | | - export ARCH_TAG="${IMAGE_TAG}-${{ matrix.arch }}" |
56 | | - |
57 | | - docker image tag "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$IMAGE_TAG" "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$ARCH_TAG" |
58 | | - docker push "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$ARCH_TAG" |
59 | | -
|
60 | | - create-manifest: |
61 | | - needs: build-and-push-image |
62 | | - runs-on: ubuntu-24.04 |
| 9 | + publish: |
| 10 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 11 | + uses: buurro/publish-container-image/.github/workflows/publish-container-image.yml@main |
63 | 12 | permissions: |
64 | 13 | contents: read |
65 | 14 | packages: write |
66 | | - steps: |
67 | | - - name: Log in to the Container registry |
68 | | - uses: docker/login-action@v3.6.0 |
69 | | - with: |
70 | | - registry: ${{ env.REGISTRY }} |
71 | | - username: ${{ github.actor }} |
72 | | - password: ${{ secrets.GITHUB_TOKEN }} |
73 | | - - name: Create and push manifest |
74 | | - run: | |
75 | | - export IMAGE_TAG="${{ needs.build-and-push-image.outputs.image-tag }}" |
76 | | - |
77 | | - # Create manifest for version tag |
78 | | - docker manifest create "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$IMAGE_TAG" \ |
79 | | - "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$IMAGE_TAG-amd64" \ |
80 | | - "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$IMAGE_TAG-arm64" |
81 | | - |
82 | | - docker manifest push "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$IMAGE_TAG" |
83 | | - |
84 | | - # Create manifest for latest tag |
85 | | - docker manifest create "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" \ |
86 | | - "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$IMAGE_TAG-amd64" \ |
87 | | - "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$IMAGE_TAG-arm64" |
88 | | - |
89 | | - docker manifest push "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" |
| 15 | + with: |
| 16 | + nix-flake-attr: '.#containerImage' |
| 17 | + secrets: inherit |
0 commit comments