Skip to content

Commit

Permalink
Merge pull request #333 from hngprojects/bugfix/update-dev-deploy
Browse files Browse the repository at this point in the history
chore: update dev deploy
augusthottie authored Aug 9, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents 70a7ae6 + 6b1d15b commit 221217c
Showing 2 changed files with 37 additions and 92 deletions.
67 changes: 37 additions & 30 deletions .github/workflows/dev-deploy.yml
Original file line number Diff line number Diff line change
@@ -7,58 +7,65 @@ on:
- dev

jobs:
build:
build_docker_image:
runs-on: ubuntu-latest
if: github.event.repository.fork == false
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v2

- name: Checkout code
uses: actions/checkout@v4
- name: Build Docker image
run: docker build -t golang_backend .

run: docker build -t golang_dev .
- name: Save and compress Docker image
run: docker save golang_backend | gzip > golang_backend.tar.gz

run: docker save golang_dev | gzip > golang_dev.tar.gz
- name: Upload Docker image
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: golang_backend
path: golang_backend.tar.gz

deploy:
needs: build
runs-on: ubuntu-latest
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
environment:
name: "development"
url: ${{ vars.URL }}

steps:
- name: Download Docker image
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4
with:
name: golang_backend
name: golang_dev
path: .

- name: Copy image to server
uses: appleboy/scp-action@master
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
password: ${{ secrets.SSH_PASSWORD }}
source: golang_backend.tar.gz
source: golang_dev.tar.gz
target: "/tmp"

run_docker_container:
runs-on: ubuntu-latest
needs: upload_docker_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: Deploy on server
uses: appleboy/ssh-action@master
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
password: ${{ secrets.SSH_PASSWORD }}
host: ${{ env.HOST }}
username: ${{ env.USERNAME }}
password: ${{ env.PASSWORD }}
script: |
gunzip -c /tmp/golang_backend.tar.gz | docker load
rm -f /tmp/golang_backend.tar.gz
cd ~/hng_boilerplate_golang_web
git checkout dev
git pull origin dev
docker compose -p golang up -d
gunzip -c /tmp/golang_dev.tar.gz | docker load
rm -f /tmp/golang_dev.tar.gz
cd ~/deployments/development
bash ./scripts/map_envs.sh app.env POSTGRES_USER=DB_USER POSTGRES_DB=DB_NAME POSTGRES_PASSWORD=PASSWORD
docker compose -f docker-compose.yml up -d
62 changes: 0 additions & 62 deletions .github/workflows/development.yml
Original file line number Diff line number Diff line change
@@ -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
@@ -157,26 +118,3 @@ jobs:
MIGRATE=true
run_docker_container:
runs-on: ubuntu-latest
needs: upload_docker_image
if: github.event.repository.fork == false && github.event_name == 'push'
environment: development
env:
SSH_USERNAME: ${{ secrets.SSH_USERNAME }}
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_PASSWORD: ${{ secrets.SSH_PASSWORD }}

steps:
- name: Deploy on server
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
bash ./scripts/map_envs.sh app.env POSTGRES_USER=DB_USER POSTGRES_DB=DB_NAME POSTGRES_PASSWORD=PASSWORD
docker compose -f docker-compose.yml up -d

0 comments on commit 221217c

Please sign in to comment.