Merge pull request #333 from hngprojects/bugfix/update-dev-deploy #5
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_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 | |
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" | |
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/[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 |