summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2020-07-19 16:37:49 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2020-08-24 19:48:10 +0200
commit8ecb607dc6b54ff7a37fc0fea4f1a896dc5e7015 (patch)
tree565f2635a5a42f919177fbf6239b3d3dfb56701b
parent55c7dd85f2cf215c302c4bb9f21a15d9dc2b489d (diff)
Cache build artifacts for Docker build
-rw-r--r--simulator/.dockerignore9
-rw-r--r--simulator/.gitignore2
-rw-r--r--simulator/Dockerfile34
3 files changed, 32 insertions, 13 deletions
diff --git a/simulator/.dockerignore b/simulator/.dockerignore
index bcbdf2b0..816d338c 100644
--- a/simulator/.dockerignore
+++ b/simulator/.dockerignore
@@ -1,11 +1,10 @@
-# IntelliJ
-/out/
+.git
+
.idea/
-*/out
+**/out
*.iml
.idea_modules/
-### Gradle
.gradle
-build/
+**/build/
diff --git a/simulator/.gitignore b/simulator/.gitignore
index 4ec6f778..917f2e6a 100644
--- a/simulator/.gitignore
+++ b/simulator/.gitignore
@@ -38,7 +38,7 @@ data/
# IntelliJ
/out/
.idea/
-*/out
+**/out
*.iml
# mpeltonen/sbt-idea plugin
diff --git a/simulator/Dockerfile b/simulator/Dockerfile
index 852809b3..e42c7f14 100644
--- a/simulator/Dockerfile
+++ b/simulator/Dockerfile
@@ -1,11 +1,31 @@
-FROM gradle:jdk14
+FROM openjdk:14-slim AS staging
MAINTAINER OpenDC Maintainers <opendc@atlarge-research.com>
-COPY ./ /simulator
-RUN cd /simulator/ \
- && gradle --no-daemon :opendc:opendc-runner-web:installDist
+# Build staging artifacts for dependency caching
+COPY ./ /app
+WORKDIR /app
+RUN mkdir /staging \
+ && cp -r buildSrc/ /staging \
+ && cp gradle.properties /staging 2>/dev/null | true \
+ && find -name "*.gradle.kts" | xargs cp --parents -t /staging
-FROM openjdk:14
-COPY --from=0 /simulator/opendc/opendc-runner-web/build/install /simulator
-WORKDIR /simulator
+FROM openjdk:14-slim AS builder
+
+# Obtain (cache) Gradle wrapper
+COPY gradlew /app/
+COPY gradle /app/gradle
+WORKDIR /app
+RUN ./gradlew --version
+
+# Install (cache) project dependencies only
+COPY --from=staging /staging/ /app/
+RUN ./gradlew clean build --no-daemon > /dev/null 2>&1 || true
+
+# Build project
+COPY ./ /app/
+RUN ./gradlew --no-daemon :opendc:opendc-runner-web:installDist
+
+FROM openjdk:14-slim
+COPY --from=builder /app/opendc/opendc-runner-web/build/install /app
+WORKDIR /app
CMD opendc-runner-web/bin/opendc-runner-web