Files
linux-odyssey/.github/workflows/ci_cd.yml
T

90 lines
2.1 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
build-and-push:
needs: ci
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
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
push: true
tags: docker.io/${{ secrets.DOCKERHUB_USERNAME }}/linux-odyssey:app
- name: Build base image
uses: docker/build-push-action@v2
with:
context: .
file: ./quests/Dockerfile
push: false
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