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 36c295a
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 82 deletions.
49 changes: 49 additions & 0 deletions .github/actions/build-push-docker/action.yaml
Original file line number Diff line number Diff line change
@@ -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
69 changes: 18 additions & 51 deletions .github/workflows/build-deploy.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand All @@ -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 }}
25 changes: 0 additions & 25 deletions .github/workflows/build-test.yaml

This file was deleted.

12 changes: 6 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit 36c295a

Please sign in to comment.