From 00bd2317a11d46f72ce49ad76457b4fc5cf1c40c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20S=C3=B8rensen?= Date: Mon, 30 Sep 2024 13:46:37 +0200 Subject: [PATCH 1/8] Add workflow to deploy to skip --- .github/workflows/skip-deploy.yml | 167 ++++++++++++++++++ .idea/misc.xml | 2 +- DockerfileForSkip | 11 ++ .../kotlin/com/kartverket/plugins/Routing.kt | 9 + 4 files changed, 188 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/skip-deploy.yml create mode 100644 DockerfileForSkip diff --git a/.github/workflows/skip-deploy.yml b/.github/workflows/skip-deploy.yml new file mode 100644 index 0000000..de55050 --- /dev/null +++ b/.github/workflows/skip-deploy.yml @@ -0,0 +1,167 @@ +name: Build and deploy backend to SKIP +on: + workflow_dispatch: + inputs: + commit_sha: + description: 'Commit hash to deploy' + default: '' + type: string + dev: + description: 'Deploy to dev' + required: true + type: boolean + prod: + description: 'Deploy to prod' + required: true + type: boolean + pull_request: + branches: + - main + paths: + - src/** + - .github/workflows/skip-deploy.yml + - gradle.properties + - build.gradle.kts + push: + branches: + - main + paths: + - src/** + - .github/workflows/skip-deploy.yml + - gradle.properties + - build.gradle.kts + +permissions: + id-token: write + contents: write + +env: + REGISTRY: ghcr.io + ARGO_VERSION_FILE: image-url-frisk-backend + +jobs: + build: + name: Build and push docker image + runs-on: ubuntu-latest + permissions: + contents: write + packages: write + outputs: + image_url: ${{ steps.setOutput.outputs.image_url }} + + steps: + - name: Checkout code + if: ${{ !(github.event_name == 'workflow_dispatch' && github.event.inputs.commit_sha == '') }} + uses: actions/checkout@v4 + + - name: Checkout code + if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.commit_sha == '' }} + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Checkout specific commit + if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.commit_sha == '' }} + run: git checkout ${{ github.event.inputs.commit_sha }} + + - uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '21' + architecture: 'x64' + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + + - name: Generate and submit dependency graph + uses: gradle/actions/dependency-submission@v3 + + - name: Execute Gradle build + working-directory: backend + run: ./gradlew shadowJar + + - name: Set tag + id: set-tag + env: + BRANCH: ${{ github.ref_name }} + run: | + if [[ "$BRANCH" == "main" || "$BRANCH" == "master" ]]; then + echo "image_tag=latest" >> $GITHUB_OUTPUT + else + echo "image_tag=prebuild-temp" >> $GITHUB_OUTPUT + fi + + - name: Login to Github Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ github.repository }} + tags: | + type=sha,format=long + type=raw,value=${{ steps.set-tag.outputs.image_tag }} + + - name: Build docker and push + id: build-docker + uses: docker/build-push-action@v5 + with: + context: . + file: DockerfileForSkip + push: ${{ !github.event.pull_request.draft }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + - name: Set output with build values + id: setOutput + run: | + echo "image_url=${{ env.REGISTRY }}/${{ github.repository }}@${{ steps.build-docker.outputs.digest }}" >> $GITHUB_OUTPUT + + pharos: + name: Run Pharos + needs: build + permissions: + actions: read + packages: read + contents: read + security-events: write + runs-on: ubuntu-latest + steps: + - name: "Run Pharos" + uses: kartverket/pharos@v0.1.5 + with: + image_url: ${{ needs.build.outputs.image_url }} + + deploy-dev: + name: Deploy to dev + if: ${{ github.ref == 'refs/heads/main' && (github.event_name != 'workflow_dispatch' || (github.event_name == 'workflow_dispatch' && github.event.inputs.dev == 'true')) }} + needs: build + runs-on: ubuntu-latest + environment: + name: dev + permissions: + id-token: write + steps: + - uses: octo-sts/action@6177b4481c00308b3839969c3eca88c96a91775f # v1.0.0 + id: octo-sts + with: + scope: kartverket/skvis-apps + identity: regelrett-backend + - name: Checkout skvis-apps + uses: actions/checkout@v4 + with: + repository: kartverket/skvis-apps + ref: main + token: ${{ steps.octo-sts.outputs.token }} + - name: Update version + run: | + echo "\"${{ needs.build.outputs.image_url }}\"" > "env/atgcp1-dev/regelrett-main/${{ env.ARGO_VERSION_FILE }}" + git config --global user.email "noreply@kartverket.no" + git config --global user.name "Frisk CI" + git commit -am "Update ${{ env.ARGO_VERSION_FILE }}" + git push \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 0dda7ee..a77594e 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -4,5 +4,5 @@ - + \ No newline at end of file diff --git a/DockerfileForSkip b/DockerfileForSkip new file mode 100644 index 0000000..dfdf911 --- /dev/null +++ b/DockerfileForSkip @@ -0,0 +1,11 @@ +# Use a minimal JDK image to run the application +FROM eclipse-temurin:21-jre-alpine +RUN apk update && apk upgrade +# Create a non-root +RUN mkdir /app +EXPOSE 8080 +RUN adduser -D user && chown -R user /app +WORKDIR . +COPY build/libs/*.jar /app/frisk-backend.jar +USER user +ENTRYPOINT ["java","-jar","/app/frisk-backend.jar"] \ No newline at end of file diff --git a/src/main/kotlin/com/kartverket/plugins/Routing.kt b/src/main/kotlin/com/kartverket/plugins/Routing.kt index c9aa3bd..2d72bfb 100644 --- a/src/main/kotlin/com/kartverket/plugins/Routing.kt +++ b/src/main/kotlin/com/kartverket/plugins/Routing.kt @@ -1,12 +1,16 @@ package com.kartverket.plugins +import com.kartverket.Database +import com.kartverket.functions.FunctionService import com.kartverket.functions.dependencies.functionDependenciesRoutes import com.kartverket.functions.functionRoutes import com.kartverket.functions.metadata.functionMetadataRoutes +import io.ktor.http.* import io.ktor.server.application.* import io.ktor.server.auth.* import io.ktor.server.routing.* import io.ktor.server.plugins.swagger.* +import io.ktor.server.response.* fun Application.configureRouting() { routing { @@ -18,5 +22,10 @@ fun Application.configureRouting() { // some of these routes shall be protected by another type of auth functionMetadataRoutes() } + route("/functions") { + get("/health") { + call.respondText("Up and running!", ContentType.Text.Plain) + } + } } } From 23ecfc009b07785ab86d2169e7017b171bd99108 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20S=C3=B8rensen?= Date: Mon, 30 Sep 2024 14:34:29 +0200 Subject: [PATCH 2/8] update --- .github/workflows/skip-deploy.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/skip-deploy.yml b/.github/workflows/skip-deploy.yml index de55050..69d3818 100644 --- a/.github/workflows/skip-deploy.yml +++ b/.github/workflows/skip-deploy.yml @@ -77,7 +77,6 @@ jobs: uses: gradle/actions/dependency-submission@v3 - name: Execute Gradle build - working-directory: backend run: ./gradlew shadowJar - name: Set tag From 8a24b1b6aac695231e206e136ae79d1b30dea540 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20S=C3=B8rensen?= Date: Mon, 30 Sep 2024 14:37:23 +0200 Subject: [PATCH 3/8] update --- .github/workflows/skip-deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/skip-deploy.yml b/.github/workflows/skip-deploy.yml index 69d3818..010becb 100644 --- a/.github/workflows/skip-deploy.yml +++ b/.github/workflows/skip-deploy.yml @@ -150,7 +150,7 @@ jobs: id: octo-sts with: scope: kartverket/skvis-apps - identity: regelrett-backend + identity: frisk-backend - name: Checkout skvis-apps uses: actions/checkout@v4 with: From ca4b17ac2c0aa9b78ebb41a6a7e08a11093ff1d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20S=C3=B8rensen?= Date: Mon, 30 Sep 2024 14:52:48 +0200 Subject: [PATCH 4/8] Update --- build.gradle.kts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/build.gradle.kts b/build.gradle.kts index d767036..f42980a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,3 +1,4 @@ +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar val kotlin_version: String by project val logback_version: String by project @@ -10,6 +11,7 @@ plugins { id("io.ktor.plugin") version "2.3.12" id("org.jetbrains.kotlin.plugin.serialization") version "2.0.20" id("org.flywaydb.flyway") version "9.22.0" // or latest + id("com.gradleup.shadow") version "8.3.0" } group = "com.kartverket" @@ -53,4 +55,10 @@ flyway { user = "my_user" password = "my_password" locations = arrayOf("filesystem:src/main/resources/db/migration") +} + +tasks { + withType { + mergeServiceFiles() + } } \ No newline at end of file From 4722d5a4eaffd05bf0ad40d5a8ab328b6cc4aeb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20S=C3=B8rensen?= Date: Mon, 30 Sep 2024 15:02:10 +0200 Subject: [PATCH 5/8] Update --- .dockerignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.dockerignore b/.dockerignore index 2e3fece..342d99d 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,5 @@ # flyctl launch added from .gitignore **/.gradle -**/build !**/gradle/wrapper/gradle-wrapper.jar !**/**/src/main/**/build !**/**/src/test/**/build From 304c1b210c3ff9cb6df6135dfb333878913bfb87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20S=C3=B8rensen?= Date: Mon, 30 Sep 2024 15:22:29 +0200 Subject: [PATCH 6/8] Update --- .github/workflows/skip-deploy.yml | 2 +- .idea/misc.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/skip-deploy.yml b/.github/workflows/skip-deploy.yml index 010becb..4f13d47 100644 --- a/.github/workflows/skip-deploy.yml +++ b/.github/workflows/skip-deploy.yml @@ -132,7 +132,7 @@ jobs: runs-on: ubuntu-latest steps: - name: "Run Pharos" - uses: kartverket/pharos@v0.1.5 + uses: kartverket/pharos@v0.2.1 with: image_url: ${{ needs.build.outputs.image_url }} diff --git a/.idea/misc.xml b/.idea/misc.xml index a77594e..596538b 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -4,5 +4,5 @@ - + \ No newline at end of file From d283bc7d13d6d139e5942749a3d0c6b1cf9d6663 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20S=C3=B8rensen?= Date: Mon, 30 Sep 2024 16:02:03 +0200 Subject: [PATCH 7/8] Update --- .github/workflows/skip-deploy.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/skip-deploy.yml b/.github/workflows/skip-deploy.yml index 4f13d47..10346e1 100644 --- a/.github/workflows/skip-deploy.yml +++ b/.github/workflows/skip-deploy.yml @@ -20,6 +20,7 @@ on: paths: - src/** - .github/workflows/skip-deploy.yml + - DockerfileForSkip - gradle.properties - build.gradle.kts push: @@ -28,6 +29,7 @@ on: paths: - src/** - .github/workflows/skip-deploy.yml + - DockerfileForSkip - gradle.properties - build.gradle.kts From c197cd16ff8b6f93ee9711212b355abaea820818 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20S=C3=B8rensen?= <54811127+larsore@users.noreply.github.com> Date: Tue, 1 Oct 2024 14:17:39 +0200 Subject: [PATCH 8/8] Update .github/workflows/skip-deploy.yml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Johannes BrĂ¥then Oma --- .github/workflows/skip-deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/skip-deploy.yml b/.github/workflows/skip-deploy.yml index 10346e1..5b1c26c 100644 --- a/.github/workflows/skip-deploy.yml +++ b/.github/workflows/skip-deploy.yml @@ -134,7 +134,7 @@ jobs: runs-on: ubuntu-latest steps: - name: "Run Pharos" - uses: kartverket/pharos@v0.2.1 + uses: kartverket/pharos@v0.2.2 with: image_url: ${{ needs.build.outputs.image_url }}