dchat/Dockerfile

96 lines
2.5 KiB
Text
Raw Permalink Normal View History

# syntax=docker/dockerfile:1.4.0
ARG MAVEN_CLI_OPTS="--batch-mode --no-transfer-progress -Dmaven.test.skip"
# Copy all project files
2023-11-23 20:07:26 +01:00
FROM docker.io/maven:3.9-eclipse-temurin-21 AS setup
WORKDIR /app
# Copy the dependency specifications
COPY pom.xml .
COPY db/pom.xml db/
COPY bot/pom.xml bot/
COPY migration/pom.xml migration/
COPY web/pom.xml web/
# Resolve dependencies for shared libraries
RUN --mount=type=cache,target=/root/.m2/ \
2023-07-27 00:28:04 +02:00
mvn ${MAVEN_CLI_OPTS} -pl db -am dependency:go-offline
# Install the shared libraries in the local Maven repo (`.m2`)
# This will also install the `root` module.
# Build db dependency
FROM setup AS db-build
COPY db db
RUN --mount=type=cache,target=/root/.m2/ \
2023-07-27 00:28:04 +02:00
mvn ${MAVEN_CLI_OPTS} -pl db -am install
# Resolve dependencies for modules without dependencies to each other
RUN --mount=type=cache,target=/root/.m2/ \
2023-07-27 00:28:04 +02:00
mvn ${MAVEN_CLI_OPTS} dependency:go-offline
# Build modules
FROM db-build AS web-build
COPY web web
RUN --mount=type=cache,target=/root/.m2/ \
--mount=type=cache,target=/app/web/src/ui/dist/ \
--mount=type=cache,target=/app/web/src/ui/node/ \
--mount=type=cache,target=/app/web/src/ui/node_modules/ \
2023-07-27 00:28:04 +02:00
mvn ${MAVEN_CLI_OPTS} -pl web package
FROM db-build AS bot-build
COPY bot bot
RUN --mount=type=cache,target=/root/.m2/ \
2023-07-27 00:28:04 +02:00
mvn ${MAVEN_CLI_OPTS} -pl bot package
FROM db-build AS migration-build
COPY migration migration
RUN --mount=type=cache,target=/root/.m2/ \
2023-07-27 00:28:04 +02:00
mvn ${MAVEN_CLI_OPTS} -pl migration package
# Create final web
2023-11-23 20:07:26 +01:00
FROM docker.io/eclipse-temurin:21-jdk-jammy AS web
WORKDIR /app
COPY --from=web-build /app/web/target/web-*-fat.jar /app/web.jar
EXPOSE 8080
CMD ["java", "-jar", "/app/web.jar"]
# Create final migration
2023-11-23 20:07:26 +01:00
FROM docker.io/eclipse-temurin:21-jdk-jammy AS migration
WORKDIR /app
COPY --from=migration-build /app/migration/target/migration-*-fat.jar /app/migration.jar
CMD ["java", "-jar", "/app/migration.jar"]
# Create final bot
2023-11-23 20:07:26 +01:00
FROM docker.io/eclipse-temurin:21-jdk-jammy AS bot
WORKDIR /app
COPY --from=bot-build /app/bot/target/bot-*-fat.jar /app/bot.jar
CMD ["java", "-jar", "/app/bot.jar"]
# Build the ui
FROM docker.io/node:18-alpine AS ui-build
WORKDIR /ui
COPY ui/package.json ui/package-lock.json .
RUN npm ci
COPY ui .
RUN npm run build
# Create final ui
FROM docker.io/nginx AS ui
COPY --from=ui-build ui/dist /usr/share/nginx/html
# Create caddy reverse proxy
FROM docker.io/caddy AS caddy
RUN <<EOF cat > /etc/caddy/Caddyfile
2023-12-07 16:36:27 +01:00
{
debug
auto_https off
}
2023-12-08 20:06:28 +01:00
:8080 {
route {
reverse_proxy /api/* web:8080
reverse_proxy ui:80
}
2023-12-07 16:36:27 +01:00
}
EOF
EXPOSE 8080