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: Pull Test Environment Images run: docker-compose -f docker-compose.testing.yml pull db-test - 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 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 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: 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