Skip to content

Commit 78e2019

Browse files
committed
feat: add GitHub Actions workflow for publishing PHP 7.4 Docker image to Docker Hub
1 parent 3931673 commit 78e2019

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
name: Publish PHP 7.4 image to Docker Hub
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: write
10+
11+
env:
12+
IMAGE_NAME: dev-php74
13+
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
14+
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
15+
DOCKERHUB_ID: ${{ secrets.DOCKERHUB_ID }}
16+
17+
jobs:
18+
push_to_registry:
19+
if: github.event_name != 'pull_request'
20+
name: Build and push PHP74 image
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v4
25+
26+
- name: Setup Docker Buildx
27+
uses: docker/setup-buildx-action@v3
28+
29+
- name: Log into Docker Hub
30+
uses: docker/login-action@v3
31+
with:
32+
registry: https://index.docker.io/v1/
33+
username: ${{ env.DOCKERHUB_USERNAME }}
34+
password: ${{ env.DOCKERHUB_PASSWORD }}
35+
36+
- name: Get latest version tag
37+
id: get_version
38+
run: |
39+
git fetch --tags
40+
# get the latest tag with regex pattern have vphp74 prefix
41+
latest_tag=$(git tag -l | grep -E '^vphp74' | sort -V | tail -n 1)
42+
echo "Latest tag: $latest_tag"
43+
echo "version=$latest_tag" >> $GITHUB_OUTPUT
44+
45+
- name: Increment version number
46+
id: inc_version
47+
run: |
48+
version=${{ steps.get_version.outputs.version }}
49+
version=${version#"v"}
50+
if [ -z "$version" ]; then
51+
major=0
52+
minor=0
53+
patch=0
54+
else
55+
IFS='.' read -r -a parts <<< "$version"
56+
major=${parts[0]:-0}
57+
minor=${parts[1]:-0}
58+
patch=${parts[2]:-0}
59+
fi
60+
patch=$((patch+1))
61+
if [ "$patch" -ge 100 ]; then
62+
patch=0
63+
minor=$((minor+1))
64+
fi
65+
if [ "$minor" -ge 10]; then
66+
minor=0
67+
major=$((major+1))
68+
fi
69+
new_version="v$major.$minor.$patch"
70+
echo "New version: $new_version"
71+
echo "new_version=$new_version" >> $GITHUB_OUTPUT
72+
73+
- name: Set new version tag
74+
run: |
75+
git tag ${{ steps.inc_version.outputs.new_version }}
76+
git push origin ${{ steps.inc_version.outputs.new_version }}
77+
78+
- name: Extract Docker metadata
79+
id: meta
80+
uses: docker/metadata-action@v5
81+
with:
82+
images: ${{ env.DOCKERHUB_ID }}/${{ env.IMAGE_NAME }}
83+
tags: |
84+
type=ref,event=branch
85+
type=ref,event=tag
86+
type=semver,pattern={{version}}
87+
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
88+
type=raw,value=${{ steps.inc_version.outputs.new_version }}
89+
90+
- name: Build and push PHP74 image
91+
id: build-and-push
92+
uses: docker/build-push-action@v6
93+
with:
94+
context: php74
95+
push: true
96+
tags: |
97+
${{ env.DOCKERHUB_ID }}/${{ env.IMAGE_NAME }}:latest
98+
${{ env.DOCKERHUB_ID }}/${{ env.IMAGE_NAME }}:${{ steps.inc_version.outputs.new_version }}
99+
labels: ${{ steps.meta.outputs.labels }}
100+
build-args: |
101+
PHP_VERSION=7.4
102+
USER_ID=1000
103+
GROUP_ID=1000
104+
PHP_VERSION_SHORT=74

0 commit comments

Comments
 (0)