Skip to content

Commit

Permalink
Merge pull request #329 from hngprojects/golang-bug
Browse files Browse the repository at this point in the history
Golang bug
  • Loading branch information
ThePrimeJnr authored Aug 9, 2024
2 parents 900c965 + b27f78b commit 2ff67da
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 23 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/dev-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Dev Deployment

on:
workflow_dispatch:
push:
branches:
- dev

jobs:
build:
runs-on: ubuntu-latest
if: github.event.repository.fork == false
steps:
- uses: actions/checkout@v2

- name: Build Docker image
run: docker build -t golang_backend .

- name: Save and compress Docker image
run: docker save golang_backend | gzip > golang_backend.tar.gz

- name: Upload Docker image
uses: actions/upload-artifact@v2
with:
name: golang_backend
path: golang_backend.tar.gz

deploy:
needs: build
runs-on: ubuntu-latest

environment:
name: "development"
url: ${{ vars.URL }}

steps:
- name: Download Docker image
uses: actions/download-artifact@v2
with:
name: golang_backend
path: .

- name: Copy image to server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
source: golang_backend.tar.gz
target: "/tmp"

- name: Deploy on server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
script: |
gunzip -c /tmp/golang_backend.tar.gz | docker load
rm -f /tmp/golang_backend.tar.gz
cd ~/hng_boilerplate_golang_web
docker compose -p golang up -d
5 changes: 1 addition & 4 deletions .github/workflows/development.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
name: Build, Test, and Deploy for Development

on:
push:
branches:
- dev
pull_request:
branches:
- dev
Expand Down Expand Up @@ -181,4 +178,4 @@ jobs:
gunzip -c /tmp/golang_dev.tar.gz | docker load
rm -f /tmp/golang_dev.tar.gz
cd ~/deployments/development
docker compose -f docker-compose.yml up -d
docker compose -f docker-compose.yml up -d
26 changes: 8 additions & 18 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,34 @@
name: golang_dev
name: golang

services:
db:
image: postgres:16
environment:
POSTGRES_USER: development_user
POSTGRES_PASSWORD: password
POSTGRES_DB: development_db
POSTGRES_PORT: 5432
env_file:
- ./app.env
volumes:
- db_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 10s
timeout: 10s
retries: 2

redis:
image: redis:latest

backend:
image: ${COMPOSE_PROJECT_NAME}
image: golang_backend
build:
context: .
depends_on:
- db
- redis
ports:
- "8000:7000"
env_file:
- app.env
- ./app.env

nginx:
image: nginx:latest
ports:
- "8115:80"
- "7000:80"
depends_on:
- backend
volumes:
- ./nginx/nginx.dev.conf:/etc/nginx/nginx.conf
- ./nginx.conf:/etc/nginx/nginx.conf

volumes:
db_data:
db_data:
2 changes: 1 addition & 1 deletion nginx/nginx.dev.conf → nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ events { worker_connections 1024; }
http {
upstream backend {
least_conn;
server backend:8000;
server backend:7000;
}

server {
Expand Down

0 comments on commit 2ff67da

Please sign in to comment.