Merge pull request #340 from hngprojects/bugfix/workflow-step #13
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
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: Create app.env file | |
uses: ./.github/actions/create-env-action | |
with: | |
APP_NAME: "development" | |
APP_URL: "https://deployment.api-golang.boilerplate.hng.tech" | |
SERVER_PORT: ${{ secrets.SERVER_PORT }} | |
DB_NAME: ${{ secrets.DB_NAME }} | |
USERNAME: ${{ secrets.USERNAME }} | |
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" | |
- 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: Update app with latest changes | |
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 | |
- 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 | |
docker compose -f docker-compose.yml up -d |