|
1 | | -name: Build and Release Image |
| 1 | +name: Docker |
2 | 2 |
|
3 | 3 | on: |
4 | | - release: |
5 | | - types: |
6 | | - - created |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - master |
| 8 | + tags: |
| 9 | + - v* |
7 | 10 |
|
8 | 11 | env: |
9 | | - IMAGE_NAME: valhalla |
| 12 | + REGISTRY: ghcr.io |
| 13 | + IMAGE_NAME: ${{ github.repository }}/valhalla |
10 | 14 |
|
11 | 15 | jobs: |
12 | | - push: |
| 16 | + build-and-push-image: |
13 | 17 | runs-on: ubuntu-latest |
14 | 18 | permissions: |
15 | 19 | contents: read |
16 | 20 | packages: write |
17 | 21 | steps: |
18 | | - - uses: actions/checkout@v6 |
19 | | - - name: Build image |
20 | | - run: docker build . --tag image |
21 | | - - name: Log into registry |
22 | | - run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin |
23 | | - - name: Push image |
24 | | - run: | |
25 | | - IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME |
26 | | - # Strip git ref prefix from version |
27 | | - [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') |
28 | | - echo IMAGE_ID=$IMAGE_ID |
29 | | - echo VERSION=$VERSION |
30 | | - docker tag image $IMAGE_ID:$VERSION |
31 | | - # Use Docker `latest` tag convention |
32 | | - [ "$VERSION" == "master" ] && docker tag image $IMAGE_ID:latest |
33 | | - docker push $IMAGE_ID:$VERSION |
| 22 | + - name: Checkout repository |
| 23 | + uses: actions/checkout@v6 |
| 24 | + - uses: docker/setup-buildx-action@v3 |
| 25 | + - name: Log in to the Container registry |
| 26 | + uses: docker/login-action@v3 |
| 27 | + with: |
| 28 | + registry: ${{ env.REGISTRY }} |
| 29 | + username: ${{ github.actor }} |
| 30 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 31 | + - name: Extract metadata (tags, labels) for Docker |
| 32 | + id: meta |
| 33 | + uses: docker/metadata-action@v5 |
| 34 | + with: |
| 35 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 36 | + - name: Build and push Docker image |
| 37 | + uses: docker/build-push-action@v6 |
| 38 | + with: |
| 39 | + context: . |
| 40 | + push: true |
| 41 | + tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest,${{ steps.meta.outputs.tags }} |
| 42 | + labels: ${{ steps.meta.outputs.labels }} |
| 43 | + cache-from: type=gha |
| 44 | + cache-to: type=gha,mode=max |
0 commit comments