Use multi stage build

This commit is contained in:
Jimmy 2021-09-20 21:40:53 +12:00
parent 082084dd13
commit 8c4a434afd
2 changed files with 16 additions and 7 deletions

View File

@ -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 ARG JAVA_VERSION=16
FROM openjdk:${JAVA_VERSION} FROM openjdk:16
ENV MIN_MEM=512M ENV MIN_MEM=512M
ENV MAX_MEM=1G ENV MAX_MEM=1G
ENV STOP="stop" ENV STOP="stop"
ENV JAR=server.jar ENV JAR=server.jar
COPY ./bin/main /main COPY --from=builder /app/main /main
COPY ./bin/cmd /usr/local/bin/cmd COPY --from=builder /app/cmd /usr/local/bin/cmd
EXPOSE 25565 EXPOSE 25565
VOLUME [ "/server" ] VOLUME [ "/server" ]
WORKDIR /server
ENTRYPOINT [ "/main" ] ENTRYPOINT [ "/main" ]

View File

@ -1,6 +1,2 @@
#!/bin/sh #!/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 . sudo docker build -t magmise/minecraft:latest .