update dockerfiles

- define user uid/gid
- use new geedeecee files (hopefully means smaller images, faster building)
This commit is contained in:
Adam 2022-10-22 19:55:02 +02:00
parent e370cb5ef9
commit 9b331cc105
15 changed files with 95 additions and 119 deletions

View file

@ -1,3 +1,4 @@
import kafkatorio.extensions.dropDirectory
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins { plugins {
@ -90,6 +91,15 @@ val runEventsProcessors by tasks.registering {
dependsOn(tasks.run) dependsOn(tasks.run)
} }
tasks.dockerComposeBuild {
dependsOn(tasks.distTar) tasks.dockerContextPrepareFiles {
from(zipTree(tasks.distZip.flatMap { it.archiveFile })) {
eachFile {
relativePath = relativePath.dropDirectory()
if (!isDirectory && relativePath.pathString.matches("""bin\/.+""".toRegex())) {
name = name.replace(file.nameWithoutExtension, "run")
}
}
}
} }

View file

@ -2,21 +2,18 @@
FROM eclipse-temurin:11-jdk-jammy FROM eclipse-temurin:11-jdk-jammy
ARG KAFKATORIO_VERSION ARG KAFKATORIO_VERSION
ARG DIST_DIR="../build/distributions/" ARG APP_FILES="build/"
ARG APP_NAME="events-processors" ARG USER_ID=1000
ARG USER_GID=1000
WORKDIR /app USER $USER_ID:$USER_GID
ENV SERVER_DATA_DIR="/app/data" \
KAFKA_STREAMS_STATE_DIR="/app/state/kafka"
ENV SERVER_DATA_DIR="/app/data"
ENV KAFKA_STREAMS_STATE_DIR="/app/state/kafka"
VOLUME ${SERVER_DATA_DIR} \ VOLUME ${SERVER_DATA_DIR} \
${KAFKA_STREAMS_STATE_DIR} ${KAFKA_STREAMS_STATE_DIR}
COPY ${DIST_DIR}/${APP_NAME}-${KAFKATORIO_VERSION}.tar ${APP_NAME}.tar COPY ${APP_FILES} /app/
RUN tar -xf ${APP_NAME}.tar --strip-components=1 \
&& rm ${APP_NAME}.tar \
&& cp /app/bin/${APP_NAME} /app/bin/run \
&& chmod 775 /app/bin/run
ENTRYPOINT /app/bin/run ENTRYPOINT /app/bin/run

View file

@ -7,12 +7,11 @@ services:
container_name: ${APP_NAME} container_name: ${APP_NAME}
restart: unless-stopped restart: unless-stopped
build: build:
context: .. context: .
dockerfile: ./docker/Dockerfile dockerfile: Dockerfile
args: args:
KAFKATORIO_VERSION: ${KAFKATORIO_VERSION} KAFKATORIO_VERSION: ${KAFKATORIO_VERSION}
DIST_DIR: "./build/distributions/" APP_FILES: "./build/"
APP_NAME: ${APP_NAME}
environment: environment:
KAFKA_BOOTSTRAP_SERVERS: "http://kafka:29092" KAFKA_BOOTSTRAP_SERVERS: "http://kafka:29092"
# KAFKA_STREAMS_STATE_DIR: "" # KAFKA_STREAMS_STATE_DIR: ""

View file

@ -1,3 +1,4 @@
import kafkatorio.extensions.dropDirectory
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
@ -88,6 +89,14 @@ val runSyslogServer by tasks.registering {
dependsOn(tasks.run) dependsOn(tasks.run)
} }
tasks.dockerComposeBuild { tasks.dockerContextPrepareFiles {
dependsOn(tasks.distTar) from(zipTree(tasks.distZip.flatMap { it.archiveFile })) {
eachFile {
relativePath = relativePath.dropDirectory()
if (!isDirectory && relativePath.pathString.matches("""bin\/.+""".toRegex())) {
name = name.replace(file.nameWithoutExtension, "run")
}
}
}
} }

View file

@ -2,26 +2,22 @@
FROM eclipse-temurin:11-jdk-jammy FROM eclipse-temurin:11-jdk-jammy
ARG KAFKATORIO_VERSION ARG KAFKATORIO_VERSION
ARG DIST_DIR="../build/distributions/" ARG APP_FILES="build/"
ARG APP_NAME="events-server-syslog" ARG USER_ID=1000
ARG USER_GID=1000
WORKDIR /app USER $USER_ID:$USER_GID
ENV SERVER_DATA_DIR="/app/data" \
KAFKA_STREAMS_STATE_DIR="/app/state/kafka" \
SOCKET_SERVER_HOST=0.0.0.0 \
SOCKET_SERVER_PORT=9002
ENV SOCKET_SERVER_HOST=0.0.0.0
ENV SOCKET_SERVER_PORT=9002
EXPOSE $SOCKET_SERVER_PORT EXPOSE $SOCKET_SERVER_PORT
ENV SERVER_DATA_DIR="/app/data"
ENV KAFKA_STREAMS_STATE_DIR="/app/state/kafka"
VOLUME ${SERVER_DATA_DIR} \ VOLUME ${SERVER_DATA_DIR} \
${KAFKA_STREAMS_STATE_DIR} ${KAFKA_STREAMS_STATE_DIR}
COPY ${DIST_DIR}/${APP_NAME}-${KAFKATORIO_VERSION}.tar ${APP_NAME}.tar COPY ${APP_FILES} /app/
RUN tar -xf ${APP_NAME}.tar --strip-components=1 \
&& rm ${APP_NAME}.tar \
&& cp /app/bin/${APP_NAME} /app/bin/run \
&& chmod 775 /app/bin/run
ENTRYPOINT /app/bin/run ENTRYPOINT /app/bin/run

