Skip to content

Commit

Permalink
Merge pull request #358 from hngprojects/migration-patch
Browse files Browse the repository at this point in the history
Create and update workflow files
  • Loading branch information
vicradon authored Aug 15, 2024
2 parents 2e1c15b + 8bac613 commit 8929bae
Show file tree
Hide file tree
Showing 9 changed files with 251 additions and 1 deletion.
83 changes: 83 additions & 0 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Build, Test, and Deploy for Development

on:
push:
branches:
- dev

jobs:
build_and_upload_artifact:
runs-on: ubuntu-latest
if: github.event.repository.fork == false
environment: development
env:
SSH_USERNAME: ${{ secrets.SSH_USERNAME }}
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_PORT: ${{ secrets.SSH_PORT }}
SSH_KEY: ${{ secrets.SSH_KEY }}

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: Create app.env file
uses: vicradon/[email protected]
with:
action_input_file: "app-sample.env"
action_output_file: "app.env"
action_true_string_variables: |
MAIL_PASSWORD
SERVER_PORT: ${{ secrets.SERVER_PORT }}
DB_NAME: ${{ secrets.DB_NAME }}
USERNAME: ${{ secrets.USERNAME }}
APP_NAME: "development"
APP_URL: ${{ vars.URL}}
REDIS_PORT: ${{ secrets.REDIS_PORT }}
MAIL_SERVER: ${{ secrets.MAIL_SERVER }}
MAIL_USERNAME: ${{ secrets.MAIL_USERNAME }}
MAIL_PASSWORD: ${{ secrets.MAIL_PASSWORD }}
MAIL_PORT: ${{ secrets.MAIL_PORT }}
MIGRATE: "true"

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

restart_app:
runs-on: ubuntu-latest
needs: build_and_upload_artifact
environment: development
env:
SSH_USERNAME: ${{ secrets.SSH_USERNAME }}
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_PORT: ${{ secrets.SSH_PORT }}
SSH_PASSWORD: ${{ secrets.SSH_PASSWORD }}

steps:
- name: SSH into server and deploy
uses: appleboy/[email protected]
with:
host: ${{ env.SSH_HOST }}
username: ${{ env.SSH_USERNAME }}
password: ${{ env.SSH_PASSWORD }}
port: ${{ env.SSH_PORT }}
script: |
mkdir -p ~/deployments/development
cd ~/deployments/development
git reset --hard
git pull origin dev
pm2 restart development_app
83 changes: 83 additions & 0 deletions .github/workflows/prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Build, Test, and Deploy for Production

on:
push:
branches:
- main

jobs:
build_and_upload_artifact:
runs-on: ubuntu-latest
if: github.event.repository.fork == false
environment: production
env:
SSH_USERNAME: ${{ secrets.SSH_USERNAME }}
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_PORT: ${{ secrets.SSH_PORT }}
SSH_KEY: ${{ secrets.SSH_KEY }}

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 production_app

- name: Create app.env file
uses: vicradon/[email protected]
with:
action_input_file: "app-sample.env"
action_output_file: "app.env"
action_true_string_variables: |
MAIL_PASSWORD
SERVER_PORT: ${{ secrets.SERVER_PORT }}
DB_NAME: ${{ secrets.DB_NAME }}
USERNAME: ${{ secrets.USERNAME }}
APP_NAME: "production"
APP_URL: ${{ vars.URL}}
REDIS_PORT: ${{ secrets.REDIS_PORT }}
MAIL_SERVER: ${{ secrets.MAIL_SERVER }}
MAIL_USERNAME: ${{ secrets.MAIL_USERNAME }}
MAIL_PASSWORD: ${{ secrets.MAIL_PASSWORD }}
MAIL_PORT: ${{ secrets.MAIL_PORT }}
MIGRATE: "true"

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

restart_app:
runs-on: ubuntu-latest
needs: build_and_upload_artifact
environment: production
env:
SSH_USERNAME: ${{ secrets.SSH_USERNAME }}
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_PORT: ${{ secrets.SSH_PORT }}
SSH_PASSWORD: ${{ secrets.SSH_PASSWORD }}

steps:
- name: SSH into server and deploy
uses: appleboy/[email protected]
with:
host: ${{ env.SSH_HOST }}
username: ${{ env.SSH_USERNAME }}
password: ${{ env.SSH_PASSWORD }}
port: ${{ env.SSH_PORT }}
script: |
mkdir -p ~/deployments/production
cd ~/deployments/production
git reset --hard
git pull origin main
pm2 restart production_app
83 changes: 83 additions & 0 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Build, Test, and Deploy for Staging

on:
push:
branches:
- staging

jobs:
build_and_upload_artifact:
runs-on: ubuntu-latest
if: github.event.repository.fork == false
environment: staging
env:
SSH_USERNAME: ${{ secrets.SSH_USERNAME }}
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_PORT: ${{ secrets.SSH_PORT }}
SSH_KEY: ${{ secrets.SSH_KEY }}

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 staging_app

- name: Create app.env file
uses: vicradon/[email protected]
with:
action_input_file: "app-sample.env"
action_output_file: "app.env"
action_true_string_variables: |
MAIL_PASSWORD
SERVER_PORT: ${{ secrets.SERVER_PORT }}
DB_NAME: ${{ secrets.DB_NAME }}
USERNAME: ${{ secrets.USERNAME }}
APP_NAME: "staging"
APP_URL: ${{ vars.URL}}
REDIS_PORT: ${{ secrets.REDIS_PORT }}
MAIL_SERVER: ${{ secrets.MAIL_SERVER }}
MAIL_USERNAME: ${{ secrets.MAIL_USERNAME }}
MAIL_PASSWORD: ${{ secrets.MAIL_PASSWORD }}
MAIL_PORT: ${{ secrets.MAIL_PORT }}
MIGRATE: "true"

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

restart_app:
runs-on: ubuntu-latest
needs: build_and_upload_artifact
environment: staging
env:
SSH_USERNAME: ${{ secrets.SSH_USERNAME }}
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_PORT: ${{ secrets.SSH_PORT }}
SSH_PASSWORD: ${{ secrets.SSH_PASSWORD }}

steps:
- name: SSH into server and deploy
uses: appleboy/[email protected]
with:
host: ${{ env.SSH_HOST }}
username: ${{ env.SSH_USERNAME }}
password: ${{ env.SSH_PASSWORD }}
port: ${{ env.SSH_PORT }}
script: |
mkdir -p ~/deployments/staging
cd ~/deployments/staging
git reset --hard
git pull origin staging
pm2 restart staging_app
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ app.env

development_app
staging_app
production_app
production_app
.DS_Store
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 8929bae

Please sign in to comment.