From 66e1b2c4e6719dcf42ceeff2734c711d7332febe Mon Sep 17 00:00:00 2001 From: Sergey Nikitin Date: Sat, 20 Jan 2024 19:04:25 +0100 Subject: [PATCH] fix(ci): Build docker on PR level --- .github/workflows/ci.yml | 7 +++++ .github/workflows/deploy.yml | 36 +++++-------------------- .github/workflows/docker.yml | 51 ++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 30 deletions(-) create mode 100644 .github/workflows/docker.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index da4df1fa..438b1e2e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,3 +8,10 @@ jobs: scan: uses: ./.github/workflows/scan.yml secrets: inherit + + deploy: + # needs: [scan] + uses: ./.github/workflows/docker.yml + secrets: inherit + with: + version: 0.0.0-${{ github.sha }} diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 9a96a0c0..5ff973d6 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -9,36 +9,12 @@ on: required: true jobs: - docker: - runs-on: ubuntu-latest - name: Push docker image - timeout-minutes: 5 - steps: - - name: App version - run: echo "Picked the app version ${GITHUB_SHA}" - - - name: Checkout - uses: actions/checkout@v3 - - - name: Install NodeJS and NPM modules - uses: ./.github/actions/npm - - - name: Login to GitHub Container Registry - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Publish to Registry - uses: docker/build-push-action@v3 - with: - context: . - push: true - tags: | - ghcr.io/${{ secrets.DOCKER_USERNAME }}/voice-to-text-bot/voice-to-speech-app:latest - ghcr.io/${{ secrets.DOCKER_USERNAME }}/voice-to-text-bot/voice-to-speech-app:${{ github.sha }} - build-args: APP_VERSION=${{ inputs.version }} + deploy: + uses: ./.github/workflows/docker.yml + secrets: inherit + with: + docker-tag: latest + version: ${{ inputs.version }} heroku: runs-on: ubuntu-latest diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 00000000..35d543ec --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,51 @@ +name: Build docker image + +on: + workflow_call: + inputs: + docker-tag: + type: string + description: "Extra docker tag" + version: + type: string + description: "Version tag" + required: true +jobs: + docker: + runs-on: ubuntu-latest + name: Push docker image + timeout-minutes: 5 + steps: + - name: App version + run: echo "Picked the app version ${GITHUB_SHA}" + + - name: Checkout + uses: actions/checkout@v3 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Publish to Registry + if: inputs.docker-tag == '' + uses: docker/build-push-action@v3 + with: + context: . + push: true + tags: | + ghcr.io/${{ secrets.DOCKER_USERNAME }}/voice-to-text-bot/voice-to-speech-app:${{ github.sha }} + build-args: APP_VERSION=${{ inputs.version }} + + - name: Publish to Registry and extra tag + if: inputs.docker-tag != '' + uses: docker/build-push-action@v3 + with: + context: . + push: true + tags: | + ghcr.io/${{ secrets.DOCKER_USERNAME }}/voice-to-text-bot/voice-to-speech-app:${{ inputs.docker-tag }} + ghcr.io/${{ secrets.DOCKER_USERNAME }}/voice-to-text-bot/voice-to-speech-app:${{ github.sha }} + build-args: APP_VERSION=${{ inputs.version }}