-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
129 lines (95 loc) · 4 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# ------------------------------------------
# Build and run Practicalli Clojure Service
#
# Author: Practicalli
#
# Builder image:
# Official Clojure Docker image with Java 17 (eclipse-temurin) and Clojure CLI
# https://hub.docker.com/_/clojure/
#
# Run-time image:
# Official Java Docker image with Java 17 (eclipse-temurin)
# https://hub.docker.com/_/eclipse-temurin
# ------------------------------------------
# ------------------------
# Setup Builder container
FROM clojure:temurin-17-alpine AS builder
# Set Clojure CLI version (defaults to latest release)
# ENV CLOJURE_VERSION=1.11.1.1155
# Create directory for project code (working directory)
RUN mkdir -p /build
# Set Docker working directory
WORKDIR /build
# Cache and install Clojure dependencies
# Add before copying code to cache the layer even if code changes
COPY deps.edn Makefile /build/
RUN make deps
# Copy project to working directory
# .dockerignore file excludes all but essential files
COPY ./ /build
# ------------------------
# Test and Package application via Makefile
# `make all` calls `deps`, `test-ci`, `dist` and `clean` tasks
# using shared library cache mounted by pipeline process
# `dist` task packages Clojure service as an uberjar
# - creates: /build/practicalli-gameboard-api-service.jar
# - uses command `clojure -T:build uberjar`
RUN make dist
# End of Docker builder image
# ------------------------------------------
# ------------------------------------------
# Docker container to run Practicalli Gameboard API Service
# run locally using: docker-compose up --build
# ------------------------
# Setup Run-time Container
# Official OpenJDK Image
FROM eclipse-temurin:17-alpine
# Example labels for runtime docker image
# LABEL org.opencontainers.image.authors="nospam+dockerfile@practical.li"
# LABEL io.github.practicalli.clojure.service="Practicalli Clojure service"
# LABEL io.github.practicalli.team="Practicalli Engineering Team"
# LABEL version="2023.04.13"
# LABEL description="Production Grade Clojure service"
# Add operating system packages
# - dumb-init to ensure SIGTERM sent to java process running Clojure service
# - Curl and jq binaries for manual running of system integration scripts
# check for newer package versions: https://pkgs.alpinelinux.org/
RUN apk add --no-cache \
dumb-init~=1.2.5 \
curl~=8.0.1 \
jq~=1.6
# Create Non-root group and user to run service securely
RUN addgroup -S clojure && adduser -S clojure -G clojure
# Create directory to contain service archive, owned by non-root user
RUN mkdir -p /service && chown -R clojure. /service
# Tell docker that all future commands should run as the appuser user
USER clojure
# Copy service archive file from Builder image
WORKDIR /service
COPY --from=builder /build/target/practicalli-clojure-webapp-standalone.jar /service/
# Optional: Add System Integration testing scripts
# RUN mkdir -p /service/test-scripts
# COPY --from=builder /build/test-scripts/curl--* /service/test-scripts/
# ------------------------
# Set Service Environment variables
# optional over-rides for Integrant configuration
# ENV HTTP_SERVER_PORT=
# ENV MYSQL_DATABASE=
ENV SERVICE_PROFILE=prod
# Expose port of HTTP Server
EXPOSE 8080
# ------------------------
# Run service
# JDK_JAVA_OPTIONS environment variable for setting JVM options
# Use JVM options that optomise running in a container
# For very low latency, use the Z Garbage collector "-XX:+UseZGC"
ENV JDK_JAVA_OPTIONS "-XshowSettings:system -XX:+UseContainerSupport -XX:MaxRAMPercentage=90"
# Start service using dumb-init and java run-time
# (overrides `jshell` entrypoint - default in eclipse-temuring image)
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
CMD ["java", "-jar", "/service/practicalli-clojure-webapp-standalone.jar"]
# Docker Entrypoint documentation
# https://docs.docker.com/engine/reference/builder/#entrypoint
# $kill PID For Graceful Shutdown(SIGTERM) - can be caught for graceful shutdown
# $kill -9 PID For Forceful Shutdown(SIGKILL) - process ends immeciately
# SIGSTOP cannot be intercepted, process ends immediately