Skip to content

Commit 5ed9d03

Browse files
authored
Merge pull request #3 from xmudrii/build-image
Add GitHub Action for building and pushing images
2 parents 0a82c4b + c5863bd commit 5ed9d03

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

.github/workflows/build-image.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Build and push image
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- .github/workflows/push-image.yml
7+
- Dockerfile
8+
push:
9+
branches:
10+
- master
11+
tags:
12+
- 'v*'
13+
14+
permissions:
15+
contents: read
16+
packages: write
17+
18+
env:
19+
REGISTRY: ghcr.io
20+
IMAGE_NAME: ${{ toLower(github.repository) }}
21+
22+
jobs:
23+
docker:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Set up QEMU
27+
uses: docker/setup-qemu-action@v3
28+
29+
- name: Set up Docker Buildx
30+
uses: docker/setup-buildx-action@v3
31+
32+
- name: Login to GHCR
33+
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')
34+
uses: docker/login-action@v3
35+
with:
36+
registry: ${{ env.REGISTRY }}
37+
username: ${{ github.actor }}
38+
password: ${{ secrets.GITHUB_TOKEN }}
39+
40+
- name: Generate image metadata
41+
id: meta
42+
uses: docker/metadata-action@v5
43+
with:
44+
images: |
45+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
46+
tags: |
47+
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/master' }}
48+
type=ref,event=tag
49+
type=sha
50+
51+
- name: Build and push
52+
uses: docker/build-push-action@v6
53+
with:
54+
context: .
55+
file: ./Dockerfile
56+
push: ${{ github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v') }}
57+
tags: ${{ steps.meta.outputs.tags }}
58+
labels: ${{ steps.meta.outputs.labels }}
59+
platforms: linux/amd64,linux/arm64
60+
cache-from: type=gha
61+
cache-to: type=gha,mode=max

0 commit comments

Comments
 (0)