Skip to content

Commit

Permalink
Justering av byggeløyper
Browse files Browse the repository at this point in the history
  • Loading branch information
henriwi committed Aug 16, 2024
1 parent f693db8 commit 578ce57
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 82 deletions.
55 changes: 55 additions & 0 deletions .github/actions/build-push-docker/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Build docker
description: Builds and push docker image

outputs:
image_name:
description: Image name
value: ${{ steps.set_outputs.outputs.image_name }}
image_tag:
description: Image tag
value: ${{ steps.set_outputs.outputs.new_tag }}
image_digest:
description: Image digest
value: ${{ 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
70 changes: 21 additions & 49 deletions .github/workflows/build-deploy.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
name: Build and Push Image to Registry
name: Build, test and deploy
on:
workflow_dispatch:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:

permissions:
contents: write
Expand All @@ -15,71 +18,39 @@ env:

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
id: docker
if: github.event_name == 'push' && github.ref_name == 'main'
uses: ./.github/actions/build-push-docker
outputs:
image_name: ${{ steps.docker.outputs.image_name }}
image_tag: ${{ steps.docker.outputs.image_tag }}
image_digest: ${{ steps.docker.outputs.image_digest }}

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:
application_name: bygning-backend
image_name: ${{ needs.build.outputs.image_name }}
image_tag: ${{ needs.build.outputs.new_tag }}
image_digest: ${{ needs.build.outputs.new_digest }}
image_tag: ${{ needs.build.outputs.image_tag }}
image_digest: ${{ needs.build.outputs.image_digest }}
env: dev
namespace: matrikkelbygning-main
cluster: atgcp1
Expand All @@ -88,6 +59,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
Expand All @@ -97,4 +69,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_name }}@${{ needs.build.outputs.image_digest }}
25 changes: 0 additions & 25 deletions .github/workflows/build-test.yaml

This file was deleted.

9 changes: 2 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
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 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"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ nødvendig rundt miljøkonfigurasjon, det skal ha sane defaults.

### Integrasjonstester

Prosjektet inneholder noen integrasjonstester som ligger under [src/intTest](src/integrationTest). Testene bruker blant annet
Prosjektet inneholder noen integrasjonstester som ligger under [src/integrationTest](src/integrationTest). Testene bruker blant annet
testcontainers for å kjøre opp en database som bruke under testene.

Testene er definert med en egen task som kan kjøres slik:
Expand Down

0 comments on commit 578ce57

Please sign in to comment.