From 8c4a434afd3e9c222f36ae5b33a785af8d6aa8fa Mon Sep 17 00:00:00 2001 From: Jimmy Date: Mon, 20 Sep 2021 21:40:53 +1200 Subject: [PATCH] Use multi stage build --- Dockerfile | 19 ++++++++++++++++--- build.sh | 4 ---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 004ad9c..e8ea85c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,29 @@ +FROM golang AS builder + +WORKDIR /app + +COPY ./src /app/src +COPY ./go.mod /app +COPY ./go.sum /app + +RUN go build -o /app/main /app/src/main.go +RUN go build -o /app/cmd /app/src/cmd.go + ARG JAVA_VERSION=16 -FROM openjdk:${JAVA_VERSION} +FROM openjdk:16 ENV MIN_MEM=512M ENV MAX_MEM=1G ENV STOP="stop" ENV JAR=server.jar -COPY ./bin/main /main -COPY ./bin/cmd /usr/local/bin/cmd +COPY --from=builder /app/main /main +COPY --from=builder /app/cmd /usr/local/bin/cmd EXPOSE 25565 VOLUME [ "/server" ] +WORKDIR /server + ENTRYPOINT [ "/main" ] diff --git a/build.sh b/build.sh index 5268abd..a8d7de8 100755 --- a/build.sh +++ b/build.sh @@ -1,6 +1,2 @@ #!/bin/sh - -mkdir -p bin && \ -go build -o bin/main src/main.go && \ -go build -o bin/cmd src/cmd.go && \ sudo docker build -t magmise/minecraft:latest .