-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #348 from hngprojects/dev
Chore: Merge dev to staging
- Loading branch information
Showing
63 changed files
with
1,996 additions
and
794 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
name: Build Binary and Run Tests | ||
|
||
on: | ||
pull_request: | ||
branches: [dev] | ||
|
||
jobs: | ||
build_and_test: | ||
runs-on: ubuntu-latest | ||
environment: development | ||
env: | ||
TEST_USERNAME: postgres | ||
TEST_PASSWORD: password | ||
TEST_DB_NAME: db_name | ||
TEST_DB_HOST: localhost | ||
TEST_DB_PORT: 5432 | ||
TEST_DB_CONNECTION: pgsql | ||
TEST_TIMEZONE: Africa/Lagos | ||
TEST_SSLMODE: disable | ||
TEST_MIGRATE: true | ||
REDIS_PORT: 6379 | ||
REDIS_HOST: localhost | ||
REDIS_DB: 0 | ||
|
||
services: | ||
postgres: | ||
image: postgres:latest | ||
env: | ||
POSTGRES_USER: ${{ env.TEST_USERNAME }} | ||
POSTGRES_PASSWORD: ${{ env.TEST_PASSWORD }} | ||
POSTGRES_DB: ${{ env.TEST_DB_NAME }} | ||
ports: | ||
- 5432:5432 | ||
redis: | ||
image: redis | ||
options: >- | ||
--health-cmd "redis-cli ping" | ||
--health-interval 10s | ||
--health-timeout 5s | ||
--health-retries 5 | ||
ports: | ||
- 6379:6379 | ||
|
||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@v4 | ||
- name: Set Golang | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: "1.22.1" | ||
- name: Create app config file | ||
run: cp app-sample.env app.env | ||
- name: Build the application | ||
run: go build -o development_app | ||
- name: Run the application | ||
run: nohup ./development_app > /dev/null 2>&1 & | ||
- name: Wait for application to start | ||
run: | | ||
for i in {1..30}; do | ||
curl -s http://localhost:8019 && break | ||
sleep 1 | ||
done | ||
- name: Run All Tests | ||
run: go test ./... -timeout 300s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
name: Dev Deployment | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- dev | ||
|
||
jobs: | ||
build_and_upload_image: | ||
runs-on: ubuntu-latest | ||
if: github.event.repository.fork == false | ||
environment: development | ||
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_dev . | ||
- name: Save and compress Docker image | ||
run: docker save golang_dev | gzip > golang_dev.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_dev.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: development | ||
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: "development" | ||
APP_URL: "https://deployment.api-golang.boilerplate.hng.tech" | ||
SERVER_PORT: ${{ secrets.SERVER_PORT }} | ||
USERNAME: ${{ secrets.USERNAME }} | ||
PASSWORD: ${{ secrets.PASSWORD }} | ||
DB_NAME: ${{ secrets.DB_NAME }} | ||
DB_HOST: ${{ secrets.DB_HOST }} | ||
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/development" | ||
|
||
run_docker_container: | ||
runs-on: ubuntu-latest | ||
needs: [build_and_upload_image, update_repo_and_create_env] | ||
if: github.event.repository.fork == false | ||
environment: development | ||
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/development | ||
git reset --hard | ||
git pull origin dev | ||
gunzip -c /tmp/golang_dev.tar.gz | docker load | ||
rm -f /tmp/golang_dev.tar.gz | ||
docker compose -f docker-compose.yml up -d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.