Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cd: updated working-dir #600

Merged
merged 2 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 64 additions & 47 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
@@ -1,61 +1,78 @@
name: Deploy to Dev

on:
workflow_run:
workflows: [CI]
types:
- completed
branches: [dev]
push:
branches:
- dev

jobs:
deploy:
runs-on: ubuntu-latest
runs-on: bingo
defaults:
run:
working-directory: /var/www/aihomework/boilerplates/dev

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

# - name: Install sshpass
# run: sudo apt-get install sshpass
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

- 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: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '20'

- name: Build Docker images
# - name: Remove old actions remote URL
# continue-on-error: true
# run: |
# git remote rm action

# - name: Stash or remove local changes
# run: |
# if git diff --quiet; then
# echo "No local changes to stash."
# else
# echo "Stashing local changes..."
# git stash --include-untracked || echo "Failed to stash changes. Attempting to reset..."
# git reset --hard || exit 1
# fi

- name: Pull from GitHub
id: pull
run: |
docker compose --env-file .env -f docker-compose.yml build
remote_repo="https://${GITHUB_ACTOR}:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git"
git remote add action $remote_repo
git pull action dev

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: List Docker images
run: docker images
- name: Run tests
run: yarn test

- name: Save Docker images to tarball
- name: Build the application
run: yarn build && sudo rm -rf build

# - name: Generate migrations
# run: yarn migration:generate

# - name: Run migrations
# run: yarn migration:run

- name: Setup and restart service
run: |
docker save hng_boilerplate_expressjs-backend:latest | gzip > dev-images.tar.gz
sudo cp server-script/aihomeworkdev.service /etc/systemd/system
sudo systemctl daemon-reload
sudo systemctl restart aihomeworkdev.service

- 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
- name: Verify deployment
run: |
echo "Waiting for service to start..."
sleep 10
if sudo systemctl is-active --quiet aihomeworkdev.service; then
echo "Deployment successful!"
else
echo "Deployment failed!"
exit 1
fi
2 changes: 1 addition & 1 deletion server-script/startappdev.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash

cd /var/www/aihomework/dev/
cd /var/www/aihomework/boilerplates/dev/
mkdir -p logs
/usr/bin/yarn start >> logs/devoutput.log 2>&1
Loading