From 24e349f3a8b94bd982470fce40f6a7cd132f71b8 Mon Sep 17 00:00:00 2001 From: Joe Taber Date: Tue, 5 May 2020 17:37:53 -0500 Subject: [PATCH] Simplify docker build. Just `docker build .` Some differences: * No dependencies besides docker required, including java, maven, etc. (Nice for CI) * Use docker layer cache to avoid downloading dependencies every build * Redownload all dependencies based on when pom.xml is changed Also substitute deprecated "MAINTAINER" step in favor of "LABEL". --- docker/Docker.md => Docker.md | 0 Dockerfile | 27 +++++++++++++++++++++++++++ Makefile | 7 +------ docker/bootstrap.sh => bootstrap.sh | 0 docker/Dockerfile | 13 ------------- 5 files changed, 28 insertions(+), 19 deletions(-) rename docker/Docker.md => Docker.md (100%) create mode 100644 Dockerfile rename docker/bootstrap.sh => bootstrap.sh (100%) mode change 100755 => 100644 delete mode 100644 docker/Dockerfile diff --git a/docker/Docker.md b/Docker.md similarity index 100% rename from docker/Docker.md rename to Docker.md diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4179c7f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +FROM maven:3-jdk-8 as build +WORKDIR /app + +COPY pom.xml . + +# Run maven build & remove artifacts to cache downloaded dependencies until pom.xml changes +RUN mvn clean package -Dmaven.main.skip -Dmaven.test.skip && rm -r target + +# Copy all files with extensions (i.e. skip Dockerfile, Makefile) +COPY *.* ./ + +# Build for real +RUN mvn clean package -Dmaven.test.skip + +FROM java:8 + +LABEL maintainer="Miguel Garcia Puyol " + +WORKDIR /var/app + +COPY --from=build /app/target/zkui-*-jar-with-dependencies.jar /var/app/zkui.jar +ADD config.cfg /var/app/config.cfg +ADD bootstrap.sh /var/app/bootstrap.sh + +ENTRYPOINT ["/var/app/bootstrap.sh"] + +EXPOSE 9090 diff --git a/Makefile b/Makefile index 1f1abee..9520b57 100644 --- a/Makefile +++ b/Makefile @@ -6,12 +6,7 @@ VERSION=2.0-SNAPSHOT all: build publish build: - mvn clean install - cp config.cfg docker - cp target/$(NAME)-*-jar-with-dependencies.jar docker - docker build -t $(NAME):$(VERSION) --no-cache --rm docker - rm docker/$(NAME)-*.jar - rm docker/config.cfg + docker build -t $(NAME):$(VERSION) . publish: docker tag $(NAME):$(VERSION) $(NAME):$(VERSION) diff --git a/docker/bootstrap.sh b/bootstrap.sh old mode 100755 new mode 100644 similarity index 100% rename from docker/bootstrap.sh rename to bootstrap.sh diff --git a/docker/Dockerfile b/docker/Dockerfile deleted file mode 100644 index eaea6f4..0000000 --- a/docker/Dockerfile +++ /dev/null @@ -1,13 +0,0 @@ -FROM java:8 - -MAINTAINER Miguel Garcia Puyol - -WORKDIR /var/app - -ADD zkui-*.jar /var/app/zkui.jar -ADD config.cfg /var/app/config.cfg -ADD bootstrap.sh /var/app/bootstrap.sh - -ENTRYPOINT ["/var/app/bootstrap.sh"] - -EXPOSE 9090