Skip to content

Commit 96725a9

Browse files
authored
Merge pull request #7 from interline-io/gh-actions2
newer actions for build.yml
2 parents fedb452 + 967d39a commit 96725a9

File tree

1 file changed

+33
-22
lines changed

1 file changed

+33
-22
lines changed

.github/workflows/build.yml

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,44 @@
1-
name: Build and Release Image
1+
name: Docker
22

33
on:
4-
release:
5-
types:
6-
- created
4+
push:
5+
branches:
6+
- main
7+
- master
8+
tags:
9+
- v*
710

811
env:
9-
IMAGE_NAME: valhalla
12+
REGISTRY: ghcr.io
13+
IMAGE_NAME: ${{ github.repository }}/valhalla
1014

1115
jobs:
12-
push:
16+
build-and-push-image:
1317
runs-on: ubuntu-latest
1418
permissions:
1519
contents: read
1620
packages: write
1721
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

Comments
 (0)