From 36c295ade74ecc61a4fdaddedf040a27e50e86f2 Mon Sep 17 00:00:00 2001 From: Henrik Wingerei Date: Fri, 16 Aug 2024 07:20:08 +0200 Subject: [PATCH] =?UTF-8?q?Justering=20av=20byggel=C3=B8yper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/actions/build-push-docker/action.yaml | 49 +++++++++++++ .github/workflows/build-deploy.yaml | 69 +++++-------------- .github/workflows/build-test.yaml | 25 ------- Dockerfile | 12 ++-- 4 files changed, 73 insertions(+), 82 deletions(-) create mode 100644 .github/actions/build-push-docker/action.yaml delete mode 100644 .github/workflows/build-test.yaml diff --git a/.github/actions/build-push-docker/action.yaml b/.github/actions/build-push-docker/action.yaml new file mode 100644 index 00000000..e908ca94 --- /dev/null +++ b/.github/actions/build-push-docker/action.yaml @@ -0,0 +1,49 @@ +name: Build docker +description: Builds and push docker image + +outputs: + image_url: + description: Full url to docker image + value: ${{ steps.set_outputs.outputs.image_name }}@${{ steps.set_outputs.outputs.new_digest }} + +runs: + using: composite + + steps: + - name: Login to Github Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.registry }} + username: ${{ github.actor }} + password: ${{ github.token }} + + - name: Bump version and push tag + id: tag_version + uses: mathieudutour/github-tag-action@v6.2 + with: + github_token: ${{ github.token }} + + - name: Build docker and push + id: build + uses: docker/build-push-action@v6 + with: + context: . + push: true + tags: ${{ env.registry }}/${{ github.repository }}:${{ steps.tag_version.outputs.new_tag }} , ${{ env.registry }}/${{ github.repository }}:latest + + - name: Set outputs + id: set_outputs + shell: bash + run: | + echo 'image_name=${{ env.registry }}/${{ github.repository }}' >> $GITHUB_OUTPUT + echo 'new_digest=${{ steps.build.outputs.digest }}' >> $GITHUB_OUTPUT + echo 'new_tag=${{ steps.tag_version.outputs.new_tag }}' >> $GITHUB_OUTPUT + + - name: Add summary of build + id: summary + shell: bash + run: | + echo '### Image release info' >> $GITHUB_STEP_SUMMARY + echo '- Image name: ${{ env.registry }}/${{ github.repository }}' >> $GITHUB_STEP_SUMMARY + echo '- Digest: ${{ steps.build.outputs.digest }}' >> $GITHUB_STEP_SUMMARY + echo '- Tag: ${{ steps.tag_version.outputs.new_tag }}' >> $GITHUB_STEP_SUMMARY diff --git a/.github/workflows/build-deploy.yaml b/.github/workflows/build-deploy.yaml index 6b8bcc75..dafe4e06 100644 --- a/.github/workflows/build-deploy.yaml +++ b/.github/workflows/build-deploy.yaml @@ -1,78 +1,44 @@ -name: Build and Push Image to Registry +name: Build, test and deploy on: - workflow_dispatch: push: branches: - main - -permissions: - contents: write - packages: write + pull_request: + branches: + - main + workflow_dispatch: env: registry: ghcr.io image_name: ${{ github.repository }} +permissions: + contents: write + packages: write + jobs: build: - name: Docker build and push + name: Build, test and push runs-on: ubuntu-latest - - outputs: - image_name: ${{ steps.set_outputs.outputs.image_name }} - new_tag: ${{ steps.set_outputs.outputs.new_tag }} - new_digest: ${{ steps.set_outputs.outputs.new_digest }} - steps: - name: Checkout project sources uses: actions/checkout@v4 - - name: Setup Java uses: actions/setup-java@v4 with: distribution: 'temurin' java-version: '21' - - - name: Login to Github Container Registry - uses: docker/login-action@v3 - with: - registry: ${{ env.registry }} - username: ${{ github.actor }} - password: ${{ github.token }} - - - name: Bump version and push tag - id: tag_version - uses: mathieudutour/github-tag-action@v6.2 - with: - github_token: ${{ github.token }} - - - name: Build docker and push - id: build - uses: docker/build-push-action@v6 - with: - context: . - push: true - tags: ${{ env.registry }}/${{ github.repository }}:${{ steps.tag_version.outputs.new_tag }} , ${{ env.registry }}/${{ github.repository }}:latest - - - name: Set outputs - id: set_outputs - run: | - echo 'image_name=${{ env.registry }}/${{ github.repository }}' >> $GITHUB_OUTPUT - echo 'new_digest=${{ steps.build.outputs.digest }}' >> $GITHUB_OUTPUT - echo 'new_tag=${{ steps.tag_version.outputs.new_tag }}' >> $GITHUB_OUTPUT - - - name: Add summary of build - id: summary - run: | - echo '### Image release info' >> $GITHUB_STEP_SUMMARY - echo '- Image name: ${{ env.registry }}/${{ github.repository }}' >> $GITHUB_STEP_SUMMARY - echo '- Digest: ${{ steps.build.outputs.digest }}' >> $GITHUB_STEP_SUMMARY - echo '- Tag: ${{ steps.tag_version.outputs.new_tag }}' >> $GITHUB_STEP_SUMMARY + - name: Run build and integration tests + run: ./gradlew build integrationTest + - name: Build and push docker + if: github.event_name == 'push' && github.ref_name == 'main' + uses: ./.github/actions/build-push-docker deploy: needs: [ build ] name: Deploy to dev uses: kartverket/bygning-github-workflows/.github/workflows/update-app-version.yaml@main + if: github.event_name == 'push' && github.ref_name == 'main' permissions: id-token: write with: @@ -88,6 +54,7 @@ jobs: needs: [ build ] name: Run Pharos runs-on: ubuntu-latest + if: github.event_name == 'push' && github.ref_name == 'main' permissions: actions: read packages: read @@ -97,4 +64,4 @@ jobs: - name: "Run Pharos" uses: kartverket/pharos@v0.2.1 with: - image_url: ${{ needs.build.outputs.image_name }}@${{ needs.build.outputs.new_digest }} + image_url: ${{ needs.build.outputs.image_url }} diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml deleted file mode 100644 index dda3bc61..00000000 --- a/.github/workflows/build-test.yaml +++ /dev/null @@ -1,25 +0,0 @@ -name: Build and Test -on: - pull_request: - branches: - - main - -permissions: - contents: read - -jobs: - build: - name: Build and test - runs-on: ubuntu-latest - steps: - - name: Checkout project sources - uses: actions/checkout@v4 - - - name: Setup Java - uses: actions/setup-java@v4 - with: - distribution: 'temurin' - java-version: '21' - - - name: Run integration tests and build - run: ./gradlew integrationTest build diff --git a/Dockerfile b/Dockerfile index c7bf63dc..eeeae2ee 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,10 @@ -FROM gradle:8-jdk21-alpine AS build -COPY --chown=gradle:gradle . /home/gradle/src -WORKDIR /home/gradle/src -RUN gradle integrationTest shadowjar --no-daemon +#FROM gradle:8-jdk21-alpine AS build +#COPY --chown=gradle:gradle . /home/gradle/src +#WORKDIR /home/gradle/src +#RUN gradle integrationTest --no-daemon FROM eclipse-temurin:21-jdk-alpine EXPOSE 8080:8080 RUN mkdir /app -COPY --from=build /home/gradle/src/build/libs/*.jar /app/matrikkel-bygning-egenregistrering.jar -ENTRYPOINT ["java", "-Dlogback.configurationFile=logback-cloud.xml", "-jar","/app/matrikkel-bygning-egenregistrering.jar"] +COPY /build/libs/matrikkel-bygning-egenregistrering-all.jar /app/app.jar +ENTRYPOINT ["java", "-Dlogback.configurationFile=logback-cloud.xml", "-jar","/app/app.jar"]