Skip to content

Commit

Permalink
Add Docker build (#661)
Browse files Browse the repository at this point in the history
* Add build Docker image
  • Loading branch information
roar-skinderviken authored Aug 13, 2024
1 parent 7f0ff82 commit 8ebeac7
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 2 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/build-docker-and-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Build Docker and push

on:
push:
tags:
- '*'

env:
REGISTRY: ghcr.io
IMAGE: ${{ github.repository }}

jobs:
build_and_push_docker:
permissions:
contents: read
packages: write

runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set docker image env var
run: |
echo "DOCKER_IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE }}:${{ github.ref_name }}" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: linux/amd64,linux/arm64

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3

- name: Build with Gradle
run: ./gradlew build -p web --build-cache --info

- name: 'Login to GitHub Container Registry'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker images
uses: docker/build-push-action@v6
with:
context: ./web
platforms: linux/amd64,linux/arm64
push: true
provenance: false
tags: |
${{ env.DOCKER_IMAGE }}
4 changes: 4 additions & 0 deletions web/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM bellsoft/liberica-openjdk-alpine:21
ARG JAR_FILE=build/libs/*-all.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
22 changes: 22 additions & 0 deletions web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,25 @@ Kjøre frontend-tester (også en del av `./gradlew check`)
npx vitest run
```

Bygge Docker-image, kostra-kontrollprogram-web
```bash
./gradlew clean -p web jibDockerBuild --image=kostra-kontrollprogram
```

Liste alle Docker-images
```bash
docker images
```
kostra-kontrollprogram:latest vil vises i listen.

Kjør Docker
```bash
docker run --name kostra-kontrollprogram -p 8080:8080 kostra-kontrollprogram:latest
```
Applikasjonen vil være tilgjengelig på http://localhost:8080/

Rydde opp
```bash
docker rm kostra-kontrollprogram # fjerne stanset container
docker rmi kostra-kontrollprogram # fjerne Docker-image
```
4 changes: 2 additions & 2 deletions web/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ tasks.register<Copy>("processFrontendResources") {
into(backendTargetDir)
}

tasks.named<Task>("processResources") {
tasks.named("processResources") {
dependsOn("processFrontendResources")
}
}

0 comments on commit 8ebeac7

Please sign in to comment.