dockerfile
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 7m24s

This commit is contained in:
Dmitri 2026-04-16 12:18:06 +02:00
parent 8f0bbe4e0b
commit 4b9ef4691e
Signed by: kanopo
GPG Key ID: 759ADD40E3132AC7
5 changed files with 90 additions and 69 deletions

8
.dockerignore Normal file
View File

@ -0,0 +1,8 @@
.git
.gitignore
target
.env
.data
compose.yaml
README.md
LICENSE

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
target/
.env
.data/

View File

@ -1,45 +1,22 @@
# ---- STAGE 1: Build ----
# Use an OpenJDK image that matches the version you develop with.
# It contains the JDK, but not Maven.
FROM eclipse-temurin:25-jdk-jammy AS builder
FROM rust:1.88-bookworm AS builder
# Set the working directory
WORKDIR /app
# ---- Caching Dependencies ----
# First, copy the files that define the build, including the Maven Wrapper
COPY mvnw .
COPY .mvn .mvn
COPY pom.xml .
# Make the wrapper executable
RUN chmod +x ./mvnw
# Run a Maven command to download dependencies.
# Since pom.xml and wrapper files rarely change, this layer will be cached by Docker,
# speeding up subsequent builds significantly.
RUN ./mvnw dependency:go-offline
# ---- Building the Application ----
# Now, copy the source code. If only source code changes, the layers above are cached.
COPY Cargo.toml Cargo.lock ./
COPY src ./src
# Build the application JAR using the Maven Wrapper
RUN ./mvnw clean package -DskipTests
RUN cargo build --release
FROM debian:bookworm-slim AS runtime
# ---- STAGE 2: Runtime ----
# Use a lean Eclipse Temurin JRE image for a small and secure final container.
FROM eclipse-temurin:25-jre-jammy
# Set the working directory
WORKDIR /app
# Copy only the built JAR file from the 'builder' stage
COPY --from=builder /app/target/*.jar app.jar
RUN apt-get update \
&& apt-get install -y --no-install-recommends ca-certificates \
&& rm -rf /var/lib/apt/lists/*
COPY --from=builder /app/target/release/rhythm_backend /app/rhythm_backend
# Expose the application port
EXPOSE 8080
# Command to run the application
ENTRYPOINT ["java", "-jar", "app.jar"]
ENTRYPOINT ["/app/rhythm_backend"]

36
compose.prod.yaml Normal file
View File

@ -0,0 +1,36 @@
services:
api-prod:
image: git.kanopo.dev/rhythm/rhythm-backend:latest
restart: unless-stopped
container_name: rhythm-api-prod
ports:
- "8080:8080"
environment:
DB_HOST: db-prod
env_file:
- ".env"
depends_on:
db-prod:
condition: service_healthy
profiles:
- prod
db-prod:
image: postgres:18.0-alpine
restart: unless-stopped
container_name: rhythm-db-prod
ports:
- "${DB_PORT_PROD:-5433}:5432"
environment:
POSTGRES_USER: ${DB_USERNAME}
POSTGRES_PASSWORD: ${DB_PASSWORD}
POSTGRES_DB: ${DB_NAME}
volumes:
- ./.data/postgres-prod:/var/lib/postgresql/data
profiles:
- prod
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${DB_USERNAME} -d ${DB_NAME}"]
interval: 5s
timeout: 3s
retries: 10

View File

@ -1,39 +1,39 @@
services:
# api-prod:
# build: .
# restart: unless-stopped
# container_name: qrcode-api
# ports:
# - "8080:8080"
# environment:
# DB_HOST: db-prod
# env_file:
# - ".env"
# depends_on:
# db-prod:
# condition: service_healthy
# profiles:
# - prod
#
# db-prod:
# image: postgres:18.0-alpine
# restart: unless-stopped
# container_name: qrcode-database-prod
# ports:
# - "${DB_PORT:-5432}:5432"
# environment:
# POSTGRES_USER: ${DB_USERNAME}
# POSTGRES_PASSWORD: ${DB_PASSWORD}
# POSTGRES_DB: ${DB_NAME}
# volumes:
# - postgres_data:/var/lib/postgresql/data
# profiles:
# - prod
# healthcheck:
# test: ["CMD-SHELL", "pg_isready -U ${DB_USERNAME} -d ${DB_NAME}"]
# interval: 5s
# timeout: 3s
# retries: 10
api-prod:
build: .
restart: unless-stopped
container_name: rhythm-api-prod
ports:
- "8080:8080"
environment:
DB_HOST: db-prod
env_file:
- ".env"
depends_on:
db-prod:
condition: service_healthy
profiles:
- prod
db-prod:
image: postgres:18.0-alpine
restart: unless-stopped
container_name: rhythm-db-prod
ports:
- "${DB_PORT_PROD:-5433}:5432"
environment:
POSTGRES_USER: ${DB_USERNAME}
POSTGRES_PASSWORD: ${DB_PASSWORD}
POSTGRES_DB: ${DB_NAME}
volumes:
- ./.data/postgres-prod:/var/lib/postgresql/data
profiles:
- prod
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${DB_USERNAME} -d ${DB_NAME}"]
interval: 5s
timeout: 3s
retries: 10
db-dev:
image: postgres:18.0-alpine
@ -55,4 +55,3 @@ services:
volumes:
postgres_data: