From d98ab8cf1e23dc4fe1578622a1298eddb0b9fe33 Mon Sep 17 00:00:00 2001 From: James McDowell Date: Sun, 16 May 2021 09:11:11 +1000 Subject: [PATCH 1/3] Updated dockerignore to prevent the generated database files from being sent to the build context. This was causing an error connected to the docker daemon when issuing `docker-compose up --build`, possibly due to the size or number of files in that folder causing an overflow of sorts --- .dockerignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.dockerignore b/.dockerignore index 3fbb8c079e..79289b3acd 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,5 @@ /docs /handbook -/tools \ No newline at end of file +/tools +/docker-db-data +/.idea \ No newline at end of file From 8429d78e016d7cfe68848b85fde15451a1ca2fd8 Mon Sep 17 00:00:00 2001 From: James McDowell Date: Sun, 16 May 2021 09:59:12 +1000 Subject: [PATCH 2/3] 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. --- .dockerignore | 18 +++++++++++++----- Dockerfile | 38 +++++++++++++++++++++++++++++--------- docker-compose.yml | 10 ++++++++++ 3 files changed, 52 insertions(+), 14 deletions(-) diff --git a/.dockerignore b/.dockerignore index 79289b3acd..389407f6ea 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,5 +1,13 @@ -/docs -/handbook -/tools -/docker-db-data -/.idea \ No newline at end of file +# Project administration files +.idea +.git +.github + +# 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 diff --git a/Dockerfile b/Dockerfile index b24fea224d..21eaab8819 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,40 @@ # 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 -COPY src /home/app/src -COPY pom.xml /home/app -RUN mvn -f /home/app/pom.xml clean package +FROM maven:3.6.3-jdk-8 AS jar + +# Build in a separated location which won't have permissions issues. +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 -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 -ENTRYPOINT ["java", "-jar", "/usr/local/lib/Cosmic.jar"] +ENTRYPOINT ["java", "-jar", "./Server.jar"] diff --git a/docker-compose.yml b/docker-compose.yml index fc7334dedd..449b5039da 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,8 +5,18 @@ services: depends_on: - db ports: + # Login server - "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" + 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: DB_HOST: "db" From f47b38f65d8d13806d1afd00efafb39cb2f55b94 Mon Sep 17 00:00:00 2001 From: James McDowell <23255412+wejrox@users.noreply.github.com> Date: Sun, 16 May 2021 14:32:27 +1000 Subject: [PATCH 3/3] Skip tests and run compile in parallel for speed --- Dockerfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 21eaab8819..37701dfc68 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,10 +11,12 @@ 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 +# Skip compiling tests since we don't want all the dependecies to be downloaded. +RUN mvn -f ./pom.xml clean dependency:go-offline -Dmaven.test.skip -T 1C # Source code changes may not change dependencies, so it can go last. +# Skip compiling tests since we don't want all the dependecies to be downloaded for plugins. COPY src ./src -RUN mvn -f ./pom.xml clean package +RUN mvn -f ./pom.xml clean package -Dmaven.test.skip -T 1C # # Server creation stage