-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Dockerfile
47 lines (35 loc) · 1.27 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
# syntax=docker/dockerfile:1
# 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 AS build
# Create a working directory
RUN mkdir -p /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 stage ###
#################
FROM eclipse-temurin:17-jre-alpine AS run
# Create app directory for unpriviledged user
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# Create unpriviledged system user
RUN adduser --disabled-password --no-create-home --uid 1000 unpriv
# 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"]