Optimised multi layered builds to speed up deployment, added comments to help new developers, reduced unnecessary objects being sent to the docker build context, mounted in files that may change regularly to remove the requirement for a full rebuild.

This commit is contained in:
James McDowell
2021-05-16 09:59:12 +10:00
parent d98ab8cf1e
commit 8429d78e01
3 changed files with 52 additions and 14 deletions

View File

@@ -1,5 +1,13 @@
/docs # Project administration files
/handbook .idea
/tools .git
/docker-db-data .github
/.idea
# Not used by the build.
docs
handbook
sql
tools
# Created by the db when using docker-compose, large and causes rebuild issues if sent to the context.
docker-db-data

View File

@@ -1,20 +1,40 @@
# Initial Docker support thanks to xinyifly # Initial Docker support thanks to xinyifly
# Optimisation performed by wejrox
# #
# Build stage # Cosmic JAR creation stage
# #
FROM maven:3.6.3-jdk-8 AS build FROM maven:3.6.3-jdk-8 AS jar
COPY src /home/app/src
COPY pom.xml /home/app # Build in a separated location which won't have permissions issues.
RUN mvn -f /home/app/pom.xml clean package WORKDIR /opt/cosmic
# Any changes to the pom will affect the entire build, so it should be copied first.
COPY pom.xml ./pom.xml
# Grab all the dependencies listed in the pom early, since it prevents changes to source code from requiring a complete re-download.
RUN mvn -f ./pom.xml clean dependency:go-offline
# Source code changes may not change dependencies, so it can go last.
COPY src ./src
RUN mvn -f ./pom.xml clean package
# #
# Package stage # Server creation stage
# #
FROM openjdk:8 FROM openjdk:8
COPY --from=build /home/app/target/Cosmic.jar /usr/local/lib/Cosmic.jar
COPY ./ ./ # Host the server in a location that won't have permissions issues.
WORKDIR /opt/server
# Copy the wizet files first since they're so big and won't change often.
COPY wz ./wz
# Copy the JAR we build earlier.
COPY --from=jar /opt/cosmic/target/Cosmic.jar ./Server.jar
# Scripts are sourced on server startup, so you can mount over them for quicker redeploy.
COPY scripts ./scripts/
# Config is read on server startup, so you can mount over it for quicker redeploy.
COPY config.yaml ./
# Default exposure, although not required if using docker compose.
# This exposes the login server, and channels.
# Format for channels: WWCC, where WW is 75 plus the world number and CC is 75 plus the channel number (both zero indexed).
EXPOSE 8484 7575 7576 7577 EXPOSE 8484 7575 7576 7577
ENTRYPOINT ["java", "-jar", "/usr/local/lib/Cosmic.jar"] ENTRYPOINT ["java", "-jar", "./Server.jar"]

View File

@@ -5,8 +5,18 @@ services:
depends_on: depends_on:
- db - db
ports: ports:
# Login server
- "8484:8484" - "8484:8484"
# Channels.
# Format: WWCC, where WW is 75 plus the world number and CC is 75 plus the channel number (both zero indexed).
# In this case, world 1 channels 1-3.
- "7575-7577:7575-7577" - "7575-7577:7575-7577"
volumes:
# Config changes can be reloaded without rebuilding the image.
# Still requires a redeployment as they're sourced on startup.
- ./config.yaml:/opt/server/config.yaml
- ./scripts:/opt/server/scripts
- ./wz:/opt/server/wz
environment: environment:
DB_HOST: "db" DB_HOST: "db"