Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workflow to deploy to skip #12

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# flyctl launch added from .gitignore
**/.gradle
**/build
!**/gradle/wrapper/gradle-wrapper.jar
!**/**/src/main/**/build
!**/**/src/test/**/build
Expand Down
168 changes: 168 additions & 0 deletions .github/workflows/skip-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
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
- DockerfileForSkip
- gradle.properties
- build.gradle.kts
push:
branches:
- main
paths:
- src/**
- .github/workflows/skip-deploy.yml
- DockerfileForSkip
- 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
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/[email protected]
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: frisk-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 "[email protected]"
git config --global user.name "Frisk CI"
git commit -am "Update ${{ env.ARGO_VERSION_FILE }}"
git push
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions DockerfileForSkip
Original file line number Diff line number Diff line change
@@ -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"]
8 changes: 8 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -53,4 +55,10 @@ flyway {
user = "my_user"
password = "my_password"
locations = arrayOf("filesystem:src/main/resources/db/migration")
}

tasks {
withType<ShadowJar> {
mergeServiceFiles()
}
}
9 changes: 9 additions & 0 deletions src/main/kotlin/com/kartverket/plugins/Routing.kt
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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)
}
}
}
}
Loading