From b9f39204bde791dfb4875eba39d7c56c4a6bfd33 Mon Sep 17 00:00:00 2001 From: meysamhadeli Date: Tue, 7 Feb 2023 18:02:57 +0330 Subject: [PATCH] chore: Update ci.yml --- .../actions/docker-build-publish/action.yml | 46 +++++++++++++++++++ ...after.yml => release-drafter-template.yml} | 0 .github/workflows/ci.yml | 29 +++--------- .github/workflows/release-drafter-labeler.yml | 2 +- 4 files changed, 53 insertions(+), 24 deletions(-) create mode 100644 .github/actions/docker-build-publish/action.yml rename .github/{release-drafter.yml => release-drafter-template.yml} (100%) diff --git a/.github/actions/docker-build-publish/action.yml b/.github/actions/docker-build-publish/action.yml new file mode 100644 index 0000000..6cec9a4 --- /dev/null +++ b/.github/actions/docker-build-publish/action.yml @@ -0,0 +1,46 @@ +name: "Publish and Build Docker" +description: "Publish and Build Docker " + +# Input parameters allow you to specify data that the action expects to use during runtime. GitHub stores input parameters as environment variables.(so they are just string) +# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#inputs +inputs: + tag-name: + description: "Tag Name" + required: true + registry-username: + description: "Registry username" + required: true + registry-password: + description: "Registry password" + required: true + +# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runs-for-composite-actions +runs: + using: "composite" + steps: + + ##ref: https://docs.docker.com/language/golang/configure-ci-cd/ + ##ref: https://event-driven.io/en/how_to_buid_and_push_docker_image_with_github_actions + - name: Login to DockerHub + uses: docker/login-action@v2 + if: ${{ github.ref == 'refs/heads/main' && success() }} + with: + username: ${{ inputs.registry-username }} + password: ${{ inputs.registry-password }} + + - name: Build Docker Image + if: ${{ github.ref == 'refs/heads/main' && success() }} + run: | + docker build -t ${{ inputs.registry-username }}/booking-microservices-flight:${{ inputs.tag-name }} -f "${{ github.workspace }}/src/Services/Flight/Dockerfile" . + docker build -t ${{ inputs.registry-username }}/booking-microservices-identity:${{ inputs.tag-name }} -f "${{ github.workspace }}/src/Services/Identity/Dockerfile" . + docker build -t ${{ inputs.registry-username }}/booking-microservices-passenger:${{ inputs.tag-name }} -f "${{ github.workspace }}/src/Services/Passenger/Dockerfile" . + docker build -t ${{ inputs.registry-username }}/booking-microservices-booking:${{ inputs.tag-name }} -f "${{ github.workspace }}/src/Services/Booking/Dockerfile" . + + - name: Publish Docker Image + if: ${{ github.ref == 'refs/heads/main' && success() }} + run: | + docker push ${{ inputs.registry-username }}/booking-microservices-flight:${{ inputs.tag-name }} + docker push ${{ inputs.registry-username }}/booking-microservices-identity:${{ inputs.tag-name }} + docker push ${{ inputs.registry-username }}/booking-microservices-passenger:${{ inputs.tag-name }} + docker push ${{ inputs.registry-username }}/booking-microservices-booking:${{ inputs.tag-name }} + diff --git a/.github/release-drafter.yml b/.github/release-drafter-template.yml similarity index 100% rename from .github/release-drafter.yml rename to .github/release-drafter-template.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 66ed5ab..e23a4a3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,28 +45,11 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - ##ref: https://docs.docker.com/language/golang/configure-ci-cd/ - ##ref: https://event-driven.io/en/how_to_buid_and_push_docker_image_with_github_actions - - name: Login to DockerHub - uses: docker/login-action@v2 + + - name: Call Composite Action docker-build-publish + uses: ./.github/actions/docker-build-publish if: ${{ github.ref == 'refs/heads/main' && success() }} with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_PASSWORD }} - - - name: Build Docker Image - if: ${{ github.ref == 'refs/heads/main' && success() }} - run: | - docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/booking-microservices-flight:${{ steps.last_release.outputs.tag_name }} -f "${{ github.workspace }}/src/Services/Flight/Dockerfile" . - docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/booking-microservices-identity:${{ steps.last_release.outputs.tag_name }} -f "${{ github.workspace }}/src/Services/Identity/Dockerfile" . - docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/booking-microservices-passenger:${{ steps.last_release.outputs.tag_name }} -f "${{ github.workspace }}/src/Services/Passenger/Dockerfile" . - docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/booking-microservices-booking:${{ steps.last_release.outputs.tag_name }} -f "${{ github.workspace }}/src/Services/Booking/Dockerfile" . - - - name: Publish Docker Image - if: ${{ github.ref == 'refs/heads/main' && success() }} - run: | - docker push ${{ secrets.DOCKERHUB_USERNAME }}/booking-microservices-flight:${{ steps.last_release.outputs.tag_name }} - docker push ${{ secrets.DOCKERHUB_USERNAME }}/booking-microservices-identity:${{ steps.last_release.outputs.tag_name }} - docker push ${{ secrets.DOCKERHUB_USERNAME }}/booking-microservices-passenger:${{ steps.last_release.outputs.tag_name }} - docker push ${{ secrets.DOCKERHUB_USERNAME }}/booking-microservices-booking:${{ steps.last_release.outputs.tag_name }} - + tag-name: ${{ steps.last_release.outputs.tag_name }} + registry-username: ${{ secrets.DOCKERHUB_USERNAME }} + registry-password: ${{ secrets.DOCKERHUB_PASSWORD }} diff --git a/.github/workflows/release-drafter-labeler.yml b/.github/workflows/release-drafter-labeler.yml index 960bec7..aba7db2 100644 --- a/.github/workflows/release-drafter-labeler.yml +++ b/.github/workflows/release-drafter-labeler.yml @@ -15,7 +15,7 @@ jobs: steps: - uses: release-drafter/release-drafter@v5 with: - config-name: release-drafter.yml + config-name: release-drafter-template.yml disable-releaser: true # only run auto-labeler for PRs env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}