Skip to content

Commit 258b165

Browse files
committed
#39 [docker public hub] feat: public nginx image
1 parent 76cb28b commit 258b165

File tree

3 files changed

+124
-1
lines changed

3 files changed

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

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ services:
1414
## WEB SERVICE
1515
nginx:
1616
container_name: "${COMPOSE_PROJECT_NAME}-nginx"
17+
image: cslant/blog-nginx
1718
build:
1819
context: nginx
1920
args:

nginx/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
ARG PHP_VERSION=8.3
22
ARG PHP_VERSION_SHORT=83
33

4-
FROM nginx:1.26.0-alpine
4+
FROM nginx:1.27.0-alpine
55
LABEL maintainer="Tan Nguyen <[email protected]>"
66
LABEL authors="cslant"
77
LABEL description="Nginx image for CSlant development - Using for Blog"

0 commit comments

Comments
 (0)