Skip to content

Commit 0794fb8

Browse files
NicolasDorierdpad85
authored andcommitted
Docker support with repeatable build (#255)
Dependency to `git` has been removed, we now use `notag` when building without a git directory. In order to reliably fetch all dependencies, we do a first blank build (with no source files), then we copy the sources and do a real commit. This is a simpler and more robust approach. Also, fixed the .dockerignore to filter out IDE files.
1 parent 5f6987b commit 0794fb8

File tree

6 files changed

+73
-33
lines changed

6 files changed

+73
-33
lines changed

.dockerignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Dockerfile
2+
.dockerignore
3+
.git
4+
**/*.idea
5+
**/*.iml
6+
**/target

Dockerfile

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
FROM openjdk:8u121-jdk-alpine as BUILD
2+
3+
# Setup maven, we don't use https://hub.docker.com/_/maven/ as it declare .m2 as volume, we loose all mvn cache
4+
# We can alternatively do as proposed by https://github.com/carlossg/docker-maven#packaging-a-local-repository-with-the-image
5+
# this was meant to make the image smaller, but we use multi-stage build so we don't care
6+
7+
RUN apk add --no-cache curl tar bash
8+
9+
ARG MAVEN_VERSION=3.5.2
10+
ARG USER_HOME_DIR="/root"
11+
ARG SHA=707b1f6e390a65bde4af4cdaf2a24d45fc19a6ded00fff02e91626e3e42ceaff
12+
ARG BASE_URL=https://apache.osuosl.org/maven/maven-3/${MAVEN_VERSION}/binaries
13+
14+
RUN mkdir -p /usr/share/maven /usr/share/maven/ref \
15+
&& curl -fsSL -o /tmp/apache-maven.tar.gz ${BASE_URL}/apache-maven-${MAVEN_VERSION}-bin.tar.gz \
16+
&& echo "${SHA} /tmp/apache-maven.tar.gz" | sha256sum -c - \
17+
&& tar -xzf /tmp/apache-maven.tar.gz -C /usr/share/maven --strip-components=1 \
18+
&& rm -f /tmp/apache-maven.tar.gz \
19+
&& ln -s /usr/share/maven/bin/mvn /usr/bin/mvn
20+
21+
ENV MAVEN_HOME /usr/share/maven
22+
ENV MAVEN_CONFIG "$USER_HOME_DIR/.m2"
23+
24+
# Let's fetch eclair dependencies, so that Docker can cache them
25+
# This way we won't have to fetch dependencies again if only the source code changes
26+
# The easiest way to reliably get dependencies is to build the project with no sources
27+
WORKDIR /usr/src
28+
COPY pom.xml pom.xml
29+
COPY eclair-core/pom.xml eclair-core/pom.xml
30+
COPY eclair-node/pom.xml eclair-node/pom.xml
31+
COPY eclair-node-gui/pom.xml eclair-node-gui/pom.xml
32+
RUN mkdir -p eclair-core/src/main/scala && touch eclair-core/src/main/scala/empty.scala
33+
# Blank build. We only care about eclair-node, and we use install because eclair-node depends on eclair-core
34+
RUN mvn install -pl eclair-node -am clean
35+
36+
# Only then do we copy the sources
37+
COPY . .
38+
39+
# And this time we can build in offline mode
40+
RUN mvn package -pl eclair-node -am -DskipTests -o
41+
# It might be good idea to run the tests here, so that the docker build fail if the code is bugged
42+
43+
# We currently use a debian image for runtime because of some jni-related issue with sqlite
44+
FROM openjdk:8u151-jre-slim
45+
WORKDIR /app
46+
# Eclair only needs the eclair-node-*.jar to run
47+
COPY --from=BUILD /usr/src/eclair-node/target/eclair-node-*.jar .
48+
RUN ln `ls` eclair-node
49+
ENTRYPOINT [ "java", "-jar", "eclair-node" ]

eclair-core/pom.xml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,6 @@
1515

1616
<build>
1717
<plugins>
18-
<plugin>
19-
<groupId>pl.project13.maven</groupId>
20-
<artifactId>git-commit-id-plugin</artifactId>
21-
<executions>
22-
<execution>
23-
<goals>
24-
<goal>revision</goal>
25-
</goals>
26-
</execution>
27-
</executions>
28-
</plugin>
2918
<plugin>
3019
<groupId>com.googlecode.maven-download-plugin</groupId>
3120
<artifactId>download-maven-plugin</artifactId>

eclair-node-gui/pom.xml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,6 @@
1515

1616
<build>
1717
<plugins>
18-
<plugin>
19-
<groupId>pl.project13.maven</groupId>
20-
<artifactId>git-commit-id-plugin</artifactId>
21-
<executions>
22-
<execution>
23-
<goals>
24-
<goal>revision</goal>
25-
</goals>
26-
</execution>
27-
</executions>
28-
</plugin>
2918
<plugin>
3019
<groupId>org.apache.maven.plugins</groupId>
3120
<artifactId>maven-jar-plugin</artifactId>

eclair-node/pom.xml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,6 @@
1515

1616
<build>
1717
<plugins>
18-
<plugin>
19-
<groupId>pl.project13.maven</groupId>
20-
<artifactId>git-commit-id-plugin</artifactId>
21-
<executions>
22-
<execution>
23-
<goals>
24-
<goal>revision</goal>
25-
</goals>
26-
</execution>
27-
</executions>
28-
</plugin>
2918
<plugin>
3019
<groupId>org.apache.maven.plugins</groupId>
3120
<artifactId>maven-jar-plugin</artifactId>

pom.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
4848
<maven.compiler.source>1.8</maven.compiler.source>
4949
<maven.compiler.target>1.8</maven.compiler.target>
50+
<!-- default tag used when building without git -->
51+
<git.commit.id>notag</git.commit.id>
52+
<git.commit.id.abbrev>notag</git.commit.id.abbrev>
5053
<scala.version>2.11.11</scala.version>
5154
<scala.version.short>2.11</scala.version.short>
5255
<akka.version>2.4.18</akka.version>
@@ -85,6 +88,21 @@
8588
<artifactId>versions-maven-plugin</artifactId>
8689
<version>2.3</version>
8790
</plugin>
91+
<plugin>
92+
<groupId>pl.project13.maven</groupId>
93+
<artifactId>git-commit-id-plugin</artifactId>
94+
<version>2.2.2</version>
95+
<executions>
96+
<execution>
97+
<goals>
98+
<goal>revision</goal>
99+
</goals>
100+
<configuration>
101+
<failOnNoGitDirectory>false</failOnNoGitDirectory>
102+
</configuration>
103+
</execution>
104+
</executions>
105+
</plugin>
88106
<plugin>
89107
<groupId>net.alchim31.maven</groupId>
90108
<artifactId>scala-maven-plugin</artifactId>

0 commit comments

Comments
 (0)