Skip to content

Commit

Permalink
feat: cd pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
proffapt committed Apr 20, 2024
1 parent 37dd92a commit 6d05937
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Continuous Deployment Pipeline

on:
push:
branches:
- "master"
paths:
- "go.mod"
- "go.sum"
- "main.go"
- "Dockerfile"
- "docker-compose.yml"
- "metaploy/**"
- ".github/workflows/deploy.yaml"

jobs:
push:
name: Push Stage
runs-on: ubuntu-latest

steps:
- name: Sync local repo with remote repo
uses: appleboy/ssh-action@master
env:
PROJECT_DIR: ${{ secrets.PROJECT_DIR }}
with:
host: ${{ secrets.SSH_HOSTNAME }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
passphrase: ${{ secrets.SSH_PRIVATE_KEY_PASSPHRASE }}
envs: PROJECT_DIR
script_stop: true
script: |
cd "${PROJECT_DIR}/"
sudo git fetch origin
sudo git reset --hard origin/master
build:
name: Build Stage
needs: push
runs-on: ubuntu-latest

steps:
- name: Build the latest container(s)
uses: appleboy/ssh-action@master
env:
PROJECT_DIR: ${{ secrets.PROJECT_DIR }}
with:
host: ${{ secrets.SSH_HOSTNAME }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
passphrase: ${{ secrets.SSH_PRIVATE_KEY_PASSPHRASE }}
envs: PROJECT_DIR
script_stop: true
script: |
cd "${PROJECT_DIR}/"
sudo docker compose build
deploy:
name: Deploy Stage
needs: [push, build]
runs-on: ubuntu-latest

steps:
- name: Deploy the latest build(s)
uses: appleboy/ssh-action@master
env:
PROJECT_DIR: ${{ secrets.PROJECT_DIR }}
with:
host: ${{ secrets.SSH_HOSTNAME }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
passphrase: ${{ secrets.SSH_PRIVATE_KEY_PASSPHRASE }}
envs: PROJECT_DIR
script_stop: true
script: |
cd "${PROJECT_DIR}/"
sudo docker compose down
sudo docker compose up -d

0 comments on commit 6d05937

Please sign in to comment.