Skip to content

Commit

Permalink
Adding files needed for the dockerization of the app
Browse files Browse the repository at this point in the history
Signed-off-by: Alfredo Gutierrez <[email protected]>
  • Loading branch information
AlfredoG87 committed Jul 19, 2024
1 parent 6e8a3e8 commit 7aa2716
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@ gradle-app.setting
# JDT-specific (Eclipse Java Development Tools)
.classpath

# .env files
server/docker/.env
37 changes: 37 additions & 0 deletions server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,40 @@ testModuleInfo {
requires("org.mockito")
requires("org.mockito.junit.jupiter")
}

var updateDockerEnv =
tasks.register<Exec>("updateDockerEnv") {
description =
"Creates the .env file in the docker folder that contains environment variables for docker"
group = "docker"

workingDir(layout.projectDirectory.dir("docker"))
commandLine("./update-env.sh", project.version)
}

tasks.register<Exec>("createDockerImage") {
description = "Creates the docker image of the Block Node Server based on the current version"
group = "docker"

dependsOn(updateDockerEnv, tasks.assemble)
workingDir(layout.projectDirectory.dir("docker"))
commandLine("./docker-build.sh", project.version, layout.projectDirectory.dir("..").asFile)
}

tasks.register<Exec>("startDockerContainer") {
description = "Starts the docker container of the Block Node Server of the current version"
group = "docker"

dependsOn(updateDockerEnv)
workingDir(layout.projectDirectory.dir("docker"))
commandLine("sh", "-c", "docker-compose -p block-node up -d")
}

tasks.register<Exec>("stopDockerContainer") {
description = "Stops running docker containers of the Block Node Server"
group = "docker"

dependsOn(updateDockerEnv)
workingDir(layout.projectDirectory.dir("docker"))
commandLine("sh", "-c", "docker-compose -p block-node stop")
}
9 changes: 9 additions & 0 deletions server/docker/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.iml
*.md
*.sw*
*.csv

mvnw*
LICENSE*

.java-version
20 changes: 20 additions & 0 deletions server/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use Eclipse Temurin with Java 21 as the base image
FROM eclipse-temurin:21

# Define version
ARG VERSION

# Set the working directory inside the container
WORKDIR /app

# Copy Distribution TAR file
COPY --from=distributions server-${VERSION}.tar .

# Extract the TAR file
RUN tar -xvf server-${VERSION}.tar

# Expose the port that the application will run on
EXPOSE 8080

# RUN the bin script for starting the server
ENTRYPOINT ["sh", "-c", "/app/server-${VERSION}/bin/server"]
8 changes: 8 additions & 0 deletions server/docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
This folder contains file that are used to start the services as docker containers.
All docker workflows are defined with a corresponding gradle task. No script or file in this folder should be called 'by hand'.

Gradle tasks are of group `docker`
- updateDockerEnv
- createDockerImage
- startDockerContainer
- stopDockerContainer
16 changes: 16 additions & 0 deletions server/docker/docker-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

if [[ $# -lt 1 ]]; then
echo "Usage: ${0} [version] [project_dir]"
exit 1
fi

VERSION=${1}

echo "CREATING CONTAINER FOR VERSION ${VERSION}"
echo "Using project directory: ${2}"
echo

# run docker build
echo "Building container:"
docker buildx build --load -t "block-node-server:${1}" --build-context distributions=../build/distributions --build-arg VERSION="${VERSION}" . || exit "${?}"
9 changes: 9 additions & 0 deletions server/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: '3.8'

services:
block-node-server:
image: block-node-server:${VERSION}
env_file:
- .env
ports:
- "8080:8080"
16 changes: 16 additions & 0 deletions server/docker/update-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

# This scripts create a '.env' file that is used for docker & docker-compose as an input of environment variables.
# This script is called by gradle and get the current project version as an input param

if [ $# -lt 1 ]; then
echo "USAGE: $0 <VERSION>"
exit 1
fi

echo "VERSION=$1" > .env
echo "REGISTRY_PREFIX=" >> .env
# Storage root path, this is temporary until we have a proper .properties file for all configs
echo "BLOCKNODE_STORAGE_ROOT_PATH=/app/storage" >> .env

echo "VERSION/TAG UPDATED TO $1"

0 comments on commit 7aa2716

Please sign in to comment.