Skip to content

Commit 5e82c56

Browse files
committed
container builds local and CI
1 parent 965e88e commit 5e82c56

File tree

2 files changed

+77
-2
lines changed

2 files changed

+77
-2
lines changed

.github/workflows/docker.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Docker
2+
3+
on:
4+
push:
5+
branches: [main, develop]
6+
tags: ['v*']
7+
pull_request:
8+
branches: [main]
9+
10+
env:
11+
REGISTRY: ghcr.io
12+
IMAGE_NAME: ${{ github.repository }}
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
19+
packages: write
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
25+
- name: Setup Docker Buildx
26+
uses: docker/setup-buildx-action@v3
27+
28+
- name: Log in to Container Registry
29+
if: github.event_name != 'pull_request'
30+
uses: docker/login-action@v3
31+
with:
32+
registry: ${{ env.REGISTRY }}
33+
username: ${{ github.actor }}
34+
password: ${{ secrets.GITHUB_TOKEN }}
35+
36+
- name: Extract metadata
37+
id: meta
38+
uses: docker/metadata-action@v5
39+
with:
40+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
41+
tags: |
42+
# Canary builds for every push to main/develop
43+
type=raw,value=canary,enable={{is_default_branch}}
44+
type=raw,value=canary-{{branch}},enable=${{ github.ref_name != 'main' && github.event_name == 'push' }}
45+
type=raw,value=canary-{{sha}},enable=${{ github.event_name == 'push' }}
46+
# PR builds
47+
type=ref,event=pr,prefix=pr-
48+
# Release builds only on tags
49+
type=semver,pattern={{version}}
50+
type=semver,pattern={{major}}.{{minor}}
51+
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
52+
53+
- name: Build and push Docker image
54+
uses: docker/build-push-action@v5
55+
with:
56+
context: .
57+
platforms: linux/amd64,linux/arm64
58+
push: ${{ github.event_name != 'pull_request' }}
59+
tags: ${{ steps.meta.outputs.tags }}
60+
labels: ${{ steps.meta.outputs.labels }}
61+
cache-from: type=gha
62+
cache-to: type=gha,mode=max

Makefile

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,24 @@ test.local:
1919
${DOCKER_IMAGE_NAME}:latest \
2020
--test
2121

22-
build.latest:
22+
build.ghcr:
2323
docker buildx build --pull --push \
2424
--platform linux/amd64 \
2525
-t ${DOCKER_IMAGE_URL}:latest \
2626
-t ${DOCKER_IMAGE_URL}:${VERSION} \
2727
. --label "version=v${VERSION}"
2828

29-
.PHONY: test
29+
build.ghcr.multi:
30+
docker buildx build --pull --push \
31+
--platform linux/amd64,linux/arm64 \
32+
-t ${DOCKER_IMAGE_URL}:latest \
33+
-t ${DOCKER_IMAGE_URL}:${VERSION} \
34+
. --label "version=v${VERSION}"
35+
36+
login.ghcr:
37+
echo ${GITHUB_TOKEN} | docker login ghcr.io -u ${GITHUB_USERNAME} --password-stdin
38+
39+
# Legacy target for backward compatibility
40+
build.latest: build.ghcr
41+
42+
.PHONY: test build.local run.local test.local build.ghcr build.ghcr.multi login.ghcr build.latest

0 commit comments

Comments
 (0)