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

pr-deploy #537

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
48 changes: 27 additions & 21 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,40 @@ on:

jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
working-directory: /var/www/aihomework/dev
runs-on: self-hosted

steps:
- name: Pull from github
id: pull
- name: Checkout code
uses: actions/checkout@v4

- name: Pull from GitHub
run: |
git stash
git pull origin dev

- name: install dependencies
run: yarn install

- name: Run Test
run: yarn test
- name: Build Docker image
run: docker build -t aihomework-dev:latest .

- name: buld the dist
run: yarn build
- name: Save Docker image to tarball
run: docker save aihomework-dev:latest -o aihomework-dev.tar

- name: migrate
run: yarn reset-db

- name: setup service file
run: sudo cp server-script/aihomeworkdev.service /etc/systemd/system
- name: Upload Docker image to server
env:
SERVER_USER: ${{ secrets.SERVER_USER }}
SERVER_HOST: ${{ secrets.SERVER_HOST }}
SERVER_SSH_KEY: ${{ secrets.SERVER_SSH_KEY }}
run: |
scp -i $SERVER_SSH_KEY aihomework-dev.tar $SERVER_USER@$SERVER_HOST:/var/www/aihomework/dev/

- name: start the app
- name: Load Docker image on server and start
env:
SERVER_USER: ${{ secrets.SERVER_USER }}
SERVER_HOST: ${{ secrets.SERVER_HOST }}
SERVER_SSH_KEY: ${{ secrets.SERVER_SSH_KEY }}
run: |
sudo systemctl daemon-reload
sudo systemctl restart aihomeworkdev
ssh -i $SERVER_SSH_KEY $SERVER_USER@$SERVER_HOST << 'EOF'
cd /var/www/aihomework/dev
docker load -i aihomework-dev.tar
docker-compose down
docker-compose up -d
EOF
36 changes: 36 additions & 0 deletions .github/workflows/pr-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: PR Deploy

on:
pull_request:
types: [opened, synchronize, reopened, closed]

jobs:
deploy-pr:
environment:
name: preview
url: ${{ steps.deploy.outputs.preview-url }}
runs-on: ubuntu-latest

steps:
- name: Checkout to branch
uses: actions/checkout@v4

- id: deploy
name: Pull Request Deploy
uses: hngprojects/[email protected]
with:
server_host: ${{ secrets.SERVER_HOST }}
server_username: ${{ secrets.SERVER_USERNAME }}
server_password: ${{ secrets.SERVER_PASSWORD }}
server_port: ${{ secrets.SERVER_PORT }}
comment: true
context: '.'
dockerfile: 'Dockerfile'
exposed_port: '8000'
host_volume_path: '/var/'
container_volume_path: '/var/'
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Print Preview URL
run: |
echo "Preview URL: ${{ steps.deploy.outputs.preview-url }}"
40 changes: 25 additions & 15 deletions .github/workflows/prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,39 @@ on:
jobs:
build:
runs-on: self-hosted
defaults:
run:
working-directory: /var/www/aihomework/prod

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

- name: Pull from GitHub
run: |
git stash
git pull origin main

- name: Install dependencies
run: yarn install

- name: Build the dist
run: yarn build
- name: Build Docker image
run: docker build -t aihomework-prod:latest .

- name: migrate
run: yarn migrate
- name: Save Docker image to tarball
run: docker save aihomework-prod:latest -o aihomework-prod.tar

- name: Setup service file
run: sudo cp server-script/aihomeworkprod.service /etc/systemd/system
- name: Upload Docker image to server
env:
SERVER_USER: ${{ secrets.SERVER_USER }}
SERVER_HOST: ${{ secrets.SERVER_HOST }}
SERVER_SSH_KEY: ${{ secrets.SERVER_SSH_KEY }}
run: |
scp -i $SERVER_SSH_KEY aihomework-prod.tar $SERVER_USER@$SERVER_HOST:/var/www/aihomework/prod/

- name: Start the app
- name: Load Docker image on server and start
env:
SERVER_USER: ${{ secrets.SERVER_USER }}
SERVER_HOST: ${{ secrets.SERVER_HOST }}
SERVER_SSH_KEY: ${{ secrets.SERVER_SSH_KEY }}
run: |
sudo systemctl daemon-reload
sudo systemctl restart aihomeworkprod
ssh -i $SERVER_SSH_KEY $SERVER_USER@$SERVER_HOST << 'EOF'
cd /var/www/aihomework/prod
docker load -i aihomework-prod.tar
docker-compose down
docker-compose up -d
EOF