Updated CI/CD Tests #9
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
name: Deployment | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
paths: | |
- 'src/website/**' | |
- '.devcontainer/**' | |
jobs: | |
deploy-web: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout workspace | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.GH_TOKEN }} | |
- name: Install dependencies and run lint checks | |
run: | | |
cd src/website | |
npm ci | |
npm run lint | |
- name: Build website | |
run: | | |
cd src/website | |
npm run build | |
- name: Debug SSH Key for Pre-production | |
if: github.event_name == 'pull_request' | |
run: | | |
echo "${{ secrets.SSH_KEY_PREPROD }}" | tr -d '\r' > key_preprod | |
chmod 600 key_preprod | |
ssh-keygen -y -f key_preprod | |
- name: Debug SSH Key for Production | |
if: github.event_name == 'push' | |
run: | | |
echo "${{ secrets.SSH_KEY_PROD }}" | tr -d '\r' > key_prod | |
chmod 600 key_prod | |
ssh-keygen -y -f key_prod | |
- name: Update docker image for pre-production | |
if: github.event_name == 'pull_request' | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.SSH_HOST_PREPROD }} | |
username: ${{ secrets.SSH_USERNAME_PREPROD }} | |
key: ${{ secrets.SSH_KEY_PREPROD }} | |
script: | | |
[ ! -d "sailbot_workspace" ] && git clone https://github.com/UBCSailbot/sailbot_workspace.git | |
cd sailbot_workspace | |
git pull | |
touch src/website/.env.local # Adds a local environment file to VM to override env vars in .env.production | |
echo NEXT_PUBLIC_SERVER_HOST=http://${{ secrets.SSH_HOST_PREPROD }} >> src/website/.env.local | |
docker compose -f .devcontainer/docker-compose.yml -f .devcontainer/website/docker-compose.website.prod.yml up --force-recreate -d --build --remove-orphans | |
- name: Update docker image for production | |
if: github.event_name == 'push' | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.SSH_HOST_PROD }} | |
username: ${{ secrets.SSH_USERNAME_PROD }} | |
key: ${{ secrets.SSH_KEY_PROD }} | |
script: | | |
[ ! -d "sailbot_workspace" ] && git clone https://github.com/UBCSailbot/sailbot_workspace.git | |
cd sailbot_workspace | |
git pull | |
touch src/website/.env.local # Adds a local environment file to VM to override env vars in .env.production | |
echo NEXT_PUBLIC_SERVER_HOST=http://${{ secrets.SSH_HOST_PROD }} >> src/website/.env.local | |
docker compose -f .devcontainer/docker-compose.yml -f .devcontainer/website/docker-compose.website.prod.yml up --force-recreate -d --build --remove-orphans |