Skip to content

Commit c89c712

Browse files
authored
Merge pull request #43 from cslant/feature/public-docker-hub
Feature/public docker hub
2 parents 3f98830 + f240dcd commit c89c712

File tree

4 files changed

+124
-7
lines changed

4 files changed

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

.github/workflows/php-docker-public.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Publish PHP Docker image
1+
name: Publish PHP image to Docker Hub
22

33
on:
44
push:

.github/workflows/worker-docker-public.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Publish Worker Docker image
1+
name: Publish Worker image to Docker Hub
22

33
on:
44
push:

docker-compose.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ services:
5050
## BACKEND SERVICES
5151
php:
5252
container_name: "${COMPOSE_PROJECT_NAME:-blog}-php"
53+
image: cslant/blog-php
5354
build:
5455
context: php
5556
args:
@@ -77,6 +78,7 @@ services:
7778
## FRONTEND SERVICES
7879
node:
7980
container_name: "${COMPOSE_PROJECT_NAME:-blog}-node"
81+
image: cslant/blog-node
8082
build:
8183
context: node
8284
args:
@@ -87,11 +89,6 @@ services:
8789
- cslant_blog
8890
volumes:
8991
- ${SOURCE_CODE_PATH}:/var/dev
90-
environment:
91-
- BLOG_DOMAIN=${BLOG_DOMAIN}
92-
- BLOG_API_DOMAIN=${BLOG_API_DOMAIN}
93-
- BLOG_ADMIN_DOMAIN=${BLOG_ADMIN_DOMAIN}
94-
- BLOG_ADMIN_DIR=${BLOG_ADMIN_DIR}
9592

9693
fe:
9794
container_name: "${COMPOSE_PROJECT_NAME}-fe"
@@ -158,6 +155,7 @@ services:
158155

159156
worker:
160157
container_name: "${COMPOSE_PROJECT_NAME}-worker"
158+
image: cslant/blog-worker
161159
build:
162160
context: worker
163161
args:

0 commit comments

Comments
 (0)