Skip to content

Commit b1cc9cb

Browse files
committed
feat(cd): publish and pull from dockerhub
1 parent 2403417 commit b1cc9cb

File tree

3 files changed

+124
-7
lines changed

3 files changed

+124
-7
lines changed

.github/workflows/deploy.yaml

+115-6
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,117 @@ on:
1515
workflow_dispatch: # This allows us to trigger the workflow manually
1616

1717
jobs:
18+
dockerhub:
19+
name: Publish Docker Image(s) to Dockerhub
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
26+
- name: Set up QEMU
27+
uses: docker/setup-qemu-action@v3
28+
29+
- name: Set up Docker Buildx
30+
uses: docker/setup-buildx-action@v3
31+
32+
- name: Login to Docker Hub
33+
uses: docker/login-action@v3
34+
with:
35+
username: ${{ secrets.DOCKERHUB_USERNAME }}
36+
password: ${{ secrets.DOCKERHUB_PASSWORD }}
37+
38+
- name: Cache Docker layers for Wiki DB
39+
uses: actions/cache@v3
40+
with:
41+
path: /tmp/.buildx-cache-wiki-db
42+
key: ${{ runner.os }}-buildx-wiki-db-${{ github.sha }}
43+
restore-keys: |
44+
${{ runner.os }}-buildx-wiki-db-
45+
46+
- name: Build & Push Wiki DB
47+
uses: docker/build-push-action@v5
48+
with:
49+
context: ./mysql
50+
push: true
51+
tags: ${{ secrets.DOCKERHUB_USERNAME }}/wiki-db:latest
52+
cache-from: type=local,src=/tmp/.buildx-cache-wiki-db
53+
cache-to: type=local,dest=/tmp/.buildx-cache-wiki-db-new,mode=max
54+
55+
- name: Move Wiki DB cache
56+
run: |
57+
rm -rf /tmp/.buildx-cache-wiki-db
58+
mv /tmp/.buildx-cache-wiki-db-new /tmp/.buildx-cache-wiki-db
59+
60+
- name: Cache Docker layers for Wiki Jobs
61+
uses: actions/cache@v3
62+
with:
63+
path: /tmp/.buildx-cache-wiki-jobs
64+
key: ${{ runner.os }}-buildx-wiki-jobs-${{ github.sha }}
65+
restore-keys: |
66+
${{ runner.os }}-buildx-wiki-jobs-
67+
68+
- name: Build & Push Wiki Jobs
69+
uses: docker/build-push-action@v5
70+
with:
71+
context: ./jobs
72+
push: true
73+
tags: ${{ secrets.DOCKERHUB_USERNAME }}/wiki-jobs:latest
74+
cache-from: type=local,src=/tmp/.buildx-cache-wiki-jobs
75+
cache-to: type=local,dest=/tmp/.buildx-cache-wiki-jobs-new,mode=max
76+
77+
- name: Move Wiki Jobs cache
78+
run: |
79+
rm -rf /tmp/.buildx-cache-wiki-jobs
80+
mv /tmp/.buildx-cache-wiki-jobs-new /tmp/.buildx-cache-wiki-jobs
81+
82+
- name: Cache Docker layers for Wiki Nginx
83+
uses: actions/cache@v3
84+
with:
85+
path: /tmp/.buildx-cache-wiki-nginx
86+
key: ${{ runner.os }}-buildx-wiki-nginx-${{ github.sha }}
87+
restore-keys: |
88+
${{ runner.os }}-buildx-wiki-nginx-
89+
90+
- name: Build & Push Wiki Nginx
91+
uses: docker/build-push-action@v5
92+
with:
93+
context: ./nginx
94+
push: true
95+
tags: ${{ secrets.DOCKERHUB_USERNAME }}/wiki-nginx:latest
96+
cache-from: type=local,src=/tmp/.buildx-cache-wiki-nginx
97+
cache-to: type=local,dest=/tmp/.buildx-cache-wiki-nginx-new,mode=max
98+
99+
- name: Move Wiki Nginx cache
100+
run: |
101+
rm -rf /tmp/.buildx-cache-wiki
102+
mv /tmp/.buildx-cache-wiki-nginx-new /tmp/.buildx-cache-wiki-nginx
103+
104+
- name: Cache Docker layers for Wiki Mediawiki
105+
uses: actions/cache@v3
106+
with:
107+
path: /tmp/.buildx-cache-wiki
108+
key: ${{ runner.os }}-buildx-wiki-${{ github.sha }}
109+
restore-keys: |
110+
${{ runner.os }}-buildx-wiki-
111+
112+
- name: Build & Push Wiki Mediawiki
113+
uses: docker/build-push-action@v5
114+
with:
115+
context: ./mediawiki
116+
push: true
117+
tags: ${{ secrets.DOCKERHUB_USERNAME }}/wiki:latest
118+
cache-from: type=local,src=/tmp/.buildx-cache-wiki
119+
cache-to: type=local,dest=/tmp/.buildx-cache-wiki-new,mode=max
120+
121+
- name: Move Wiki Mediawiki cache
122+
run: |
123+
rm -rf /tmp/.buildx-cache-wiki-nginx
124+
mv /tmp/.buildx-cache-wiki-new /tmp/.buildx-cache-wiki
125+
18126
push:
19-
name: Push Stage
127+
name: Push Code Stage
128+
needs: dockerhub
20129
runs-on: ubuntu-latest
21130

22131
steps:
@@ -36,13 +145,13 @@ jobs:
36145
sudo git fetch origin
37146
sudo git reset --hard origin/master
38147
39-
build:
40-
name: Build Stage
148+
pull:
149+
name: Pull Image Stage
41150
needs: push
42151
runs-on: ubuntu-latest
43152

44153
steps:
45-
- name: Build the latest container(s)
154+
- name: Pull the latest images(s)
46155
uses: appleboy/ssh-action@master
47156
env:
48157
PROJECT_DIR: ${{ secrets.PROJECT_DIR }}
@@ -56,11 +165,11 @@ jobs:
56165
script_stop: true
57166
script: |
58167
cd "${PROJECT_DIR}/"
59-
sudo docker compose -f docker-compose.prod.yml build
168+
sudo docker compose -f docker-compose.prod.yml pull
60169
61170
deploy:
62171
name: Deploy Stage
63-
needs: [push, build]
172+
needs: pull
64173
runs-on: ubuntu-latest
65174

66175
steps:

docker-compose.prod.yml

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ include:
33

44
services:
55
jobs:
6+
image: metakgporg/wiki-jobs
7+
container_name: wiki-jobs
68
build: "./jobs"
79
restart: always
810
networks:

docker-compose.yml

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
services:
22
mysql:
3+
image: metakgporg/wiki-db
4+
container_name: wiki-db
35
build: "./mysql"
46
restart: always
57
networks:
@@ -15,6 +17,8 @@ services:
1517
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
1618

1719
mediawiki:
20+
image: metakgporg/wiki
21+
container_name: wiki
1822
build: "./mediawiki"
1923
restart: always
2024
networks:
@@ -37,6 +41,8 @@ services:
3741
- DEV=$DEV
3842

3943
nginx:
44+
image: metakgporg/wiki-nginx
45+
container_name: wiki-nginx
4046
build: "./nginx"
4147
restart: always
4248
networks:
@@ -64,4 +70,4 @@ volumes:
6470
static-volume:
6571
nginx-config-volume:
6672
external: true
67-
name: metaploy-nginx-config-volume
73+
name: metaploy-nginx-config-volume

0 commit comments

Comments
 (0)