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: push workflow changes from dev into staging #360

Merged
merged 7 commits into from
Aug 15, 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
3 changes: 0 additions & 3 deletions .github/workflows/dev-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ name: Dev Deployment

on:
workflow_dispatch:
push:
branches:
- dev

jobs:
build_and_upload_image:
Expand Down
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_PASSWORD: ${{ secrets.SSH_PASSWORD }}

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_PASSWORD: ${{ secrets.SSH_PASSWORD }}

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
3 changes: 0 additions & 3 deletions .github/workflows/staging-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ name: Staging Deployment

on:
workflow_dispatch:
push:
branches:
- staging

jobs:
build_and_upload_image:
Expand Down
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_PASSWORD: ${{ secrets.SSH_PASSWORD }}

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.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ services:
image: redis:latest

backend:
image: golang_prod
image: golang_prod:latest
build:
context: .
depends_on:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ services:
- ../golang_volumes/redis_volumes/golang_staging/:/data

backend:
image: golang_staging
image: golang_staging:latest
build:
context: .
depends_on:
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml → docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ services:
- ../golang_volumes/redis_volumes/golang_dev/:/data

backend:
image: golang_dev
image: golang_dev:latest
build:
context: .
depends_on:
Expand Down
File renamed without changes.
Loading