Skip to content

Commit

Permalink
Reduce docker container size (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
pilosus authored Oct 29, 2022
1 parent eb65ec8 commit 25ef671
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
## DB data ##
**/*.log
**/target/
db-data/
Dockerfile
.git
.gitignore
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ file. This change log follows the conventions of
[keepachangelog.com](http://keepachangelog.com/).

## [Unreleased]
### Changed
- Base docker images for production and testing moved to Linux
Alpine-based with Eclipse Temurin 17 JRE to reduce container size
([#63](https://github.com/pilosus/dienstplan/issues/63))

## [0.2.12] - 2022-05-21

Expand Down
43 changes: 35 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,47 @@
# syntax=docker/dockerfile:1
# multi-stage docker file, separate build and run steps

# Multi-stage docker file with separate build and run steps for image size optimisation
# https://docs.docker.com/develop/develop-images/multistage-build/
# Use Eclipse Temurin JDK/JRE as a vendor-agnostic, high-qulity solution
# with permissive FLOSS license
# https://whichjdk.com/#adoptium-eclipse-temurin

###################
### Build stage ###
###################

FROM clojure:temurin-17-lein-alpine@sha256:37968e7afb62937499c3773e9b713400da4abb358e6beb0ec9bae41a59715111 AS build

# build step
FROM clojure:openjdk-17-lein-bullseye
# Create a working directory
RUN mkdir -p /usr/src/app
COPY project.clj /usr/src/app/
WORKDIR /usr/src/app

# Install deps as a separate step for layer caching
COPY project.clj /usr/src/app/
RUN lein deps

# Compile uber-jar
COPY . /usr/src/app
RUN mv "$(lein uberjar | sed -n 's/^Created \(.*standalone\.jar\)/\1/p')" app.jar

# run step
FROM openjdk:17-slim-bullseye
#################
### Run stage ###
#################

FROM eclipse-temurin:17-jre-alpine@sha256:e1506ba20f0cb2af6f23e24c7f8855b417f0b085708acd9b85344a884ba77767 AS run

# Create app directory for unpriviledged user
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY --from=0 /usr/src/app/app.jar /usr/src/app/
COPY --from=0 /usr/src/app/resources /usr/src/app/resources

# Create unpriviledged system user
RUN adduser --disabled-password --no-create-home --uid 1000 dienstplan

# Copy uber-jar from the build stage
COPY --from=build /usr/src/app/app.jar /usr/src/app/
COPY --from=build /usr/src/app/resources /usr/src/app/resources
RUN chown -R 1000:1000 /usr/src/app

# Run as unpriviledged user
USER 1000
CMD ["java", "-jar", "app.jar"]
2 changes: 1 addition & 1 deletion Dockerfile-test
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM clojure:openjdk-17-lein-bullseye
FROM clojure:temurin-17-lein-alpine@sha256:37968e7afb62937499c3773e9b713400da4abb358e6beb0ec9bae41a59715111
RUN mkdir -p /usr/src/app
COPY project.clj /usr/src/app/
WORKDIR /usr/src/app
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# dienstplan

[![codecov](https://codecov.io/gh/pilosus/dienstplan/branch/main/graph/badge.svg?token=2ouqzEwhLc)](https://codecov.io/gh/pilosus/dienstplan)
[![Docker Image Version (latest semver)](https://img.shields.io/docker/v/pilosus/dienstplan?label=docker%20image&sort=semver)](https://hub.docker.com/r/pilosus/dienstplan)
[![Docker Image Version (latest semver)](https://img.shields.io/docker/v/pilosus/dienstplan?label=docker)](https://hub.docker.com/r/pilosus/dienstplan)
[![Hits-of-Code](https://hitsofcode.com/github/pilosus/dienstplan?branch=main)](https://hitsofcode.com/github/pilosus/dienstplan/view?branch=main)

Slack bot for duty rotations.
Expand Down Expand Up @@ -127,8 +127,8 @@ Commands:

### Server requirements

- Any server with Java 17 or higher (tested with OpenJDK 17)
- PostgreSQL 9.4 or higher (tested with PostgreSQL 13)
- Any server with Java 17 or higher (tested with [Eclipse Temurin 17.0.4.1](https://whichjdk.com/#adoptium-eclipse-temurin))
- PostgreSQL 9.4 to 14.5 (as of 2022-10-29 PostgreSQL 15 is not tested yet)
- (Optionally) [Sentry account](https://sentry.io/) for error tracking

### Environment variables
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3.9"
services:
postgres:
image: postgres:14-bullseye
image: postgres:14.5-alpine3.16@sha256:db802f226b620fc0b8adbeca7859eb203c8d3c9ce5d84870fadee05dea8f50ce
volumes:
- "/tmp/diestplan-db-data:/var/lib/postgresql/data"
env_file:
Expand Down
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject dienstplan "0.2.12"
(defproject dienstplan "0.3.0-SNAPSHOT"
:description "Duty rotation slack bot"
:url "https://github.com/pilosus/dienstplan"
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
Expand Down

0 comments on commit 25ef671

Please sign in to comment.