From 4472c8cfd6f3c52f1266962048c35a5feb56d700 Mon Sep 17 00:00:00 2001 From: Alex Dyakonov Date: Sun, 3 Nov 2024 12:06:32 +0300 Subject: [PATCH 1/2] Updated ci/cd pipelines --- .github/workflows/cd-dev.yaml | 9 +++-- .github/workflows/cd-production.yaml | 35 +++++++++++++------ .github/workflows/ci-build.yaml | 19 ++++++++++ .../{ci-tests-build.yaml => ci-tests.yaml} | 13 ++----- 4 files changed, 49 insertions(+), 27 deletions(-) create mode 100644 .github/workflows/ci-build.yaml rename .github/workflows/{ci-tests-build.yaml => ci-tests.yaml} (70%) diff --git a/.github/workflows/cd-dev.yaml b/.github/workflows/cd-dev.yaml index eb6ab6b..328c1c4 100644 --- a/.github/workflows/cd-dev.yaml +++ b/.github/workflows/cd-dev.yaml @@ -1,8 +1,8 @@ -name: CD Dev +name: CD-dev on: workflow_run: - workflows: ["CI"] + workflows: ["CI-tests"] types: - completed @@ -36,7 +36,6 @@ jobs: run: | echo "VITE_API_URL=${{ secrets.VITE_API_URL_DEV }}" > .env - - name: Build and push Docker image id: push uses: docker/build-push-action@v5 @@ -45,8 +44,8 @@ jobs: file: ./Dockerfile push: true tags: | - shampiniony/dishdash-miniapp:dev - shampiniony/dishdash-miniapp:dev-${{ env.COMMIT_SHORT_SHA }} + ${{ secrets.DOCKER_USERNAME }}/dishdash-miniapp:dev + ${{ secrets.DOCKER_USERNAME }}/dishdash-miniapp:dev-${{ env.COMMIT_SHORT_SHA }} - name: Trigger Watchtower to update dev container shell: bash diff --git a/.github/workflows/cd-production.yaml b/.github/workflows/cd-production.yaml index 07ee36d..f8916df 100644 --- a/.github/workflows/cd-production.yaml +++ b/.github/workflows/cd-production.yaml @@ -1,15 +1,34 @@ -name: Publish Docker image +name: CD-prod on: + workflow_dispatch: + inputs: + tag_name: + description: Write tag for deploy + required: true + workflow_run: - workflows: ["CI"] + workflows: ["CI-test", "CI-build"] types: - completed jobs: + check_ci_status: + name: Check CI Status + runs-on: ubuntu-latest + steps: + - name: Check CI status + id: ci_status + run: | + if [[ "${{ github.event.workflow_run.conclusion }}" != "success" ]]; then + echo "CI workflow did not succeed. Stopping deployment." + exit 1 + fi + push_to_registry: name: Push Docker image to Docker Hub - if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'main' }} + needs: check_ci_status + if: (github.event_name == 'workflow_dispatch' && github.event.inputs.tag_name != '') runs-on: ubuntu-latest permissions: packages: write @@ -20,12 +39,6 @@ jobs: - name: Check out the repo uses: actions/checkout@v4 - - name: Set short git commit SHA - id: vars - run: | - calculatedSha=$(git rev-parse --short ${{ github.sha }}) - echo "COMMIT_SHORT_SHA=$calculatedSha" >> $GITHUB_ENV - - name: Log in to Docker Hub uses: docker/login-action@v2 with: @@ -44,8 +57,8 @@ jobs: file: ./Dockerfile push: true tags: | - shampiniony/dishdash-miniapp:latest - shampiniony/dishdash-miniapp:${{ env.COMMIT_SHORT_SHA }} + ${{ secrets.DOCKER_USERNAME }}/dishdash-miniapp:latest + ${{ secrets.DOCKER_USERNAME }}/dishdash-miniapp:${{ github.event.inputs.tag_name }} - name: Trigger watchtower to update container(s) shell: bash diff --git a/.github/workflows/ci-build.yaml b/.github/workflows/ci-build.yaml new file mode 100644 index 0000000..16ed647 --- /dev/null +++ b/.github/workflows/ci-build.yaml @@ -0,0 +1,19 @@ +name: CI-build + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Build docker image + run: docker compose build diff --git a/.github/workflows/ci-tests-build.yaml b/.github/workflows/ci-tests.yaml similarity index 70% rename from .github/workflows/ci-tests-build.yaml rename to .github/workflows/ci-tests.yaml index ce576c2..d49a84e 100644 --- a/.github/workflows/ci-tests-build.yaml +++ b/.github/workflows/ci-tests.yaml @@ -1,4 +1,4 @@ -name: CI +name: CI-tests on: push: @@ -7,11 +7,8 @@ on: branches: [ "main", "dev" ] jobs: - build: - runs-on: ubuntu-22.04 - steps: - uses: actions/checkout@v4 @@ -27,10 +24,4 @@ jobs: run: yarn lint - name: Run Unit Tests - run: yarn test - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Build docker image - run: docker compose build + run: yarn test \ No newline at end of file From d6312c201f1eb908e31defc5aa9de0f77f956530 Mon Sep 17 00:00:00 2001 From: Alex Dyakonov Date: Sun, 3 Nov 2024 14:12:30 +0300 Subject: [PATCH 2/2] Updated pipelines --- .github/workflows/cd-dev.yaml | 4 ++-- .github/workflows/cd-production.yaml | 20 +++----------------- .github/workflows/ci-build.yaml | 11 +++++------ .github/workflows/ci-tests.yaml | 8 ++------ 4 files changed, 12 insertions(+), 31 deletions(-) diff --git a/.github/workflows/cd-dev.yaml b/.github/workflows/cd-dev.yaml index 328c1c4..4403019 100644 --- a/.github/workflows/cd-dev.yaml +++ b/.github/workflows/cd-dev.yaml @@ -1,8 +1,8 @@ -name: CD-dev +name: cd-dev on: workflow_run: - workflows: ["CI-tests"] + workflows: ["ci-tests"] types: - completed diff --git a/.github/workflows/cd-production.yaml b/.github/workflows/cd-production.yaml index f8916df..ae42fb0 100644 --- a/.github/workflows/cd-production.yaml +++ b/.github/workflows/cd-production.yaml @@ -7,27 +7,13 @@ on: description: Write tag for deploy required: true - workflow_run: - workflows: ["CI-test", "CI-build"] - types: - - completed - jobs: - check_ci_status: - name: Check CI Status - runs-on: ubuntu-latest - steps: - - name: Check CI status - id: ci_status - run: | - if [[ "${{ github.event.workflow_run.conclusion }}" != "success" ]]; then - echo "CI workflow did not succeed. Stopping deployment." - exit 1 - fi + ci-tests: + uses: .github/workflows/ci-tests.yaml push_to_registry: name: Push Docker image to Docker Hub - needs: check_ci_status + needs: ci-tests if: (github.event_name == 'workflow_dispatch' && github.event.inputs.tag_name != '') runs-on: ubuntu-latest permissions: diff --git a/.github/workflows/ci-build.yaml b/.github/workflows/ci-build.yaml index 16ed647..a75b883 100644 --- a/.github/workflows/ci-build.yaml +++ b/.github/workflows/ci-build.yaml @@ -1,9 +1,8 @@ -name: CI-build +name: ci-build -on: - push: - branches: [ "main" ] - pull_request: +on: + workflow_call: {} + pull_request: branches: [ "main" ] jobs: @@ -16,4 +15,4 @@ jobs: uses: docker/setup-buildx-action@v2 - name: Build docker image - run: docker compose build + run: docker compose build --progress plain diff --git a/.github/workflows/ci-tests.yaml b/.github/workflows/ci-tests.yaml index d49a84e..ae49220 100644 --- a/.github/workflows/ci-tests.yaml +++ b/.github/workflows/ci-tests.yaml @@ -1,10 +1,6 @@ -name: CI-tests +name: ci-tests -on: - push: - branches: [ "main", "dev" ] - pull_request: - branches: [ "main", "dev" ] +on: [workflow_call] jobs: build: