-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
56 lines (38 loc) · 2.05 KB
/
Copy pathDockerfile
File metadata and controls
56 lines (38 loc) · 2.05 KB
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
# First stage: download the Java dependencies and build
#==================================================================================================
FROM maven:3.8.3-adoptopenjdk-11 AS builder
# Copy in Maven settings templates and credentials
COPY docker/credentials /root/credentials
COPY docker/.m2 /root/.m2
# Populate settings templates with credentials
WORKDIR /root/.m2
# (Note that | rather than / is used as the sed delimiter, since encrypted passwords can contain the former, but not the latter
RUN sed -i "s|MASTER_PASSWORD|$(mvn --encrypt-master-password master_password)|" settings-security.xml
RUN sed -i "s|REPO_USERNAME|$(cat ../credentials/repo_username.txt)|;s|REPO_PASSWORD|$(cat ../credentials/repo_password.txt|xargs mvn --encrypt-password)|" settings.xml
# Copy in Java source and build
WORKDIR /root/code
# Copy just the pom.xml file
COPY pom.xml ./pom.xml
# Retrieve all of the dependencies
RUN --mount=type=cache,id=stack-mvn,target=/root/.m2/repository,sharing=locked mvn clean dependency:resolve --update-snapshots
# Copy in the code
COPY src ./src/
# Ensure that the latest versions of SNAPSHOT dependencies are always used
ARG CACHEBUST=1
RUN --mount=type=cache,id=stack-mvn,target=/root/.m2/repository,sharing=locked mvn package --update-snapshots
FROM builder AS test
RUN --mount=type=cache,id=stack-mvn,target=/root/.m2/repository2,sharing=locked mkdir -p /root/.m2/repository && cp -r /root/.m2/repository2/* /root/.m2/repository
CMD ["mvn", "test"]
#==================================================================================================
# Second stage: copy the output into a clean image
#==================================================================================================
FROM adoptopenjdk/openjdk11:jre-11.0.13_8 AS agent
# Copy in the entrypoint script
COPY docker/entrypoint.sh /entrypoint.sh
WORKDIR /app
# Copy the downloaded dependencies from the builder
COPY --from=builder /root/code/target/lib /app/lib
# Port for Java debugging
EXPOSE 5005
# Run the entrypoint script
ENTRYPOINT ["/entrypoint.sh"]