View file

@ -7,12 +7,11 @@ services:
container_name: ${APP_NAME} container_name: ${APP_NAME}
restart: unless-stopped restart: unless-stopped
build: build:
context: .. context: .
dockerfile: ./docker/Dockerfile dockerfile: Dockerfile
args: args:
KAFKATORIO_VERSION: ${KAFKATORIO_VERSION} KAFKATORIO_VERSION: ${KAFKATORIO_VERSION}
DIST_DIR: "./build/distributions/" APP_FILES: "./build/"
APP_NAME: ${APP_NAME}
environment: environment:
KAFKA_BOOTSTRAP_SERVERS: "http://kafka:29092" KAFKA_BOOTSTRAP_SERVERS: "http://kafka:29092"
# KAFKA_STREAMS_STATE_DIR: "" # KAFKA_STREAMS_STATE_DIR: ""

View file

@ -1,3 +1,4 @@
import kafkatorio.extensions.dropDirectory
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
@ -91,6 +92,14 @@ val runEventsWebServer by tasks.registering {
dependsOn(tasks.run) dependsOn(tasks.run)
} }
tasks.dockerComposeBuild { tasks.dockerContextPrepareFiles {
dependsOn(tasks.distTar) from(zipTree(tasks.distZip.flatMap { it.archiveFile })) {
eachFile {
relativePath = relativePath.dropDirectory()
if (!isDirectory && relativePath.pathString.matches("""bin\/.+""".toRegex())) {
name = name.replace(file.nameWithoutExtension, "run")
}
}
}
} }

View file

@ -1,26 +1,22 @@
# syntax=docker/dockerfile:1 # syntax=docker/dockerfile:1
FROM openjdk:11 FROM eclipse-temurin:11-jdk-jammy
ARG KAFKATORIO_VERSION ARG KAFKATORIO_VERSION
ARG DIST_DIR="../build/distributions/" ARG APP_FILES="build/"
ARG APP_NAME="events-server-web" ARG USER_ID=1000
ARG USER_GID=1000
WORKDIR /app USER $USER_ID:$USER_GID
ENV SERVER_DATA_DIR="/app/data" \
KAFKA_STREAMS_STATE_DIR="/app/state/kafka" \
WEB_SERVER_PORT=80
ENV WEB_SERVER_PORT=80
EXPOSE $WEB_SERVER_PORT EXPOSE $WEB_SERVER_PORT
ENV SERVER_DATA_DIR="/app/data"
ENV KAFKA_STREAMS_STATE_DIR="/app/state/kafka"
VOLUME ${SERVER_DATA_DIR} \ VOLUME ${SERVER_DATA_DIR} \
${KAFKA_STREAMS_STATE_DIR} ${KAFKA_STREAMS_STATE_DIR}
COPY ${DIST_DIR}/${APP_NAME}-${KAFKATORIO_VERSION}.tar ${APP_NAME}.tar COPY ${APP_FILES} /app/
RUN tar -xf ${APP_NAME}.tar --strip-components=1 \
&& rm ${APP_NAME}.tar \
&& cp /app/bin/${APP_NAME} /app/bin/run \
&& chmod 775 /app/bin/run
ENTRYPOINT /app/bin/run ENTRYPOINT /app/bin/run

View file

@ -7,12 +7,11 @@ services:
container_name: ${APP_NAME} container_name: ${APP_NAME}
restart: unless-stopped restart: unless-stopped
build: build:
context: .. context: .
dockerfile: ./docker/Dockerfile dockerfile: Dockerfile
args: args:
KAFKATORIO_VERSION: ${KAFKATORIO_VERSION} KAFKATORIO_VERSION: ${KAFKATORIO_VERSION}
DIST_DIR: "./build/distributions/" APP_FILES: "./build/"
APP_NAME: ${APP_NAME}
environment: environment:
KAFKA_BOOTSTRAP_SERVERS: "http://kafka:29092" KAFKA_BOOTSTRAP_SERVERS: "http://kafka:29092"
# KAFKA_STREAMS_STATE_DIR: "" # KAFKA_STREAMS_STATE_DIR: ""

View file

