Skip to content

Commit 2520cab

Browse files
committed
fix: update Dockerfile for MySQL image and add GitHub Actions workflow for publishing
1 parent ad12be6 commit 2520cab

File tree

2 files changed

+100
-1
lines changed

2 files changed

+100
-1
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: Publish MySql 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-mysql57
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 mysql57 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 vmysql57 prefix
41+
latest_tag=$(git tag -l | grep -E '^vmysql57' | 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 mysql57 image
91+
id: build-and-push
92+
uses: docker/build-push-action@v6
93+
with:
94+
context: mysql57
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 }}

mysql/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ FROM mysql:8.0.35
22

33
LABEL maintainer="Tan Nguyen <[email protected]>"
44
LABEL authors="cslant"
5-
LABEL description="Postgres image for CSlant development"
5+
LABEL description="MySQL image for CSlant development"
66

77
#####################################
88
# Set Timezone

0 commit comments

Comments
 (0)