Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ jobs:
- name: Build and run tests
run: ./mvnw --batch-mode --no-transfer-progress verify

docker:
name: Backend Docker image (build)
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v7

# Makes sure the image used for deployment still builds (nothing is pushed).
- name: Build image
run: docker build --tag worklog-backend ./backend

frontend:
name: Frontend (build and tests)
runs-on: ubuntu-latest
Expand Down
22 changes: 22 additions & 0 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Build output and tooling
target/
.mvn/wrapper/maven-wrapper.jar

# Local config and secrets
.env
.env.*
application-dev.*
application-local.*

# Editors, VCS and docs
.git
.gitignore
.gitattributes
.idea/
.vscode/
*.iml
HELP.md

# Docker files themselves
Dockerfile
.dockerignore
32 changes: 32 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# syntax=docker/dockerfile:1

# ---- Build stage: compile and package the application ----
FROM eclipse-temurin:21-jdk AS build
WORKDIR /workspace

# Download dependencies first so Docker can cache this layer until the pom changes.
COPY .mvn .mvn
COPY mvnw pom.xml ./
RUN chmod +x mvnw && ./mvnw --batch-mode --no-transfer-progress dependency:go-offline

COPY src src
RUN ./mvnw --batch-mode --no-transfer-progress package -Dmaven.test.skip=true \
&& mv target/backend-*.jar target/app.jar

# ---- Runtime stage: small JRE image, runs as a non-root user ----
FROM eclipse-temurin:21-jre-alpine
RUN addgroup -S app && adduser -S app -G app
USER app
WORKDIR /app

COPY --from=build /workspace/target/app.jar app.jar

# Platforms like Render set PORT; the application reads it (server.port=${PORT:8080}).
ENV PORT=8080
EXPOSE 8080

HEALTHCHECK --interval=30s --timeout=5s --start-period=60s --retries=3 \
CMD wget -q -O /dev/null "http://localhost:${PORT}/health" || exit 1

# Use at most 75% of the container memory for the heap (the free tiers are small).
ENTRYPOINT ["java", "-XX:MaxRAMPercentage=75", "-jar", "app.jar"]
50 changes: 50 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Local development helpers.
#
# docker compose up -d -> PostgreSQL only (run backend and frontend on your machine)
# docker compose --profile full up -d --build -> PostgreSQL + backend in containers
# docker compose down -> stop (data is kept); add -v to delete the data too
#
# Credentials below are for local development only.

name: worklog

services:
postgres:
image: postgres:16
container_name: worklog-postgres
restart: unless-stopped
environment:
POSTGRES_DB: worklog
POSTGRES_USER: worklog
POSTGRES_PASSWORD: worklog_dev_password
ports:
# 5433 on the host avoids a clash with a PostgreSQL installed on your machine (usually 5432).
- "${DB_PORT:-5433}:5432"
volumes:
- worklog-postgres-data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U worklog -d worklog"]
interval: 5s
timeout: 5s
retries: 5

backend:
profiles: ["full"]
build:
context: ./backend
dockerfile: Dockerfile
container_name: worklog-backend
restart: unless-stopped
depends_on:
postgres:
condition: service_healthy
environment:
DB_URL: jdbc:postgresql://postgres:5432/worklog
DB_USER: worklog
DB_PASSWORD: worklog_dev_password
CORS_ORIGINS: http://localhost:4200
ports:
- "${BACKEND_PORT:-8080}:8080"

volumes:
worklog-postgres-data: