haroldtreen/epub-press

View on GitHub
.github/workflows/build.yml

Summary

Maintainability
Test Coverage
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Build
on: [push, pull_request]
jobs:
  test_and_lint:
    runs-on: ubuntu-latest
    steps:
      - name: Use Node.js 14
        uses: actions/setup-node@v1
        with:
          node-version: 13
      - uses: actions/checkout@v2
      - run: npm ci
      - run: npm run lint
      - uses: paambaati/codeclimate-action@v2.6.0
        env:
          CC_TEST_REPORTER_ID: 96ffb20ecb0b933c764cff83a89880079aa11a32874c611fc02bfbfc0d021611
        with:
          coverageCommand: npm run test:coverage
          coverageLocations: ${{ github.workspace }}/coverage/lcov.info:lcov
  publish:
    if: ${{ contains(github.ref, 'master') || contains(github.ref, 'stage') }}
    runs-on: ubuntu-latest
    needs: [test_and_lint]
    steps:
      - uses: actions/checkout@v2
      - name: Login to Docker Hub
        uses: docker/login-action@v2
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Publish Docker
        uses: docker/build-push-action@v4
        with:
          context: .
          tags: latest,master
          build-args: converter=kindlegen
          cache-from: haroldtreen/epub-press/server:latest
  deploy_stage:
    if: ${{ contains(github.ref, 'stage') }}
    runs-on: ubuntu-latest
    needs: [publish]
    steps:
      - uses: actions/checkout@v2
      - name: Decrypt Envs
        run: scripts/decrypt-secrets.sh
        env:
          PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
      - name: Copy files
        uses: appleboy/scp-action@v0.1.3
        with:
          username: ${{ secrets.SSH_USERNAME }}
          key: ${{ secrets.SSH_KEY }}
          host: ${{ env.STAGE_HOST }}
          source: "docker-compose.stage.yaml,envs/stage.env,prometheus.yml"
          target: "/usr/local/epub-press"
          passphrase: ${{ secrets.SSH_PASSPHRASE }}
      - name: Restart Docker
        uses: appleboy/ssh-action@master
        with:
          host: ${{ env.STAGE_HOST }}
          username: ${{ secrets.SSH_USERNAME }}
          passphrase: ${{ secrets.SSH_PASSPHRASE }}
          key: ${{ secrets.SSH_KEY }}
          script: |
            cd /usr/local/epub-press/
            cp envs/stage.env .env
            docker-compose -f docker-compose.stage.yaml pull 
            docker-compose -f docker-compose.stage.yaml up -d
            docker system prune -a -f
  deploy_prod:
    if: ${{ contains(github.ref, 'master') }}
    runs-on: ubuntu-latest
    needs: [publish]
    steps:
      - uses: actions/checkout@v2
      - name: Decrypt Envs
        run: scripts/decrypt-secrets.sh
        env:
          PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
      - name: Copy files
        uses: appleboy/scp-action@v0.1.3
        with:
          username: ${{ secrets.SSH_USERNAME }}
          key: ${{ secrets.SSH_KEY }}
          host: ${{ env.STAGE_HOST }}
          source: "docker-compose.prod.yaml,envs/prod.env,prometheus.yml"
          target: "/usr/local/epub-press"
          passphrase: ${{ secrets.SSH_PASSPHRASE }}
      - name: Restart Docker
        uses: appleboy/ssh-action@master
        with:
          host: ${{ env.PROD_HOST }}
          username: ${{ secrets.SSH_USERNAME }}
          passphrase: ${{ secrets.SSH_PASSPHRASE }}
          key: ${{ secrets.SSH_KEY }}
          script: |
            cd /usr/local/epub-press/
            cp envs/prod.env .env
            docker-compose -f docker-compose.prod.yaml pull 
            docker-compose -f docker-compose.prod.yaml up -d
            docker system prune -a -f
env:
  CI: true
  STAGE_HOST: 165.227.186.65
  PROD_HOST: 45.55.36.106