Skip to content

Commit

Permalink
Docker Deployment toolchain updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Firartix authored and Nanu308 committed Nov 13, 2021
1 parent 36793ba commit 68c2751
Show file tree
Hide file tree
Showing 10 changed files with 206 additions and 21 deletions.
28 changes: 18 additions & 10 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
*
!**/*.so
!**/*.dll
!*.rsc
!*.dmb
!maps/*
!config/*
!tools/*
!map_config/*
!nano/*
/.git
/*.txt
/tmp
/data
/cfg
/scripts
/.gitlab
/.vscode
/.gitlab-ci.yml
/tools/dmitool
/tools/runtimes
/local.db*
*.dll
*.exe
*.bat
*.rsc.dyn
*.log
*.lk
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ html/changelog.html merge=union
*.dm text eol=lf
*.dmm text eol=lf
*.dme text eol=lf
*.yml text eol=lf
*.sh text eol=lf
Dockerfile eol=lf
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Thumbs.db
*.db-wal
data/
cfg/
!cfg/.keep
tmp/
dmdoc/
tools/Runtime Condenser/Input.txt
Expand Down
92 changes: 84 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
ARG BYOND_BASE_IMAGE=i386/ubuntu:bionic
# TODO: Replace 80% of that cache handling with juke tasks
# so contributors can have reproducible test builds without needing docker...
# Also will allow to properly handle building game in map checking mode

FROM ${BYOND_BASE_IMAGE} AS byond
RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y make man curl unzip libssl-dev
ARG BYOND_BASE_IMAGE=i386/ubuntu:bionic
ARG BYOND_MAJOR=513
ARG BYOND_MINOR=1542
ARG NODE_VERSION=15
ARG PYTHON_VERSION=3.7

# Base BYOND image
FROM --platform=linux/386 ${BYOND_BASE_IMAGE} AS byond
SHELL ["/bin/bash", "-c"]
RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y make man curl unzip libssl-dev
ARG BYOND_MAJOR
ARG BYOND_MINOR
ARG BYOND_DOWNLOAD_URL=https://secure.byond.com/download/build/${BYOND_MAJOR}/${BYOND_MAJOR}.${BYOND_MINOR}_byond_linux.zip
RUN curl ${BYOND_DOWNLOAD_URL} -o byond.zip \
&& unzip byond.zip \
Expand All @@ -12,18 +22,84 @@ WORKDIR /byond
RUN make here
RUN DEBIAN_FRONTEND=noninteractive apt-get clean && rm -rf /var/lib/apt/lists/*

# Legacy GitLab CI packaging container, using pre-built game in pipeline
FROM byond AS cm-runner
ENV DREAMDAEMON_PORT=1400
RUN mkdir -p /cm/data
WORKDIR /cm
COPY map_config map_config
COPY maps maps
COPY nano nano
ARG RUSTG_LIBRARY_FILE=librust_g.so
ADD ${RUSTG_LIBRARY_FILE} librust_g.so
COPY librust_g.so .
COPY tools/runner-entrypoint.sh /entrypoint.sh
RUN chmod u+x /entrypoint.sh
ARG DM_PROJECT_NAME=ColonialMarinesALPHA
COPY ${DM_PROJECT_NAME}.dmb application.dmb
COPY ${DM_PROJECT_NAME}.rsc application.rsc
COPY ColonialMarinesALPHA.dmb application.dmb
COPY ColonialMarinesALPHA.rsc application.rsc
ENTRYPOINT ["/entrypoint.sh"]

# Image used for building the game with DreamMaker
FROM byond AS cm-builder
ARG DM_PROJECT_NAME
ARG PYTHON_VERSION
RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y python${PYTHON_VERSION} python3-pip
RUN pip3 install python-dateutil requests beautifulsoup4 pyyaml
RUN DEBIAN_FRONTEND=noninteractive apt-get clean && rm -rf /var/lib/apt/lists/*

# TGUI deps prep (cache stage - keep only base structure)
FROM node:${NODE_VERSION}-buster AS tgui-thin
WORKDIR /tgui
COPY tgui .
RUN rm -rf docs public
RUN find packages \! -name "package.json" -mindepth 2 -maxdepth 2 -print | xargs rm -rf

# TGUI deps fetch (cache stage - keep deps as standalone layer)
FROM node:${NODE_VERSION}-buster AS tgui-deps
COPY --from=tgui-thin tgui /tgui
WORKDIR /tgui
RUN chmod u+x bin/tgui && bin/tgui --deps-only

# TGUI builder
FROM node:${NODE_VERSION}-buster AS tgui-build
WORKDIR /tgui
COPY --from=tgui-deps /tgui/.yarn/cache .yarn/cache
COPY tgui .
RUN chmod u+x bin/tgui && bin/tgui --deps-check && bin/tgui
RUN rm -rf .yarn/cache

# More cache shenanigans, trim uneeded build context for layer caching DM build
# this ensures modifying eg. dynamic maps don't force a game rebuild, as we just add them at end regardless
# *.txt is the changelog date marker (uses gitlab project ID)
FROM byond AS cm-cache
COPY . /build
WORKDIR /build
RUN rm -rf tgui config strings maps map_config tools *.txt
# Copy back the few files we need during DM build
COPY maps/_basemap.dm maps/
COPY maps/map_files/generic maps/map_files/generic

# Actual game building stage. We include tgui here because it'll be packed in RSC file
FROM cm-builder AS cm-build
COPY --from=cm-cache /build /build
WORKDIR /build
COPY --from=tgui-build /tgui/public tgui/public
RUN source /byond/bin/byondsetup && DreamMaker ColonialMarinesALPHA.dme

# Deployment container piecing everything together for use
FROM byond AS deploy
ENV DREAMDAEMON_PORT=1400
RUN mkdir -p /cm/data
COPY tools/runner-entrypoint.sh /entrypoint.sh
RUN chmod u+x /entrypoint.sh
RUN useradd -ms /bin/bash byond
RUN chown -R byond:byond /byond /cm /entrypoint.sh
WORKDIR /cm
USER byond
COPY librust_g.so .
COPY config config
COPY map_config map_config
COPY strings strings
COPY nano nano
COPY maps maps
COPY --from=cm-build /build/ColonialMarinesALPHA.rsc application.rsc
COPY --from=cm-build /build/ColonialMarinesALPHA.dmb application.dmb
ENTRYPOINT [ "/entrypoint.sh" ]
Empty file added cfg/.keep
Empty file.
4 changes: 2 additions & 2 deletions code/controllers/configuration/entries/general.dm
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ Basics, the most important.

/datum/config_entry/string/dburl

// Shutdown instead of restarting
/// Shutdown server instead of actually restarting when using /world/Reboot()
/datum/config_entry/flag/no_restarts
config_entry_value = FALSE
config_entry_value = TRUE

/// URL for the CentCom Galactic Ban DB API
/datum/config_entry/string/centcom_ban_db
Expand Down
19 changes: 19 additions & 0 deletions config/example/dbconfig_docker.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# file to use with the bundled docker-compose environment, drop it as config/dbconfig.txt

# server adapter
DB_PROVIDER brsql

# server address
DB_ADDRESS cm13-mysql

# server port
DB_PORT 3306

# server db
DB_DATABASE cm13

# server login
DB_USERNAME cm13

# server password
DB_PASSWORD cm13testing
56 changes: 56 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
version: '3.6'

services:
# You will probably want to copy config/example/dbconfig_docker.txt to config/dbconfig.txt to use this
cm13-mysql:
image: mysql:8
command: mysqld --default-authentication-plugin=mysql_native_password
restart: always
ports:
- 3306:3306
environment:
MYSQL_DATABASE: cm13
MYSQL_USER: cm13
MYSQL_PASSWORD: cm13testing
MYSQL_ROOT_PASSWORD: cm13testingroot
volumes:
- cm13-mysql:/var/lib/mysql
networks:
- cm13-net

cm13-game:
build:
context: .
target: deploy
ports:
- 51400:1400
volumes:
- type: bind
source: ./cfg
target: /usr/local/byond/cfg
- type: bind
source: ./data
target: /cm/data
- type: bind
source: ./config
target: /cm/config
read_only: true
- type: bind
source: ./map_config
target: /cm/map_config
read_only: true
- type: bind
source: ./maps
target: /cm/maps
read_only: true
networks:
- cm13-net
depends_on:
- cm13-mysql

volumes:
cm13-mysql:

networks:
cm13-net:
driver: bridge
22 changes: 22 additions & 0 deletions tgui/bin/tgui
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ task-install() {
yarn install
}

## Install deps in CI mode
task-install-deps() {
cd "${base_dir}"
yarn install --immutable
}

## Check deps in CI mode
task-install-check() {
cd "${base_dir}"
yarn install --immutable --immutable-cache
}

## Runs webpack
task-webpack() {
cd "${base_dir}"
Expand Down Expand Up @@ -124,6 +136,16 @@ task-merge-bundle() {
## Main
## --------------------------------------------------------

if [[ ${1} == "--deps-only" ]]; then
task-install-deps
exit 0
fi

if [[ ${1} == "--deps-check" ]]; then
task-install-check
exit 0
fi

if [[ ${1} == "--merge"* ]]; then
if [[ ${1} == "--merge=bundle" ]]; then
shift 1
Expand Down
2 changes: 1 addition & 1 deletion tools/runner-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
source /byond/bin/byondsetup
DreamDaemon application.dmb ${DREAMDAEMON_PORT} -trusted
exec DreamDaemon application.dmb ${DREAMDAEMON_PORT} -trusted

0 comments on commit 68c2751

Please sign in to comment.