Skip to content

Commit 8b2051b

Browse files
committed
Add build targets for a Docker image
Build a docker image using Jib (https://github.com/GoogleContainerTools/jib), and add a Makefile to build, run and build the docker image. See README.md to get started.
1 parent 1933de8 commit 8b2051b

File tree

8 files changed

+110
-4
lines changed

8 files changed

+110
-4
lines changed

Makefile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.PHONY: clean build all
2+
3+
VERSION := $(shell ./version.sh simple)
4+
5+
all: build docker-image
6+
7+
clean:
8+
@echo "Cleaning..."
9+
@./gradlew clean
10+
11+
build:
12+
@echo "Building version ${VERSION}..."
13+
@./gradlew build
14+
15+
run:
16+
@./gradlew run
17+
18+
docker-image:
19+
@echo "Building image ${VERSION}..."
20+
@./gradlew -Pversion=${VERSION} -p server jibDockerBuild

README.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
### Quick start
2+
3+
Build the application with:
4+
5+
```shell
6+
make build
7+
```
8+
9+
Run with:
10+
11+
```shell
12+
make run
13+
```
14+
15+
16+
### Running on Docker
17+
18+
To build a docker image to your local docker daemon:
19+
20+
```shell
21+
make docker-image
22+
```
23+
24+
To run the previously built docker image, e.g.:
25+
````shell
26+
docker run -p 8080:8080 -e "SERVER_PORT=8080" -e "SERVER_HOST=0.0.0.0" -e "WWW_ROOT=/www" bee-software/kickstart
27+
````
28+
29+
30+

buildSrc/build.gradle.kts

+2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ plugins {
44

55
repositories {
66
mavenCentral()
7+
gradlePluginPortal()
78
}
89

910
dependencies {
1011
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.32")
12+
implementation("gradle.plugin.com.google.cloud.tools:jib-gradle-plugin:3.0.0")
1113
}

buildSrc/src/main/kotlin/kickstart.gradle.kts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
33
plugins {
44
java
55
kotlin("jvm")
6+
id("com.google.cloud.tools.jib")
67
}
78

8-
group = "software.bee.kickstart"
9-
version = if (project.hasProperty("version")) project.property("version") as String else "dev"
9+
val buildNumber by extra("0")
1010

1111
repositories {
1212
mavenCentral()

gradle.properties

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
kotlin.code.style=official
1+
kotlin.code.style=official
2+
version=dirty

server/build.gradle.kts

+25
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
plugins {
22
id("kickstart")
3+
application
4+
}
5+
6+
application {
7+
mainClass.set("kickstart.CLI")
38
}
49

510
dependencies {
@@ -14,3 +19,23 @@ dependencies {
1419
testRuntime(libs.simple)
1520
testkitImplementation(libs.hamkrest)
1621
}
22+
23+
jib {
24+
from {
25+
image = "openjdk:16-alpine"
26+
}
27+
to {
28+
image = "bee-software/kickstart"
29+
tags = setOf("$version", "$version.${extra["buildNumber"]}")
30+
}
31+
32+
extraDirectories {
33+
paths {
34+
path {
35+
// copies the contents of www.root into '/www' on the container
36+
setFrom("../webapp/src/www")
37+
into = "/www"
38+
}
39+
}
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
server.host: localhost
22
server.port: 8888
33

4-
www.root: webapp/src/www/
4+
www.root: ../webapp/src/www/

version.sh

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
set -e
3+
4+
git-version() {
5+
if [ -d .git ]; then
6+
git describe --always --tags --long
7+
else
8+
hg log -r . -T "{latesttag}-{latesttagdistance}-m{node|short}" --pager off
9+
fi
10+
}
11+
12+
simple-version() {
13+
if [ -d .git ]; then
14+
echo "$(git rev-list --all --count).$(git rev-parse --short HEAD)"
15+
else
16+
hg log -r . -T "{rev}.{node|short}" --pager off
17+
fi
18+
19+
}
20+
21+
case "${1:-}" in
22+
git)
23+
long-version ;;
24+
simple)
25+
simple-version ;;
26+
*)
27+
git-version ;;
28+
esac

0 commit comments

Comments
 (0)