-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into Lanky-23-patch-1
- Loading branch information
Showing
12 changed files
with
220 additions
and
69 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
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 |
---|---|---|
@@ -1,40 +1,61 @@ | ||
name: Build, Test, and Deploy for Dev Branch | ||
name: Deploy to Dev | ||
|
||
on: | ||
push: | ||
branches: | ||
- dev | ||
workflow_run: | ||
workflows: [CI] | ||
types: | ||
- completed | ||
branches: [dev] | ||
|
||
jobs: | ||
build: | ||
runs-on: self-hosted | ||
defaults: | ||
run: | ||
working-directory: /var/www/aihomework/dev | ||
|
||
deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Pull from github | ||
id: pull | ||
run: | | ||
git stash | ||
git pull origin dev | ||
- name: install dependencies | ||
run: yarn install | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
# - name: Install sshpass | ||
# run: sudo apt-get install sshpass | ||
|
||
- name: Run Test | ||
run: yarn test | ||
|
||
- name: buld the dist | ||
run: yarn build | ||
- name: Fetch .env file from server | ||
run: | | ||
sshpass -p ${{ secrets.PASSWORD }} scp -o StrictHostKeyChecking=no ${{ secrets.USERNAME }}@${{ secrets.HOST }}:/var/www/aihomework/dev/.env .env | ||
env: | ||
SSH_HOST: ${{ secrets.HOST }} | ||
SSH_USERNAME: ${{ secrets.USERNAME }} | ||
SSH_PASSWORD: ${{ secrets.PASSWORD }} | ||
|
||
- name: migrate | ||
run: yarn reset-db | ||
- name: Build Docker images | ||
run: | | ||
docker compose --env-file .env -f docker-compose.yml build | ||
- name: setup service file | ||
run: sudo cp server-script/aihomeworkdev.service /etc/systemd/system | ||
- name: List Docker images | ||
run: docker images | ||
|
||
- name: start the app | ||
- name: Save Docker images to tarball | ||
run: | | ||
sudo systemctl daemon-reload | ||
sudo systemctl restart aihomeworkdev | ||
docker save hng_boilerplate_expressjs-backend:latest | gzip > dev-images.tar.gz | ||
- name: Copy Docker images to server | ||
uses: appleboy/scp-action@master | ||
with: | ||
host: ${{ secrets.HOST }} | ||
username: ${{ secrets.USERNAME }} | ||
password: ${{ secrets.PASSWORD }} | ||
source: "dev-images.tar.gz" | ||
target: "~/images-tar" | ||
|
||
- name: Deploy to server | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.HOST }} | ||
username: ${{ secrets.USERNAME }} | ||
password: ${{ secrets.PASSWORD }} | ||
script: | | ||
cd ~/dev-deployment/hng_boilerplate_expressjs | ||
git stash | ||
git checkout dev | ||
git pull | ||
docker load -i ~/images-tar/dev-images.tar.gz | ||
docker compose -f docker-compose.yml down | ||
docker compose -f docker-compose.yml up -d |
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
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 |
---|---|---|
@@ -1,35 +1,74 @@ | ||
name: Build, Test, and Deploy for Prod Branch | ||
name: Deploy to Prod | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
workflow_run: | ||
workflows: [CI] | ||
types: | ||
- completed | ||
branches: [prod] | ||
|
||
jobs: | ||
build: | ||
runs-on: self-hosted | ||
defaults: | ||
run: | ||
working-directory: /var/www/aihomework/prod | ||
|
||
on-success: | ||
runs-on: ubuntu-latest | ||
if: ${{ github.event.workflow_run.conclusion == 'success' }} | ||
steps: | ||
- name: Pull from GitHub | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install sshpass | ||
run: sudo apt-get install sshpass | ||
|
||
- name: Fetch .env file from server | ||
run: | | ||
sshpass -p ${{ secrets.PASSWORD }} scp -o StrictHostKeyChecking=no ${{ secrets.USERNAME }}@${{ secrets.HOST }}:~/prod-deployment/hng_boilerplate_expressjs/.env .env | ||
env: | ||
SSH_HOST: ${{ secrets.HOST }} | ||
SSH_USERNAME: ${{ secrets.USERNAME }} | ||
SSH_PASSWORD: ${{ secrets.PASSWORD }} | ||
|
||
- name: Build Docker images | ||
run: | | ||
git stash | ||
git pull origin main | ||
docker compose --env-file .env -f docker-compose.production.yml build | ||
- name: Install dependencies | ||
run: yarn install | ||
- name: List Docker images | ||
run: docker images | ||
|
||
- name: Build the dist | ||
run: yarn build | ||
- name: Save Docker images to tarball | ||
run: | | ||
docker save hng_boilerplate_expressjs-backend_prod:latest | gzip > prod-images.tar.gz | ||
- name: migrate | ||
run: yarn migrate | ||
- name: Upload artifact | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: prod-images | ||
path: prod-images.tar.gz | ||
|
||
- name: Setup service file | ||
run: sudo cp server-script/aihomeworkprod.service /etc/systemd/system | ||
- name: Copy Docker images to server | ||
uses: appleboy/scp-action@master | ||
with: | ||
host: ${{ secrets.HOST }} | ||
username: ${{ secrets.USERNAME }} | ||
password: ${{ secrets.PASSWORD }} | ||
source: "prod-images.tar.gz" | ||
target: "~/images-tar" | ||
|
||
- name: Start the app | ||
run: | | ||
sudo systemctl daemon-reload | ||
sudo systemctl restart aihomeworkprod | ||
- name: Deploy to server | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.HOST }} | ||
username: ${{ secrets.USERNAME }} | ||
password: ${{ secrets.PASSWORD }} | ||
script: | | ||
cd ~/prod-deployment/hng_boilerplate_expressjs | ||
git stash | ||
git checkout prod | ||
git pull | ||
docker load -i ~/images-tar/prod-images.tar.gz | ||
docker compose -f docker-compose.production.yml down | ||
docker compose -f docker-compose.production.yml up -d | ||
on-failure: | ||
runs-on: ubuntu-latest | ||
if: ${{ github.event.workflow_run.conclusion == 'failure' }} | ||
steps: | ||
- run: echo "CI Workflow failed. Prod deployment was not triggered." |
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,58 @@ | ||
name: Deploy to staging | ||
|
||
on: | ||
workflow_run: | ||
workflows: [CI] | ||
types: | ||
- completed | ||
branches: [staging] | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Fetch .env file from server | ||
run: | | ||
sshpass -p ${{ secrets.PASSWORD }} scp -o StrictHostKeyChecking=no ${{ secrets.USERNAME }}@${{ secrets.HOST }}:~/staging-deployment/hng_boilerplate_expressjs/.env .env | ||
env: | ||
SSH_HOST: ${{ secrets.HOST }} | ||
SSH_USERNAME: ${{ secrets.USERNAME }} | ||
SSH_PASSWORD: ${{ secrets.PASSWORD }} | ||
|
||
- name: Build Docker images | ||
run: | | ||
docker compose --env-file .env -f docker-compose.staging.yml build | ||
- name: List Docker images | ||
run: docker images | ||
|
||
- name: Save Docker images to tarball | ||
run: | | ||
docker save hng_boilerplate_expressjs-backend_staging:latest | gzip > staging-images.tar.gz | ||
- name: Copy Docker images to server | ||
uses: appleboy/scp-action@master | ||
with: | ||
host: ${{ secrets.HOST }} | ||
username: ${{ secrets.USERNAME }} | ||
password: ${{ secrets.PASSWORD }} | ||
source: "staging-images.tar.gz" | ||
target: "~/images-tar" | ||
|
||
- name: Deploy to server | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.HOST }} | ||
username: ${{ secrets.USERNAME }} | ||
password: ${{ secrets.PASSWORD }} | ||
script: | | ||
cd ~/staging-deployment/hng_boilerplate_expressjs | ||
git stash | ||
git checkout staging | ||
git pull | ||
docker load -i ~/images-tar/staging-images.tar.gz | ||
docker compose -f docker-compose.staging.yml down | ||
docker compose -f docker-compose.staging.yml up -d |
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
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
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
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,13 @@ | ||
[Unit] | ||
Description=AIHomework-Dev | ||
After=network.target | ||
|
||
[Service] | ||
WorkingDirectory=/var/www/aihomework/staging | ||
ExecStart=/bin/bash /var/www/aihomework/dev/server-script/startappstaging.sh | ||
#Restart=on-failure | ||
#RestartSec=20s | ||
StartLimitInterval=0 | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
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,5 @@ | ||
#!/bin/bash | ||
|
||
cd /var/www/aihomework/staging/ | ||
mkdir -p logs | ||
/usr/bin/yarn start >> logs/stagingoutput.log 2>&1 |
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
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