Skip to content

Commit 6f70bad

Browse files
authored
[Bugfix] Docker image builds (alexjustesen#739)
1 parent ea5388f commit 6f70bad

File tree

3 files changed

+49
-38
lines changed

3 files changed

+49
-38
lines changed
Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
1-
# This workflow uses actions that are not certified by GitHub.
2-
# They are provided by a third-party and are governed by
3-
# separate terms of service, privacy policy, and support
4-
# documentation.
5-
6-
# GitHub recommends pinning actions to a commit SHA.
7-
# To get a newer version, you will need to update the SHA.
8-
# You can also reference a tag or branch, but the action may change without warning.
9-
10-
name: Build and push Docker image to Docker Hub
1+
name: Build and push Docker images
112

123
on:
4+
# release:
5+
# types: [ published ]
6+
push:
7+
tags:
8+
- 'v*'
139
workflow_dispatch:
14-
release:
15-
branches: [ main ]
16-
types: [ published ]
1710

1811
env:
1912
PLATFORMS: linux/amd64,linux/arm64,linux/arm/v7
2013

2114
jobs:
2215
build_and_push_image:
2316
runs-on: ubuntu-22.04
17+
permissions:
18+
contents: read
19+
packages: write
2420

2521
steps:
2622
- name: Checkout repository
@@ -38,6 +34,13 @@ jobs:
3834
username: ${{ secrets.DOCKER_USERNAME }}
3935
password: ${{ secrets.DOCKER_PASSWORD }}
4036

37+
- name: Log in to the Container registry
38+
uses: docker/login-action@v2
39+
with:
40+
registry: ghcr.io
41+
username: ${{ github.actor }}
42+
password: ${{ secrets.GITHUB_TOKEN }}
43+
4144
- id: docker-image-to-lowercase
4245
name: Convert Docker image to lower case
4346
run: echo "DOCKER_IMAGE=$(echo ${{ secrets.DOCKER_USERNAME }}/${{ github.event.repository.name }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
@@ -46,12 +49,14 @@ jobs:
4649
id: meta
4750
uses: docker/metadata-action@v4
4851
with:
49-
images: ${{ env.DOCKER_IMAGE }}
52+
images: |
53+
${{ env.DOCKER_IMAGE }}
54+
ghcr.io/${{ github.repository }}
5055
tags: |
5156
type=semver,pattern={{version}}
52-
latest
57+
type=semver,pattern={{major}}.{{minor}}
5358
54-
- name: Build and push image to Docker Hub
59+
- name: Build and push Docker images
5560
uses: docker/build-push-action@v3
5661
with:
5762
context: .
Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,16 @@
1-
# This workflow uses actions that are not certified by GitHub.
2-
# They are provided by a third-party and are governed by
3-
# separate terms of service, privacy policy, and support
4-
# documentation.
5-
6-
# GitHub recommends pinning actions to a commit SHA.
7-
# To get a newer version, you will need to update the SHA.
8-
# You can also reference a tag or branch, but the action may change without warning.
9-
10-
name: Build and push Docker image to GHCR
1+
name: Build and test Docker images
112

123
on:
4+
push:
5+
branches:
6+
- 'release-**'
137
workflow_dispatch:
14-
release:
15-
branches: [ main ]
16-
types: [ published ]
178

189
env:
19-
REGISTRY: ghcr.io
20-
IMAGE_NAME: ${{ github.repository }}
2110
PLATFORMS: linux/amd64,linux/arm64,linux/arm/v7
2211

2312
jobs:
24-
build_and_push_image:
13+
build_and_test_images:
2514
runs-on: ubuntu-22.04
2615
permissions:
2716
contents: read
@@ -37,24 +26,39 @@ jobs:
3726
- name: Set up Docker Buildx
3827
uses: docker/setup-buildx-action@v2
3928

29+
- name: Log in to Docker Hub
30+
uses: docker/login-action@v2
31+
with:
32+
username: ${{ secrets.DOCKER_USERNAME }}
33+
password: ${{ secrets.DOCKER_PASSWORD }}
34+
4035
- name: Log in to the Container registry
4136
uses: docker/login-action@v2
4237
with:
43-
registry: ${{ env.REGISTRY }}
38+
registry: ghcr.io
4439
username: ${{ github.actor }}
4540
password: ${{ secrets.GITHUB_TOKEN }}
4641

42+
- id: docker-image-to-lowercase
43+
name: Convert Docker image to lower case
44+
run: echo "DOCKER_IMAGE=$(echo ${{ secrets.DOCKER_USERNAME }}/${{ github.event.repository.name }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
45+
4746
- name: Extract metadata (tags, labels) for Docker
4847
id: meta
4948
uses: docker/metadata-action@v4
5049
with:
51-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
50+
images: |
51+
${{ env.DOCKER_IMAGE }}
52+
ghcr.io/${{ github.repository }}
53+
tags: |
54+
type=semver,pattern={{version}}
55+
type=semver,pattern={{major}}.{{minor}}
5256
53-
- name: Build and push image to GHCR
57+
- name: Build and push Docker images
5458
uses: docker/build-push-action@v3
5559
with:
5660
context: .
57-
push: true
61+
push: false
5862
platforms: ${{ env.PLATFORMS }}
5963
tags: ${{ steps.meta.outputs.tags }}
6064
labels: ${{ steps.meta.outputs.labels }}

.github/workflows/test.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
name: Test
2+
23
on:
3-
- push
4-
- workflow_dispatch
4+
push:
5+
workflow_dispatch:
6+
57
jobs:
68
test:
79
strategy:

0 commit comments

Comments
 (0)