Skip to content

Commit 57f8d5b

Browse files
committed
fix the deployments
1 parent 0b1e0f0 commit 57f8d5b

File tree

2 files changed

+46
-11
lines changed

2 files changed

+46
-11
lines changed

.github/workflows/deploy.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,51 @@ on:
55
branches:
66
- deploytest
77

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

@@ -34,6 +78,7 @@ jobs:
3478
3579
- name: Run Docker Compose
3680
run: |
81+
export GIT_COMMIT_HASH=$COMMIT_SHORT_SHA
3782
export DB_PASSWORD_PATH="/home/deploytest/db-password.txt"
3883
export DOCKER_HOST=ssh://[email protected]
3984
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)