Skip to content

Commit 7aa2716

Browse files
committed
Adding files needed for the dockerization of the app
Signed-off-by: Alfredo Gutierrez <[email protected]>
1 parent 6e8a3e8 commit 7aa2716

File tree

8 files changed

+117
-0
lines changed

8 files changed

+117
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,5 @@ gradle-app.setting
4747
# JDT-specific (Eclipse Java Development Tools)
4848
.classpath
4949

50+
# .env files
51+
server/docker/.env

server/build.gradle.kts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,40 @@ testModuleInfo {
2929
requires("org.mockito")
3030
requires("org.mockito.junit.jupiter")
3131
}
32+
33+
var updateDockerEnv =
34+
tasks.register<Exec>("updateDockerEnv") {
35+
description =
36+
"Creates the .env file in the docker folder that contains environment variables for docker"
37+
group = "docker"
38+
39+
workingDir(layout.projectDirectory.dir("docker"))
40+
commandLine("./update-env.sh", project.version)
41+
}
42+
43+
tasks.register<Exec>("createDockerImage") {
44+
description = "Creates the docker image of the Block Node Server based on the current version"
45+
group = "docker"
46+
47+
dependsOn(updateDockerEnv, tasks.assemble)
48+
workingDir(layout.projectDirectory.dir("docker"))
49+
commandLine("./docker-build.sh", project.version, layout.projectDirectory.dir("..").asFile)
50+
}
51+
52+
tasks.register<Exec>("startDockerContainer") {
53+
description = "Starts the docker container of the Block Node Server of the current version"
54+
group = "docker"
55+
56+
dependsOn(updateDockerEnv)
57+
workingDir(layout.projectDirectory.dir("docker"))
58+
commandLine("sh", "-c", "docker-compose -p block-node up -d")
59+
}
60+
61+
tasks.register<Exec>("stopDockerContainer") {
62+
description = "Stops running docker containers of the Block Node Server"
63+
group = "docker"
64+
65+
dependsOn(updateDockerEnv)
66+
workingDir(layout.projectDirectory.dir("docker"))
67+
commandLine("sh", "-c", "docker-compose -p block-node stop")
68+
}

server/docker/.dockerignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.iml
2+
*.md
3+
*.sw*
4+
*.csv
5+
6+
mvnw*
7+
LICENSE*
8+
9+
.java-version

server/docker/Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Use Eclipse Temurin with Java 21 as the base image
2+
FROM eclipse-temurin:21
3+
4+
# Define version
5+
ARG VERSION
6+
7+
# Set the working directory inside the container
8+
WORKDIR /app
9+
10+
# Copy Distribution TAR file
11+
COPY --from=distributions server-${VERSION}.tar .
12+
13+
# Extract the TAR file
14+
RUN tar -xvf server-${VERSION}.tar
15+
16+
# Expose the port that the application will run on
17+
EXPOSE 8080
18+
19+
# RUN the bin script for starting the server
20+
ENTRYPOINT ["sh", "-c", "/app/server-${VERSION}/bin/server"]

server/docker/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
This folder contains file that are used to start the services as docker containers.
2+
All docker workflows are defined with a corresponding gradle task. No script or file in this folder should be called 'by hand'.
3+
4+
Gradle tasks are of group `docker`
5+
- updateDockerEnv
6+
- createDockerImage
7+
- startDockerContainer
8+
- stopDockerContainer

server/docker/docker-build.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
3+
if [[ $# -lt 1 ]]; then
4+
echo "Usage: ${0} [version] [project_dir]"
5+
exit 1
6+
fi
7+
8+
VERSION=${1}
9+
10+
echo "CREATING CONTAINER FOR VERSION ${VERSION}"
11+
echo "Using project directory: ${2}"
12+
echo
13+
14+
# run docker build
15+
echo "Building container:"
16+
docker buildx build --load -t "block-node-server:${1}" --build-context distributions=../build/distributions --build-arg VERSION="${VERSION}" . || exit "${?}"

server/docker/docker-compose.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: '3.8'
2+
3+
services:
4+
block-node-server:
5+
image: block-node-server:${VERSION}
6+
env_file:
7+
- .env
8+
ports:
9+
- "8080:8080"

server/docker/update-env.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
3+
# This scripts create a '.env' file that is used for docker & docker-compose as an input of environment variables.
4+
# This script is called by gradle and get the current project version as an input param
5+
6+
if [ $# -lt 1 ]; then
7+
echo "USAGE: $0 <VERSION>"
8+
exit 1
9+
fi
10+
11+
echo "VERSION=$1" > .env
12+
echo "REGISTRY_PREFIX=" >> .env
13+
# Storage root path, this is temporary until we have a proper .properties file for all configs
14+
echo "BLOCKNODE_STORAGE_ROOT_PATH=/app/storage" >> .env
15+
16+
echo "VERSION/TAG UPDATED TO $1"

0 commit comments

Comments
 (0)