From a483bf01a8a8cb6473ac1ba40c42af91c0e490bb Mon Sep 17 00:00:00 2001 From: vlad Date: Fri, 7 Apr 2023 11:57:11 +0300 Subject: [PATCH] feat: Add v2 for single module workflow --- .../api-single-module-v2-workflow.yml | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 .github/workflows/api-single-module-v2-workflow.yml diff --git a/.github/workflows/api-single-module-v2-workflow.yml b/.github/workflows/api-single-module-v2-workflow.yml new file mode 100644 index 0000000..c0b56e7 --- /dev/null +++ b/.github/workflows/api-single-module-v2-workflow.yml @@ -0,0 +1,85 @@ +name: Reusable workflow. Using to build, test and push single module API + +on: + workflow_call: + inputs: + ECR_REPOSITORY: + description: "Using for deploy docker image to ECR" + required: true + type: string + BOOT_JAR_NAME: + description: "Using for start docker container." + required: true + type: string + IS_TEST_ENABLED: + description: "Using for start test before pushing to ECR if value is true." + required: true + type: boolean + IS_ECR_PUSH_ENABLED: + description: "Using for disable pushing to ECR if value is true." + required: true + type: boolean + IS_COPY_DOCKERFILE: + description: "Using for copy default dockerfile from https://github.com/ArbinaHQ/arbina-github-runner/tree/master/docker/api." + required: true + type: boolean + IS_COPY_DOCKER_DIRECTORY: + description: "Using for copy default docker directory (entrypoint, cron, healthcheck) from https://github.com/ArbinaHQ/arbina-github-runner/tree/master/docker/api." + required: true + type: boolean + +jobs: + api-single-module-workflow: + runs-on: custom + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 17 + uses: actions/setup-java@v1 + with: + java-version: 17 + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Test application with Gradle + if: ${{ inputs.IS_TEST_ENABLED }} + run: ./gradlew test + env: + GITHUB_TOKEN: ${{ secrets.GH_TOKEN_CAN_READ_PACKAGES || secrets.GH_DEPBOT_TOKEN_CAN_READ_PACKAGES }} + GITHUB_USERNAME: ${{ secrets.GH_USER_CAN_READ_PACKAGES || secrets.GH_DEPBOT_USER_CAN_READ_PACKAGES }} + + - name: Build application with Gradle + run: ./gradlew bootJar + env: + GITHUB_TOKEN: ${{ secrets.GH_TOKEN_CAN_READ_PACKAGES || secrets.GH_DEPBOT_TOKEN_CAN_READ_PACKAGES }} + GITHUB_USERNAME: ${{ secrets.GH_USER_CAN_READ_PACKAGES || secrets.GH_DEPBOT_USER_CAN_READ_PACKAGES }} + + - name: Copy docker directory + if: ${{ inputs.IS_COPY_DOCKER_DIRECTORY }} + run: cp -r /docker/api/docker ./ + + - name: Copy dockerfile + if: ${{ inputs.IS_COPY_DOCKERFILE }} + run: cp /docker/api/Dockerfile ./ + + - name: Login to ECR + if: ${{ inputs.IS_ECR_PUSH_ENABLED }} + id: login-ecr + uses: docker/login-action@v2 + with: + registry: ${{ secrets.ARBINA_ECR_REGISTRY }} + username: ${{ secrets.ARBINA_ECR_USERNAME }} + password: ${{ secrets.ARBINA_ECR_PASSWORD }} + + - name: Build, tag, and push image to ECR + if: ${{ inputs.IS_ECR_PUSH_ENABLED }} + env: + ECR_REGISTRY: ${{ secrets.ARBINA_ECR_REGISTRY }} + ECR_REPOSITORY: ${{ inputs.ECR_REPOSITORY }} + IMAGE_TAG: ${{ github.sha }} + BOOT_JAR_NAME: ${{ inputs.BOOT_JAR_NAME }} + run: | + docker build --build-arg=IMAGE_TAG=$IMAGE_TAG --build-arg=BOOT_JAR_NAME=$BOOT_JAR_NAME -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG + docker build --build-arg=IMAGE_TAG=$IMAGE_TAG --build-arg=BOOT_JAR_NAME=$BOOT_JAR_NAME -t $ECR_REGISTRY/$ECR_REPOSITORY:latest . + docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest