Skip to content

Commit 6bf2537

Browse files
committed
fix the deployments
1 parent 0b1e0f0 commit 6bf2537

File tree

2 files changed

+60
-11
lines changed

2 files changed

+60
-11
lines changed

.github/workflows/deploy.yaml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,67 @@ on:
55
branches:
66
- deploytest
77

8+
permissions:
9+
packages: write
10+
811
jobs:
12+
commit-hash:
13+
runs-on: ubuntu-latest
14+
outputs:
15+
commit_hash: ${{ steps.get_commit.outputs.commit_hash }}
16+
steps:
17+
- name: Get commit hash
18+
id: get_commit
19+
run: echo "::set-output name=commit_hash::$(git rev-parse HEAD)"
20+
21+
build-and-test:
22+
runs-on: ubuntu-latest
23+
24+
steps:
25+
- uses: actions/checkout@v4
26+
- name: Setup Go
27+
uses: actions/setup-go@v5
28+
with:
29+
go-version: '1.22.x'
30+
- name: Install dependencies
31+
run: go get .
32+
- name: Build
33+
run: go build -v ./...
34+
- name: Test with the Go CLI
35+
run: go test
36+
37+
build-and-push-image:
38+
needs:
39+
- build-and-test
40+
- commit-hash
41+
runs-on: ubuntu-latest
42+
steps:
43+
- name: Checkout repository
44+
uses: actions/checkout@v3
45+
46+
- name: Set short git commit SHA
47+
id: vars
48+
run: |
49+
calculatedSha=$(git rev-parse --short ${{ github.sha }})
50+
echo "COMMIT_SHORT_SHA=$calculatedSha" >> $GITHUB_ENV
51+
52+
- name: Log in to the Container registry
53+
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
54+
with:
55+
registry: https://ghcr.io
56+
username: ${{ github.actor }}
57+
password: ${{ secrets.GITHUB_TOKEN }}
58+
59+
- name: Build and push Docker image
60+
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
61+
with:
62+
context: .
63+
push: true
64+
tags: ghcr.io/dreamsofcode-io/guestbook:${{ needs.commit-hash.outputs.commit_hash }}
65+
966
deploy:
1067
runs-on: ubuntu-latest
68+
needs: build-and-push-image
1169

1270
steps:
1371
- name: Checkout code
@@ -34,6 +92,7 @@ jobs:
3492
3593
- name: Run Docker Compose
3694
run: |
95+
export GIT_COMMIT_HASH=${{ needs.commit-hash.outputs.commit_hash }
3796
export DB_PASSWORD_PATH="/home/deploytest/db-password.txt"
3897
export DOCKER_HOST=ssh://deploytest@zenful.cloud
3998
docker-compose -f ./compose.prod.yaml up -d

compose.prod.yaml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
11
services:
2-
watchtower:
3-
image: containrrr/watchtower
4-
command:
5-
- "--label-enable"
6-
- "--interval"
7-
- "30"
8-
- "--rolling-restart"
9-
volumes:
10-
- /var/run/docker.sock:/var/run/docker.sock
112
reverse-proxy:
123
image: traefik:v3.1
134
command:
@@ -27,7 +18,7 @@ services:
2718
- letsencrypt:/letsencrypt
2819
- /var/run/docker.sock:/var/run/docker.sock
2920
guestbook:
30-
image: ghcr.io/dreamsofcode-io/guestbook:prod
21+
image: ghcr.io/dreamsofcode-io/guestbook:${GIT_COMMIT_HASH:-prod}
3122
labels:
3223
- "traefik.enable=true"
3324
- "traefik.http.middlewares.guestbook-ratelimit.ratelimit.average=20"
@@ -75,7 +66,6 @@ services:
7566
environment:
7667
- POSTGRES_DB=guestbook
7768
- POSTGRES_PASSWORD_FILE=/run/secrets/db-password
78-
#- POSTGRES_PASSWORD=${DB_PASSWORD}
7969
expose:
8070
- 5432
8171
healthcheck:

0 commit comments

Comments
 (0)