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

chore: add staging deploy #343

Merged
merged 1 commit into from
Aug 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
name: Build, Test, and Deploy for Development
name: Build Binary and Run Tests

on:
pull_request:
branches:
- dev
branches: [dev]

jobs:
build_and_test:
Expand Down Expand Up @@ -63,6 +62,3 @@ jobs:
done
- name: Run All Tests
run: go test ./... -timeout 300s



99 changes: 99 additions & 0 deletions .github/workflows/staging-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Dev Deployment

on:
workflow_dispatch:
push:
branches:
- staging

jobs:
build_and_upload_image:
runs-on: ubuntu-latest
if: github.event.repository.fork == false
environment: staging
env:
SSH_USERNAME: ${{ secrets.SSH_USERNAME }}
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_PASSWORD: ${{ secrets.SSH_PASSWORD }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Build Docker image
run: docker build -t golang_staging .
- name: Save and compress Docker image
run: docker save golang_staging | gzip > golang_staging.tar.gz
- name: Copy image to server
uses: appleboy/[email protected]
with:
host: ${{ env.SSH_HOST }}
username: ${{ env.SSH_USERNAME }}
password: ${{ env.SSH_PASSWORD }}
source: golang_staging.tar.gz
target: "/tmp"

update_repo_and_create_env:
runs-on: ubuntu-latest
needs: build_and_upload_image
if: github.event.repository.fork == false
environment: staging
env:
SSH_USERNAME: ${{ secrets.SSH_USERNAME }}
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_PASSWORD: ${{ secrets.SSH_PASSWORD }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Create app.env file
uses: vicradon/[email protected]
with:
action_input_file: "app-sample.env"
APP_NAME: "staging"
APP_URL: "https://staging.api-golang.boilerplate.hng.tech"
SERVER_PORT: ${{ secrets.SERVER_PORT }}
USERNAME: ${{ secrets.USERNAME }}
PASSWORD: ${{ secrets.PASSWORD }}
DB_NAME: ${{ secrets.DB_NAME }}
POSTGRES_USER: ${{ secrets.USERNAME }}
POSTGRES_PASSWORD: ${{ secrets.PASSWORD }}
POSTGRES_DB: ${{ secrets.DB_NAME }}
REDIS_PORT: ${{ secrets.REDIS_PORT }}
REDIS_HOST: ${{ secrets.REDIS_HOST }}
REDIS_DB: "0"
MAIL_SERVER: ${{ secrets.MAIL_SERVER }}
MAIL_USERNAME: ${{ secrets.MAIL_USERNAME }}
MAIL_PASSWORD: ${{ secrets.MAIL_PASSWORD }}
MAIL_PORT: ${{ secrets.MAIL_PORT }}
MIGRATE: "true"

- name: Copy app.env to server
uses: appleboy/[email protected]
with:
host: ${{ env.SSH_HOST }}
username: ${{ env.SSH_USERNAME }}
password: ${{ env.SSH_PASSWORD }}
source: app.env
target: "~/deployments/staging"

run_docker_container:
runs-on: ubuntu-latest
needs: [build_and_upload_image, update_repo_and_create_env]
if: github.event.repository.fork == false
environment: staging
env:
SSH_USERNAME: ${{ secrets.SSH_USERNAME }}
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_PASSWORD: ${{ secrets.SSH_PASSWORD }}
steps:
- name: Restart containers
uses: appleboy/[email protected]
with:
host: ${{ env.HOST }}
username: ${{ env.USERNAME }}
password: ${{ env.PASSWORD }}
script: |
cd ~/deployments/staging
git reset --hard
git pull origin staging
gunzip -c /tmp/golang_staging.tar.gz | docker load
rm -f /tmp/golang_staging.tar.gz
docker compose -f docker-compose-staging.yml up -d
185 changes: 0 additions & 185 deletions .github/workflows/staging.yml

This file was deleted.

6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,9 @@ app.env
tmp/
.idea/


dump.rdb
app.env

development_app
staging_app
production_app
Binary file removed development_app
Binary file not shown.
44 changes: 0 additions & 44 deletions docker-compose-development.yml

This file was deleted.

4 changes: 3 additions & 1 deletion docker-compose-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
env_file:
- app.env
volumes:
- ../pgsql_volumes/golang_staging/:/var/lib/postgresql/data
- ../golang_volumes/pgsql_volumes/golang_staging/:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U staging_user"]
interval: 10s
Expand All @@ -15,6 +15,8 @@ services:

redis:
image: redis:latest
volumes:
- ../golang_volumes/redis_volumes/golang_staging/:/data

backend:
image: golang_staging
Expand Down
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ services:
POSTGRES_PASSWORD: password
POSTGRES_USER: development_user
volumes:
- ../pgsql_volumes/golang_dev/:/var/lib/postgresql/data
- ../golang_volumes/pgsql_volumes/golang_dev/:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U development_user"]
interval: 10s
Expand All @@ -19,6 +19,8 @@ services:

redis:
image: redis:latest
volumes:
- ../golang_volumes/redis_volumes/golang_dev/:/data

backend:
image: golang_dev
Expand Down
Binary file removed dump.rdb
Binary file not shown.
Loading
Loading