Skip to content

Commit bfaac1c

Browse files
authored
Merge pull request #76 from Xerkus/feature/docker-workflow
Simplify docker build and push workflow
2 parents c6f886a + a984051 commit bfaac1c

File tree

1 file changed

+23
-45
lines changed

1 file changed

+23
-45
lines changed

.github/workflows/build-and-push-containers.yml

Lines changed: 23 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -11,65 +11,43 @@ jobs:
1111
env:
1212
DOCKER_USER: ${{ secrets.CONTAINER_USERNAME }}
1313
steps:
14-
- name: Compile tag list
15-
id: tags
16-
run: |
17-
TAG=${GITHUB_REF/refs\/tags\//}
18-
PREFIX=ghcr.io/laminas/laminas-continuous-integration
19-
MAJOR="${PREFIX}:$(echo ${TAG} | cut -d. -f1)"
20-
MINOR="${MAJOR}.$(echo ${TAG} | cut -d. -f2)"
21-
PATCH="${PREFIX}:${TAG}"
22-
echo "::set-output name=tags::[\"${MAJOR}\",\"${MINOR}\",\"${PATCH}\"]"
23-
2414
- name: Checkout
2515
uses: actions/checkout@v2
2616

27-
- name: Setup QEMU
28-
uses: docker/setup-qemu-action@v1
29-
3017
- name: Setup Docker Buildx
3118
uses: docker/setup-buildx-action@v1
19+
with:
20+
install: true
3221

3322
- name: Login to GitHub Container Registry
34-
if: ${{ env.DOCKER_USER }}
23+
if: ${{ github.event_name == 'release' }}
3524
uses: docker/login-action@v1
3625
with:
3726
registry: ghcr.io
38-
username: ${{ env.DOCKER_USER }}
39-
password: ${{ secrets.CONTAINER_PAT }}
40-
41-
- name: Build and push for release
42-
if: ${{ github.event_name == 'release' }}
43-
uses: docker/build-push-action@v2
44-
with:
45-
context: .
46-
file: ./Dockerfile
47-
platforms: linux/amd64
48-
pull: true
49-
push: true
50-
tags: ${{ join(fromJSON(steps.tags.outputs.tags), ',') }}
51-
cache-from: type=registry,ref=ghcr.io/laminas/laminas-continuous-integration-action:build-cache
52-
cache-to: type=registry,ref=ghcr.io/laminas/laminas-continuous-integration-action:build-cache,mode=max
27+
username: ${{ github.repository_owner }}
28+
password: ${{ secrets.GITHUB_TOKEN }}
5329

54-
- name: Build for local pull request
55-
if: ${{ github.event_name == 'pull_request' && env.DOCKER_USER }}
56-
uses: docker/build-push-action@v2
30+
- name: Docker meta
31+
id: docker_meta
32+
uses: docker/metadata-action@v3
5733
with:
58-
context: .
59-
file: ./Dockerfile
60-
platforms: linux/amd64
61-
pull: true
62-
push: false
63-
cache-from: type=registry,ref=ghcr.io/laminas/laminas-continuous-integration-action:build-cache
64-
cache-to: type=registry,ref=ghcr.io/laminas/laminas-continuous-integration-action:build-cache,mode=max
65-
66-
- name: Build for fork pull request
67-
if: ${{ github.event_name == 'pull_request' && ! env.DOCKER_USER }}
34+
images: ghcr.io/laminas/laminas-continuous-integration
35+
tags: |
36+
type=semver,pattern={{version}}
37+
type=ref,event=branch
38+
type=ref,event=pr
39+
flavor: |
40+
latest=false
41+
42+
- name: Build image. Push for release
6843
uses: docker/build-push-action@v2
6944
with:
7045
context: .
7146
file: ./Dockerfile
72-
platforms: linux/amd64
7347
pull: true
74-
push: false
75-
cache-from: type=registry,ref=ghcr.io/laminas/laminas-continuous-integration-action:build-cache
48+
push: ${{ github.event_name == 'release' }}
49+
tags: |
50+
${{ steps.docker_meta.outputs.tags }}
51+
labels: ${{ steps.docker_meta.outputs.labels }}
52+
cache-from: type=gha
53+
cache-to: type=gha,mode=max

0 commit comments

Comments
 (0)