docker-dontstarvetogether icon indicating copy to clipboard operation
docker-dontstarvetogether copied to clipboard

Build a modded image

Open meteorlxy opened this issue 6 years ago • 8 comments

Current version 0.8.0, we have to rebuild the whole image to enable some mods.

How about taking dstacademy/dontstarvetogether as the base image? So we can build our own modded images based on dstacademy/dontstarvetogether.

I have tried something like this but failed

FROM dstacademy/dontstarvetogether:latest

ARG MODS
ENV MODS ${MODS}

# Install mods.
RUN set -x \
  && echo $MODS \
	&& if [ -n "$MODS" ] ; then \
		   IFS="," \
		&& for mod in $MODSS; do echo "ServerModSetup(\"$mod\")" >> "$DST_HOME/mods/dedicated_server_mods_setup.lua"; done \
		&& cd "$DST_HOME/bin" \
		&& gosu $STEAM_USER ./dontstarve_dedicated_server_nullrenderer -only_update_server_mods \
		&& rm -r "$STEAM_HOME/.klei" \
	; fi

# Set up healthcheck.
HEALTHCHECK --start-period=15m --interval=5m --timeout=1m --retries=3 CMD dst-server version --check

# Set entrypoint and default command.
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["dst-server", "start"]

meteorlxy avatar Jan 17 '18 08:01 meteorlxy

I don't need to build all the image just to change the mods (using args). How are you building your images?

BraisGabin avatar Jan 17 '18 09:01 BraisGabin

According to the examples/mods, I change the MODS args and then run docker-compose build to build the image.

The base images dstacademy/steamcmd is small, but I have to build the 1.36G+ modded dst image myself.

meteorlxy avatar Jan 17 '18 12:01 meteorlxy

I believe this may be possible using ONBUILD instructions in the Dockerfile but we would have to implement it first, before someone can benefit from it.

thasmo avatar Jan 17 '18 22:01 thasmo

Yeah, ONBUILD may help. Or we can use another Dockerfile for modded image, which is based on dstacademy/dontstarvetogether

Looking forward to your implementation. Thx a lot

meteorlxy avatar Jan 18 '18 01:01 meteorlxy

Sorry, I didn't have time to check this before.

I pick the sample project with mods and I run docker-compose build. Then I changed the MODS ARG and runed docker-compose build again. And this is the output:

$ docker-compose build  
Building world
Step 1/27 : FROM dstacademy/steamcmd:0.3
 ---> b5e6b343f88b
Step 2/27 : MAINTAINER DST Academy <[email protected]>
 ---> Using cache
 ---> 82a49a7bb2db
Step 3/27 : RUN set -x 	&& dpkg --add-architecture i386 	&& apt-get update 	&& apt-get install -y --no-install-recommends 		lib32stdc++6 		libcurl4-gnutls-dev:i386 	&& apt-get clean 	&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
 ---> Using cache
 ---> fc690c0af328
Step 4/27 : ARG DST_HOME
 ---> Using cache
 ---> df3e7a4ba75e
Step 5/27 : ENV DST_HOME ${DST_HOME:-"/opt/dst"}
 ---> Using cache
 ---> 9b12ca98b48a
Step 6/27 : ARG DST_BRANCH
 ---> Using cache
 ---> 275c508ab050
Step 7/27 : ENV DST_BRANCH ${DST_BRANCH}
 ---> Using cache
 ---> a8e311602c3a
Step 8/27 : ARG DST_BRANCH_PASSWORD
 ---> Using cache
 ---> 56bcd14747bf
Step 9/27 : ENV DST_BRANCH_PASSWORD ${DST_BRANCH_PASSWORD}
 ---> Using cache
 ---> 296203d9f0ac
Step 10/27 : ARG DSTA_HOME
 ---> Using cache
 ---> 4ef62d9602a7
Step 11/27 : ENV DSTA_HOME ${DSTA_HOME:-"/usr/local/share/dsta"}
 ---> Using cache
 ---> c96477addae1
