Skip to content

Commit 034524d

Browse files
authored
Merge pull request #12 from GergoEB/patch-1
Use Github Actions to do Docker Builds
2 parents 44d8d4f + 0b1ed09 commit 034524d

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

.github/workflows/docker-image.yml

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Docker
2+
3+
on:
4+
schedule:
5+
- cron: '24 9 * * *'
6+
push:
7+
branches: [ "main" ]
8+
# Publish semver tags as releases.
9+
tags: [ 'v*.*.*' ]
10+
pull_request:
11+
branches: [ "main" ]
12+
13+
env:
14+
# Use docker.io for Docker Hub if empty
15+
REGISTRY: ghcr.io
16+
# github.repository as <account>/<repo>
17+
IMAGE_NAME: ${{ github.repository }}
18+
19+
jobs:
20+
build:
21+
runs-on: ubuntu-latest
22+
strategy:
23+
matrix:
24+
php-version: [ '8.0', '8.1', '8.2', '8.3' ] # PHP versions to build
25+
26+
permissions:
27+
contents: read
28+
packages: write
29+
id-token: write
30+
31+
steps:
32+
- name: Checkout repository
33+
uses: actions/checkout@v4
34+
35+
# Install the cosign tool except on PR
36+
- name: Install cosign
37+
if: github.event_name != 'pull_request'
38+
uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 #v3.5.0
39+
with:
40+
cosign-release: 'v2.2.4'
41+
42+
# Set up BuildKit Docker container builder
43+
- name: Set up Docker Buildx
44+
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
45+
46+
# Login against a Docker registry except on PR
47+
- name: Log into registry ${{ env.REGISTRY }}
48+
if: github.event_name != 'pull_request'
49+
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
50+
with:
51+
registry: ${{ env.REGISTRY }}
52+
username: ${{ github.actor }}
53+
password: ${{ secrets.GITHUB_TOKEN }}
54+
55+
# Extract metadata (tags, labels) for Docker
56+
- name: Extract Docker metadata
57+
id: meta
58+
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
59+
with:
60+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
61+
tags: |
62+
${{ matrix.php-version }}-${{ github.sha }}
63+
${{ matrix.php-version }}-latest
64+
${{ matrix.php-version }}
65+
66+
# Build and push Docker image with Buildx (don't push on PR)
67+
- name: Build and push Docker image
68+
id: build-and-push
69+
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
70+
with:
71+
context: .
72+
push: ${{ github.event_name != 'pull_request' }}
73+
platforms: linux/amd64,linux/arm64
74+
tags: ${{ steps.meta.outputs.tags }}
75+
labels: ${{ steps.meta.outputs.labels }}
76+
cache-from: type=gha
77+
cache-to: type=gha,mode=max
78+
build-args: |
79+
PHP_VERSION=${{ matrix.php-version }}
80+
81+
# Sign the resulting Docker image digest except on PRs.
82+
- name: Sign the published Docker image
83+
if: ${{ github.event_name != 'pull_request' }}
84+
env:
85+
TAGS: ${{ steps.meta.outputs.tags }}
86+
DIGEST: ${{ steps.build-and-push.outputs.digest }}
87+
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}

0 commit comments

Comments
 (0)