Skip to content

Commit

Permalink
ci(stack): add deploy script and prod action
Browse files Browse the repository at this point in the history
  • Loading branch information
esteinig committed Jan 26, 2024
1 parent 38adb7b commit 96dacd3
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/cicd-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: CI/CD Workflow

on:
pull_request:
branches: [ main ]
types: [ closed ]

jobs:
deploy:
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true && startsWith(github.head_ref, 'release/')

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup SSH Agent
uses: webfactory/ssh-agent@v0.8.0
with:
ssh-private-key: ${{ secrets.SSH_PRODUCTION_PRIVATE_KEY }}

- name: Deploy to production server
run: ssh ${{ secrets.SSH_PRODUCTION_SERVER }} 'bash -s' < scripts/deploy.sh prod ${{ secrets.SSH_PRODUCTION_PATH }}
41 changes: 41 additions & 0 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

# Navigate to your project directory
cd $2

# Depending on the environment, deploy the appropriate Docker Compose setup
if [ "$1" = "prod" ]; then
# Pull down the production stack
docker-compose -f docker-compose.web.yml --profile prod --profile server --project-name prod down

# Make sure we are on `main` and pull latest stable changes
# this is the latest release as this script is triggered
# by the `cicd.yml` action workflow

git checkout main
git pull origin main

# Rebuild to include latest changes and up the stack again
docker-compose -f docker-compose.web.yml --profile prod --profile server --project-name prod up --build -d

# Log this action
echo "$date Successfully deployed the production application" >> ~/brick_deploy_action.log

elif [ "$1" = "dev" ]; then
# Pull down the development stack
docker-compose -f docker-compose.web.yml --profile dev --profile server-dev --project-name dev down

# Make sure we are on `dev` and pull latest changes
git checkout dev
git pull origin dev

# Rebuild to include latest changes and up the stack again
docker-compose -f docker-compose.web.yml --profile dev --profile server-dev --project-name dev up --build -d

# Log this action
echo "$date Successfully deployed the development application" >> ~/brick_deploy_action.log

else
# Deployment script was run with invalid command-line input
echo "$date Failed to run deploy script - `$2` is not a valid option!" >> ~/brick_deploy_action.log
fi

0 comments on commit 96dacd3

Please sign in to comment.