Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploytest #2

Closed
wants to merge 17 commits into from
Prev Previous commit
Next Next commit
fix the deployments
  • Loading branch information
elliottminns committed Nov 12, 2024
commit ed045110292c854e0bf85c72b61d21dcd293282a
59 changes: 59 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,67 @@ on:
branches:
- deploytest

permissions:
packages: write

jobs:
commit-hash:
runs-on: ubuntu-latest
outputs:
commit_hash: ${{ steps.get_commit.outputs.commit_hash }}
steps:
- name: Get commit hash
id: get_commit
run: echo "::set-output name=commit_hash::$(git rev-parse HEAD)"

build-and-test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.22.x'
- name: Install dependencies
run: go get .
- name: Build
run: go build -v ./...
- name: Test with the Go CLI
run: go test

build-and-push-image:
needs:
- build-and-test
- commit-hash
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set short git commit SHA
id: vars
run: |
calculatedSha=$(git rev-parse --short ${{ github.sha }})
echo "COMMIT_SHORT_SHA=$calculatedSha" >> $GITHUB_ENV

- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: https://ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
push: true
tags: ghcr.io/dreamsofcode-io/guestbook:${{ needs.commit-hash.outputs.commit_hash }}

deploy:
runs-on: ubuntu-latest
needs: build-and-push-image

steps:
- name: Checkout code
Expand All @@ -34,6 +92,7 @@ jobs:

- name: Run Docker Compose
run: |
export GIT_COMMIT_HASH=${{ needs.commit-hash.outputs.commit_hash }}
export DB_PASSWORD_PATH="/home/deploytest/db-password.txt"
export DOCKER_HOST=ssh://deploytest@zenful.cloud
docker-compose -f ./compose.prod.yaml up -d
12 changes: 1 addition & 11 deletions compose.prod.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
services:
watchtower:
image: containrrr/watchtower
command:
- "--label-enable"
- "--interval"
- "30"
- "--rolling-restart"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
reverse-proxy:
image: traefik:v3.1
command:
Expand All @@ -27,7 +18,7 @@ services:
- letsencrypt:/letsencrypt
- /var/run/docker.sock:/var/run/docker.sock
guestbook:
image: ghcr.io/dreamsofcode-io/guestbook:prod
image: ghcr.io/dreamsofcode-io/guestbook:${GIT_COMMIT_HASH:-prod}
labels:
- "traefik.enable=true"
- "traefik.http.middlewares.guestbook-ratelimit.ratelimit.average=20"
Expand Down Expand Up @@ -75,7 +66,6 @@ services:
environment:
- POSTGRES_DB=guestbook
- POSTGRES_PASSWORD_FILE=/run/secrets/db-password
#- POSTGRES_PASSWORD=${DB_PASSWORD}
expose:
- 5432
healthcheck:
Expand Down
Loading