Step 12/27 : ARG CLUSTER_PATH
 ---> Using cache
 ---> ea0c5b4bd609
Step 13/27 : ENV CLUSTER_PATH ${CLUSTER_PATH:-"/var/lib/dsta/cluster"}
 ---> Using cache
 ---> b7ef2c67f224
Step 14/27 : ENV DESCRIPTION="Powered by DST Academy." 	SERVER_PORT="10999" 	SHARD_NAME=shard 	SHARD_BIND_IP="0.0.0.0" 	BACKUP_LOG_COUNT=0
 ---> Using cache
 ---> 01592c9c53c0
Step 15/27 : LABEL academy.dst.config.update="true"
 ---> Using cache
 ---> bea2c3d8ce18
Step 16/27 : RUN set -x 	&& mkdir -p $DST_HOME 	&& chown $STEAM_USER:$STEAM_USER $DST_HOME 	&& sync 	&& gosu $STEAM_USER steamcmd 		+@ShutdownOnFailedCommand 1 		+login anonymous 		+force_install_dir $DST_HOME 		+app_update 343050 			$([ -n "$DST_BRANCH" ] && printf %s "-beta $DST_BRANCH") 			$([ -n "$DST_BRANCH_PASSWORD" ] && printf %s "-betapassword $DST_BRANCH_PASSWORD") 			validate 		+quit 	&& rm -rf $STEAM_HOME/Steam/logs $STEAM_HOME/Steam/appcache/httpcache 	&& find $STEAM_HOME/package -type f ! -name "steam_cmd_linux.installed" ! -name "steam_cmd_linux.manifest" -delete
 ---> Using cache
 ---> 0ab727f4f36a
Step 17/27 : ARG MODS
 ---> Using cache
 ---> fb8f811687d6
Step 18/27 : ENV MODS ${MODS}
 ---> Running in 93c09413ac0b
Removing intermediate container 93c09413ac0b
 ---> 26044dfdf2f3
Step 19/27 : RUN set -x 	&& if [ -n "$MODS" ] ; then 		   IFS="," 		&& for mod in $MODS; do echo "ServerModSetup(\"$mod\")" >> "$DST_HOME/mods/dedicated_server_mods_setup.lua"; done 		&& cd "$DST_HOME/bin" 		&& gosu $STEAM_USER ./dontstarve_dedicated_server_nullrenderer -only_update_server_mods 		&& rm -r "$STEAM_HOME/.klei" 	; fi
 ---> Running in 2eafb3ab3887
+ [ -n 37816097,492173795,407705132 ]
+ IFS=,
+ echo ServerModSetup("37816097")
+ echo ServerModSetup("492173795")
+ echo ServerModSetup("407705132")
+ cd /opt/dst/bin
+ gosu steam ./dontstarve_dedicated_server_nullrenderer -only_update_server_mods
[00:00:00]: PersistRootStorage is now /opt/steam/.klei//DoNotStarveTogether/Cluster_1/Master/ 
[00:00:00]: Starting Up
[00:00:00]: Version: 251036
[00:00:00]: Current time: Sun Jan 21 14:07:42 2018
[...]

It didn't build all the image, it used the cache. It just build the last part (and that's the fast one).

Please, tell me if I'm missing something.

BraisGabin avatar Jan 21 '18 14:01 BraisGabin

@BraisGabin

But the first time you run docker-compose build, you don't have the cache.

For users who have pulled the dstacademy/dontstarvetogether image, they have to build a new one to get the cache.

meteorlxy avatar Jan 21 '18 19:01 meteorlxy

Oh, ok. I thought that you mean build the image each time you change a mod. Yeah, you must build the image once right now.

I don't see exactly how to use ONBUILD to fix this. I think that we need two images: the "vanilla" and the "modded". The modded will relay on the vanilla one, so you just need to build the modded one.

BraisGabin avatar Jan 21 '18 20:01 BraisGabin

That's it!

meteorlxy avatar Jan 22 '18 06:01 meteorlxy