Skip to content

Commit

Permalink
Merge branch 'dev' into update/org-and-api-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyberguru1 authored Aug 9, 2024
2 parents bc4fcce + ae5a5d6 commit 3d20297
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 117 deletions.
81 changes: 54 additions & 27 deletions .github/workflows/dev-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,66 +7,93 @@ on:
- dev

jobs:
build_docker_image:
build_and_upload_image:
runs-on: ubuntu-latest
if: github.event_name == 'push'
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: Upload Docker image
uses: actions/upload-artifact@v4
- name: Copy image to server
uses: appleboy/[email protected]
with:
name: golang_dev
path: golang_dev.tar.gz
host: ${{ env.SSH_HOST }}
username: ${{ env.SSH_USERNAME }}
password: ${{ env.SSH_PASSWORD }}
source: golang_dev.tar.gz
target: "/tmp"

upload_docker_image:
update_repo_and_create_env:
runs-on: ubuntu-latest
needs: build_docker_image
needs: build_and_upload_image
if: github.event.repository.fork == false
environment:
name: "development"
url: ${{ vars.URL }}
environment: development
env:
SSH_USERNAME: ${{ secrets.SSH_USERNAME }}
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_PASSWORD: ${{ secrets.SSH_PASSWORD }}
steps:
- name: Download Docker image
uses: actions/download-artifact@v4
- name: Checkout code
uses: actions/checkout@v4
- name: Create app.env file
uses: vicradon/[email protected]
with:
name: golang_dev
path: .
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 }}
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 image to server
- name: Copy app.env to server
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
password: ${{ secrets.SSH_PASSWORD }}
source: golang_dev.tar.gz
target: "/tmp"
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: upload_docker_image
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: Deploy on server
- name: Restart containers
uses: appleboy/[email protected]
with:
host: ${{ env.HOST }}
username: ${{ env.USERNAME }}
password: ${{ env.PASSWORD }}
script: |
gunzip -c /tmp/golang_dev.tar.gz | docker load
rm -f /tmp/golang_dev.tar.gz
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
91 changes: 1 addition & 90 deletions .github/workflows/development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,6 @@ on:
- dev

jobs:
build_docker_image:
runs-on: ubuntu-latest
if: github.event_name == 'push'
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: Upload Docker image
uses: actions/upload-artifact@v4
with:
name: golang_dev
path: golang_dev.tar.gz

upload_docker_image:
runs-on: ubuntu-latest
needs: build_docker_image
if: github.event.repository.fork == false && github.event_name == 'push'
environment:
name: "development"
url: ${{ vars.URL }}
steps:
- name: Download Docker image
uses: actions/download-artifact@v4
with:
name: golang_dev
path: .

- name: Copy image to server
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
password: ${{ secrets.SSH_PASSWORD }}
source: golang_dev.tar.gz
target: "/tmp"

build_and_test:
runs-on: ubuntu-latest
environment: development
Expand Down Expand Up @@ -103,55 +64,5 @@ jobs:
- name: Run All Tests
run: go test ./... -timeout 300s

deploy:
runs-on: ubuntu-latest
needs: build_and_test
if: github.event_name == 'push'
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: |
export APPROOT=~/deployments/development
mkdir -p $APPROOT
cd $APPROOT
if [ -d "$APPROOT/.git" ]; then
# Navigate to the repository directory and pull changes
cd $APPROOT || { echo "Failed to navigate to web root directory"; exit 1; }
git reset --hard HEAD || { echo "Failed to reset local changes"; exit 1; }
git pull origin dev || { echo "Failed to pull latest changes"; exit 1; }
else
git clone -b dev https://github.com/${{ github.repository}} . || { echo "Failed to clone repository"; exit 1; }
fi

bash ./scripts/deploy_app.sh development https://github.com/${{ github.repository}} \
SERVER_PORT=${{ secrets.SERVER_PORT }} \
DB_NAME=${{ secrets.DB_NAME }} \
USERNAME=${{ secrets.USERNAME }} \
APP_NAME="development" \
APP_URL="https://deployment.api-golang.boilerplate.hng.tech" \
REDIS_PORT=${{ secrets.REDIS_PORT }} \
REDIS_HOST=${{ secrets.REDIS_HOST }} \
REDIS_DB="0" \
GOOGLE_CLIENT_ID=${{ secrets.GOOGLE_CLIENT_ID }} \
GOOGLE_CLIENT_SECRET=${{ secrets.GOOGLE_CLIENT_SECRET }} \
FACEBOOK_CLIENT_ID=${{ secrets.FACEBOOK_CLIENT_ID }} \
FACEBOOK_CLIENT_SECRET=${{ secrets.FACEBOOK_CLIENT_SECRET }} \
SESSION_SECRET=${{ secrets.SESSION_SECRET }} \
MAIL_SERVER=${{ secrets.MAIL_SERVER }} \
MAIL_USERNAME=${{ secrets.MAIL_USERNAME }} \
MAIL_PASSWORD=${{ secrets.MAIL_PASSWORD }} \
MAIL_PORT=${{ secrets.MAIL_PORT }} \
MIGRATE=true

0 comments on commit 3d20297

Please sign in to comment.