diff --git a/.github/workflows/branch-deploy.yml b/.github/workflows/branch-deploy.yml index 107a93116..ad32fe4e0 100644 --- a/.github/workflows/branch-deploy.yml +++ b/.github/workflows/branch-deploy.yml @@ -10,69 +10,23 @@ permissions: contents: read jobs: - build: + initiate_env: if: ${{ github.event.label.name == 'status/feature_testing' || github.event.label.name == 'status/feature_testing_public' }} runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - with: - ref: ${{ github.event.pull_request.head.sha }} - token: ${{ github.token }} - - name: get branch name - id: extract_branch - run: | - tag='pr${{ github.event.pull_request.number }}' - echo "tag=${tag}" >> $GITHUB_OUTPUT - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Set up JDK - uses: actions/setup-java@v3 - with: - java-version: '17' - distribution: 'zulu' - cache: 'maven' - - name: Build + - name: Call Build Workflow id: build - run: | - ./mvnw -B -ntp versions:set -DnewVersion=$GITHUB_SHA - ./mvnw -B -V -ntp clean package -Pprod -DskipTests - export VERSION=$(./mvnw -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec) - echo "version=${VERSION}" >> $GITHUB_OUTPUT - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - name: Set up Docker Buildx - id: buildx - uses: docker/setup-buildx-action@v3 - - name: Cache Docker layers - uses: actions/cache@v3 - with: - path: /tmp/.buildx-cache - key: ${{ runner.os }}-buildx-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-buildx- - - name: Configure AWS credentials for Kafka-UI account - uses: aws-actions/configure-aws-credentials@v4 + uses: ./.github/workflows/build.yml with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: eu-central-1 - - name: Login to Amazon ECR - id: login-ecr - uses: aws-actions/amazon-ecr-login@v2 - - name: Build and push - id: docker_build_and_push - uses: docker/build-push-action@v5 + head_sha: ${{ github.event.pull_request.head.sha }} + pull_request_number: ${{ github.event.pull_request.number }} + + - name: Call Push Workflow + uses: ./.github/workflows/push.yml with: - builder: ${{ steps.buildx.outputs.name }} - context: api - push: true - tags: 297478128798.dkr.ecr.eu-central-1.amazonaws.com/kafka-ui:${{ steps.extract_branch.outputs.tag }} - build-args: | - JAR_FILE=api-${{ steps.build.outputs.version }}.jar - cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache - outputs: - tag: ${{ steps.extract_branch.outputs.tag }} + version: ${{ steps.build.outputs.version }} + tag: ${{ steps.build.outputs.tag }} + make-branch-env: needs: build runs-on: ubuntu-latest diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 000000000..6d8cf638d --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,45 @@ +name: Build Application + +on: + workflow_call: + inputs: + head_sha: + required: true + type: string + pull_request_number: + required: true + type: number + outputs: + tag: + description: "The tag for the Docker image" + value: ${{ steps.extract_branch.outputs.tag }} + version: + description: "The application version" + value: ${{ steps.build.outputs.version }} + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ inputs.head_sha }} + token: ${{ secrets.GITHUB_TOKEN }} + - name: get branch name + id: extract_branch + run: | + tag="pr${{ inputs.pull_request_number }}" + echo "tag=${tag}" >> $GITHUB_OUTPUT + - name: Set up JDK + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'zulu' + cache: 'maven' + - name: Build + id: build + run: | + ./mvnw -B -ntp versions:set -DnewVersion=$GITHUB_SHA + ./mvnw -B -V -ntp clean package -Pprod -DskipTests + export VERSION=$(./mvnw -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec) + echo "version=${VERSION}" >> $GITHUB_OUTPUT diff --git a/.github/workflows/push.yaml b/.github/workflows/push.yaml new file mode 100644 index 000000000..25c76399b --- /dev/null +++ b/.github/workflows/push.yaml @@ -0,0 +1,29 @@ +name: Push Docker Image + +on: + workflow_call: + inputs: + version: + required: true + type: string + tag: + required: true + type: string + +jobs: + push: + runs-on: ubuntu-latest + steps: + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to Amazon ECR + uses: aws-actions/amazon-ecr-login@v2 + - name: Build and push + uses: docker/build-push-action@v5 + with: + push: true + tags: 297478128798.dkr.ecr.eu-central-1.amazonaws.com/kafka-ui:${{ inputs.tag }} + build-args: | + JAR_FILE=api-${{ inputs.version }}.jar + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache