Files
linux-odyssey/.github/workflows/ci_cd.yml
T
Lin, Hung-Shin 10e9d89349 Update deployment (#58)
* Update ci_cd.yml

Remove deployment scripts, moved to authorized_keys instead.

* Update docker-compose.prod.yml to always restart
2023-11-05 23:27:50 +08:00

122 lines
3.2 KiB
YAML

name: CI/CD
on:
push:
jobs:
ci:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 20
- name: Install dependencies
run: yarn install
- name: Lint
run: yarn lint
- name: Test
run: yarn test
e2e:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Build Test Environment, Stage 1
run: docker-compose -f docker-compose.testing.yml build base backend app-test
- name: Build Test Environment, Stage 2
run: docker-compose -f docker-compose.testing.yml build helloworld
- name: Run Cypress Tests
env:
GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }}
GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }}
GITHUB_CLIENT_ID: ${{ secrets.GITHUB_CLIENT_ID }}
GITHUB_CLIENT_SECRET: ${{ secrets.GITHUB_CLIENT_SECRET }}
run: docker-compose -f docker-compose.testing.yml run cypress
- name: Tear Down Test Environment
run: docker-compose -f docker-compose.testing.yml down
build-and-push:
needs:
- ci
- e2e
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build backend
uses: docker/build-push-action@v2
with:
context: .
file: ./server/Dockerfile
target: prod
push: true
tags: docker.io/${{ secrets.DOCKERHUB_USERNAME }}/linux-odyssey:backend
- name: Build app
uses: docker/build-push-action@v2
with:
context: .
file: ./app/Dockerfile
target: prod
push: true
tags: docker.io/${{ secrets.DOCKERHUB_USERNAME }}/linux-odyssey:app
- name: Build analytics
uses: docker/build-push-action@v2
with:
context: .
file: ./packages/analytics/Dockerfile
target: prod
push: true
tags: docker.io/${{ secrets.DOCKERHUB_USERNAME }}/linux-odyssey:analytics
- name: Build base image
uses: docker/build-push-action@v2
with:
context: .
file: ./quests/Dockerfile
push: true
tags: docker.io/${{ secrets.DOCKERHUB_USERNAME }}/linux-odyssey:base
- name: Build quest helloworld
uses: docker/build-push-action@v2
with:
context: .
file: ./quests/helloworld/Dockerfile
push: true
tags: docker.io/${{ secrets.DOCKERHUB_USERNAME }}/linux-odyssey:helloworld
deploy:
needs: build-and-push
runs-on: ubuntu-latest
steps:
- name: SSH into server and update service
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
port: ${{ secrets.SERVER_PORT }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}