@ -2,24 +2,23 @@
FROM eclipse-temurin:11-jdk-jammy FROM eclipse-temurin:11-jdk-jammy
ARG KAFKATORIO_VERSION ARG KAFKATORIO_VERSION
ARG DIST_DIR="../build/distributions/" ARG APP_FILES="build/"
ARG USER_ID=1000
ARG USER_GID=1000
WORKDIR /app USER $USER_ID:$USER_GID
ENV SERVER_PORT=8080 ENV SERVER_DATA_DIR="/app/data" \
EXPOSE $SERVER_PORT KAFKA_STREAMS_STATE_DIR="/app/state/kafka" \
SERVER_PORT=8080 \
SOCKET_SERVER_PORT=9002
ENV SOCKET_SERVER_PORT=9002 EXPOSE $SERVER_PORT \
EXPOSE $SOCKET_SERVER_PORT $SOCKET_SERVER_PORT
ENV SERVER_DATA_DIR="/app/data"
ENV KAFKA_STREAMS_STATE_DIR="/app/state/kafka"
VOLUME ${SERVER_DATA_DIR} \ VOLUME ${SERVER_DATA_DIR} \
${KAFKA_STREAMS_STATE_DIR} ${KAFKA_STREAMS_STATE_DIR}
COPY ${DIST_DIR}/events-server-${KAFKATORIO_VERSION}.tar events-server.tar COPY ${APP_FILES} /app/
RUN tar -xf events-server.tar --strip-components=1 \ ENTRYPOINT /app/bin/run
&& rm events-server.tar
ENTRYPOINT /app/bin/events-server

View file

@ -7,12 +7,11 @@ services:
container_name: ${APP_NAME} container_name: ${APP_NAME}
restart: unless-stopped restart: unless-stopped
build: build:
context: .. context: .
dockerfile: ./docker/Dockerfile dockerfile: Dockerfile
args: args:
KAFKATORIO_VERSION: ${KAFKATORIO_VERSION} KAFKATORIO_VERSION: ${KAFKATORIO_VERSION}
DIST_DIR: "./build/distributions/" APP_FILES: "./build/"
APP_NAME: ${APP_NAME}
environment: environment:
KAFKA_BOOTSTRAP_SERVERS: "http://kafka:29092" KAFKA_BOOTSTRAP_SERVERS: "http://kafka:29092"
# KAFKA_STREAMS_STATE_DIR: "" # KAFKA_STREAMS_STATE_DIR: ""

View file

@ -1,5 +1,3 @@
import dev.adamko.geedeecee.DockerComposeExec
plugins { plugins {
id("kafkatorio.conventions.base") id("kafkatorio.conventions.base")
id("dev.adamko.geedeecee") id("dev.adamko.geedeecee")
@ -17,39 +15,3 @@ geedeecee {
tasks.dockerComposeUp { tasks.dockerComposeUp {
dependsOn(":modules:infra-kafka-cluster:dockerUp") dependsOn(":modules:infra-kafka-cluster:dockerUp")
} }
val dockerBuildKafkaPipe by tasks.registering(DockerComposeExec::class) {
dockerComposeDir.set(geedeecee.srcDir)
command.set("docker-compose build kafka-pipe")
// inputs.property("dockerSrcDirChecksum") { dockerSrcDir.filesChecksum() }
//
// outputs.upToDateWhen {
// it.inputs.properties["dockerSrcDirChecksum"] as? Long? == dockerSrcDir.filesChecksum()
// }
// val imageIdFile = file("$temporaryDir/docker-image-id.txt")
// outputs.file(imageIdFile)
// workingDir = dockerSrcDir.asFile
// commandLine = parseSpaceSeparatedArgs(""" docker-compose build kafka-pipe """)
// doLast {
// sync {
// from(dockerSrcDir)
// into(temporaryDir)
// }
// imageIdFile.outputStream().use { os ->
// exec {
// workingDir = dockerSrcDir.asFile
// commandLine = parseSpaceSeparatedArgs(""" docker-compose images -q kafka-pipe """)
// standardOutput = os
// }
// }
//}
}
tasks.assemble { dependsOn(dockerBuildKafkaPipe) }

View file

@ -148,6 +148,6 @@ tasks.zip {
} }
tasks.dockerComposeBuild { tasks.dockerContextPrepareFiles {
dependsOn(tasks.zip) from(zipTree(tasks.zip.flatMap { it.archiveFile }))
} }

View file

@ -1,9 +1,10 @@
# syntax=docker/dockerfile:1 # syntax=docker/dockerfile:1
FROM nginx FROM nginx
ARG APP_FILES="build/"
EXPOSE 80 EXPOSE 80
COPY ./docker/nginx.conf /etc/nginx/nginx.conf COPY ./nginx.conf /etc/nginx/nginx.conf
COPY ./build/distributions /usr/share/nginx/html COPY $APP_FILES /usr/share/nginx/html

View file

@ -7,10 +7,11 @@ services:
container_name: ${APP_NAME} container_name: ${APP_NAME}
restart: unless-stopped restart: unless-stopped
build: build:
context: ".." context: .
dockerfile: ./docker/Dockerfile dockerfile: Dockerfile
args: args:
APP_NAME: ${APP_NAME} KAFKATORIO_VERSION: ${KAFKATORIO_VERSION}
APP_FILES: "./build/"
ports: ports:
- "12081:80" - "12081:80"
networks: networks: