forked from hngprojects/hng_boilerplate_expressjs
-
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.
Merge pull request hngprojects#565 from hngprojects/Rob-in-son-dev.yml1
Update cd files
- Loading branch information
Showing
3 changed files
with
86 additions
and
52 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,35 +1,56 @@ | ||
name: Build, Test, and Deploy for Prod Branch | ||
name: Deploy to staging Branch | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
branches: | ||
- dev | ||
|
||
jobs: | ||
build: | ||
runs-on: self-hosted | ||
defaults: | ||
run: | ||
working-directory: /var/www/aihomework/prod | ||
|
||
build-and-deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Pull from GitHub | ||
run: | | ||
git stash | ||
git pull origin main | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install dependencies | ||
run: yarn install | ||
- name: Install sshpass | ||
run: sudo apt-get install sshpass | ||
|
||
- name: Build 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/staging/.env .env | ||
env: | ||
SSH_HOST: ${{ secrets.HOST }} | ||
SSH_USERNAME: ${{ secrets.USERNAME }} | ||
SSH_PASSWORD: ${{ secrets.PASSWORD }} | ||
|
||
- name: migrate | ||
run: yarn migrate | ||
- name: Build Docker images using docker-compose | ||
run: | | ||
docker compose --env-file .env -f docker-compose.production.yml build | ||
- name: Setup service file | ||
run: sudo cp server-script/aihomeworkprod.service /etc/systemd/system | ||
- name: Save Docker images to tarball | ||
run: | | ||
docker save $(docker compose -f docker-compose.production.yml config | grep 'image:' | awk '{print $2}') | gzip > docker-images.tar.gz | ||
- name: Upload to server | ||
run: | | ||
sshpass -p ${{ secrets.PASSWORD }} scp -o StrictHostKeyChecking=no docker-images.tar.gz ${{ secrets.USERNAME }}@${{ secrets.HOST }}:/tmp/ | ||
env: | ||
SSH_HOST: ${{ secrets.HOST }} | ||
SSH_USERNAME: ${{ secrets.USERNAME }} | ||
SSH_PASSWORD: ${{ secrets.PASSWORD }} | ||
|
||
- name: Start the app | ||
- name: Deploy and start on remote server | ||
run: | | ||
sudo systemctl daemon-reload | ||
sudo systemctl restart aihomeworkprod | ||
sshpass -p ${{ secrets.PASSWORD }} ssh -o StrictHostKeyChecking=no ${{ secrets.USERNAME }}@${{ secrets.HOST }} " | ||
cd /var/www/aihomework/dev | ||
git stash | ||
git pull origin dev | ||
docker load -i /tmp/docker-images.tar.gz | ||
docker compose -f docker-compose.production.yml down | ||
docker compose -f docker-compose.production.yml up -d | ||
rm /tmp/docker-images.tar.gz | ||
" | ||
env: | ||
SSH_HOST: ${{ secrets.HOST }} | ||
SSH_USERNAME: ${{ secrets.USERNAME }} | ||
SSH_PASSWORD: ${{ secrets.PASSWORD }} |
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,56 @@ | ||
name: Build, Test, and Deploy for Dev Branch | ||
name: Deploy to staging Branch | ||
|
||
on: | ||
push: | ||
branches: | ||
- dev | ||
|
||
jobs: | ||
build: | ||
runs-on: self-hosted | ||
defaults: | ||
run: | ||
working-directory: /var/www/aihomework/staging | ||
|
||
build-and-deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Pull from github | ||
id: pull | ||
run: | | ||
git stash | ||
git pull origin staging | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: install dependencies | ||
run: yarn install | ||
- name: Install sshpass | ||
run: sudo apt-get install sshpass | ||
|
||
- name: Run Test | ||
run: yarn test | ||
- name: Fetch .env file from server | ||
run: | | ||
sshpass -p ${{ secrets.PASSWORD }} scp -o StrictHostKeyChecking=no ${{ secrets.USERNAME }}@${{ secrets.HOST }}:/var/www/aihomework/staging/.env .env | ||
env: | ||
SSH_HOST: ${{ secrets.HOST }} | ||
SSH_USERNAME: ${{ secrets.USERNAME }} | ||
SSH_PASSWORD: ${{ secrets.PASSWORD }} | ||
|
||
- name: buld the dist | ||
run: yarn build | ||
- name: Build Docker images using docker-compose | ||
run: | | ||
docker compose --env-file .env -f docker-compose.staging.yml build | ||
- name: migrate | ||
run: yarn reset-db | ||
- name: Save Docker images to tarball | ||
run: | | ||
docker save $(docker compose -f docker-compose.staging.yml config | grep 'image:' | awk '{print $2}') | gzip > docker-images.tar.gz | ||
- name: setup service file | ||
run: sudo cp server-script/aihomeworkstaging.service /etc/systemd/system | ||
- name: Upload to server | ||
run: | | ||
sshpass -p ${{ secrets.PASSWORD }} scp -o StrictHostKeyChecking=no docker-images.tar.gz ${{ secrets.USERNAME }}@${{ secrets.HOST }}:/tmp/ | ||
env: | ||
SSH_HOST: ${{ secrets.HOST }} | ||
SSH_USERNAME: ${{ secrets.USERNAME }} | ||
SSH_PASSWORD: ${{ secrets.PASSWORD }} | ||
|
||
- name: start the app | ||
- name: Deploy and start on remote server | ||
run: | | ||
sudo systemctl daemon-reload | ||
sudo systemctl restart aihomeworkstaging | ||
sshpass -p ${{ secrets.PASSWORD }} ssh -o StrictHostKeyChecking=no ${{ secrets.USERNAME }}@${{ secrets.HOST }} " | ||
cd /var/www/aihomework/dev | ||
git stash | ||
git pull origin dev | ||
docker load -i /tmp/docker-images.tar.gz | ||
docker compose -f docker-compose.staging.yml down | ||
docker compose -f docker-compose.staging.yml up -d | ||
rm /tmp/docker-images.tar.gz | ||
" | ||
env: | ||
SSH_HOST: ${{ secrets.HOST }} | ||
SSH_USERNAME: ${{ secrets.USERNAME }} | ||
SSH_PASSWORD: ${{ secrets.PASSWORD }} |