-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci(stack): add deploy script and prod action
- Loading branch information
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
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
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 }} |
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
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 |