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 secrets: SECRET_GITHUB_TOKEN: required: true SECRET_GITHUB_USERNAME: required: true SECRET_ECR_REGISTRY: required: true SECRET_ECR_USERNAME: required: true SECRET_ECR_PASSWORD: required: true SECRET_IMAGE_TAG: required: true 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.SECRET_GITHUB_TOKEN }} GITHUB_USERNAME: ${{ secrets.SECRET_GITHUB_USERNAME }} - name: Build application with Gradle run: ./gradlew bootJar env: GITHUB_TOKEN: ${{ secrets.SECRET_GITHUB_TOKEN }} GITHUB_USERNAME: ${{ secrets.SECRET_GITHUB_USERNAME }} - 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.SECRET_ECR_REGISTRY }} username: ${{ secrets.SECRET_ECR_USERNAME }} password: ${{ secrets.SECRET_ECR_PASSWORD }} - name: Build, tag, and push image to ECR if: ${{ inputs.IS_ECR_PUSH_ENABLED }} env: ECR_REGISTRY: ${{ secrets.SECRET_ECR_REGISTRY }} ECR_REPOSITORY: ${{ inputs.ECR_REPOSITORY }} IMAGE_TAG: ${{ secrets.SECRET_IMAGE_TAG }} 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