Skip to content

Commit 2f7fad7

Browse files
authored
Merge pull request #3393 from metacpan/haarg/reusable-docker-actions
use reusable action for building and pushing docker images
2 parents 9ca309a + 7cad848 commit 2f7fad7

File tree

1 file changed

+14
-63
lines changed

1 file changed

+14
-63
lines changed

.github/workflows/build-container.yml

Lines changed: 14 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -23,72 +23,23 @@ jobs:
2323
app-id: ${{ secrets.APP_ID }}
2424
private-key: ${{ secrets.APP_PRIVATE_KEY }}
2525
owner: metacpan
26-
- name: Log in to Docker Hub
27-
uses: docker/login-action@v3
28-
with:
29-
username: ${{ secrets.DOCKER_HUB_USER }}
30-
password: ${{ secrets.DOCKER_HUB_TOKEN }}
31-
- name: Login to GitHub Container Registry
32-
uses: docker/login-action@v3
33-
with:
34-
registry: ghcr.io
35-
username: ${{ github.repository_owner }}
36-
password: ${{ secrets.GITHUB_TOKEN }}
37-
- name: Set up Docker Buildx
38-
uses: docker/setup-buildx-action@v3
3926
- uses: actions/checkout@v4
4027
with:
4128
token: ${{ steps.app-token.outputs.token }}
42-
- name: Build test image
43-
id: docker-build-test
44-
uses: docker/build-push-action@v6
45-
with:
46-
target: test
47-
push: false
48-
load: true
49-
- name: Run Perl tests
50-
run: docker run -i ${{ steps.docker-build-test.outputs.imageid }}
51-
- name: Docker meta
52-
id: meta
53-
uses: docker/metadata-action@v5
54-
with:
55-
images: |
56-
docker.io/${{ github.repository }}
57-
ghcr.io/${{ github.repository }}
58-
flavor: |
59-
latest=false
60-
tags: |
61-
type=sha,format=long,priority=2000,enable={{is_default_branch}}
62-
type=ref,event=branch
63-
type=ref,event=pr
64-
type=raw,value=latest,enable={{is_default_branch}}
65-
env:
66-
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index
67-
- name: Build and push
68-
uses: docker/build-push-action@v6
69-
with:
70-
push: true
71-
tags: ${{ steps.meta.outputs.tags }}
72-
labels: ${{ steps.meta.outputs.labels }}
73-
annotations: ${{ steps.meta.outputs.annotations }}
74-
- name: Find tag names
75-
id: find-tag-names
76-
env:
77-
DOCKER_META_JSON: ${{ steps.meta.outputs.json }}
78-
run: |
79-
echo "$DOCKER_META_JSON" | jq -r '.tags | reverse | map ( { (split(":")[-1]) : . }) | add | keys[] as $k | "\($k)=\(.[$k])"' >> "$GITHUB_OUTPUT"
29+
- uses: metacpan/metacpan-actions/docker-build-push@master
30+
id: build-push
31+
with:
32+
docker_hub_username: ${{ secrets.DOCKER_HUB_USER }}
33+
docker_hub_password: ${{ secrets.DOCKER_HUB_TOKEN }}
34+
ghcr_username: ${{ github.repository_owner }}
35+
ghcr_password: ${{ secrets.GITHUB_TOKEN }}
36+
test-target: test
8037
- name: Update deployed image
8138
if: steps.find-tag-names.outputs.latest
82-
uses: benc-uk/workflow-dispatch@v1
39+
uses: metacpan/metacpan-actions/update-deployed-tag:master
8340
with:
84-
repo: metacpan/metacpan-k8s
85-
ref: main
86-
workflow: set-image.yml
87-
token: ${{ steps.app-token.outputs.token }}
88-
inputs: |
89-
{
90-
"app": "web",
91-
"environment": "prod",
92-
"base-tag": "${{ steps.find-tag-names.outputs.latest }}",
93-
"tag": "${{ fromJSON(steps.meta.outputs.json).tags[0] }}"
94-
}
41+
token:
42+
app: web
43+
environment: prod
44+
base-tag: ${{ steps.find-tag-names.outputs.latest }}
45+
tag: ${{ steps.find-tag-names.outputs.sha }}

0 commit comments

Comments
 (0)