mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
126 lines
3.3 KiB
YAML
126 lines
3.3 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.GH_CLIENT_ID }}
|
|
GITHUB_CLIENT_SECRET: ${{ secrets.GH_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 }}
|
|
script: |
|
|
cd ${{ secrets.SERVER_PATH }}
|
|
docker compose pull
|
|
docker compose up -d
|