feat(CORE): docker permissions and rework (#13454)

- fix docker permissions with mounted volumes on new docker versions (https://github.com/docker/desktop-linux/issues/31)
- fix ac-tools image
- cleanup unused env
- add  `cap_add: SYS_NICE` to allow setting process high priority
- fix ccache in docker
- allow to switch between root user (default) to acore user in any container
- fix cache of the downloaded client data
- split docker github actions in 2 parts
- versioning mysql images
- performance improvements
This commit is contained in:
Yehonal
2022-11-07 13:20:48 +01:00
committed by GitHub
parent 6177ce4688
commit e4016823d7
36 changed files with 513 additions and 250 deletions

View File

@@ -45,7 +45,11 @@ RUN addgroup --gid $GROUP_ID acore && \
# must be created to set the correct permissions on them
RUN mkdir -p /azerothcore/env/dist/bin
RUN mkdir -p /azerothcore/env/dist/data
RUN mkdir -p /azerothcore/env/dist/data/Cameras
RUN mkdir -p /azerothcore/env/dist/data/dbc
RUN mkdir -p /azerothcore/env/dist/data/maps
RUN mkdir -p /azerothcore/env/dist/data/mmaps
RUN mkdir -p /azerothcore/env/dist/data/vmaps
RUN mkdir -p /azerothcore/env/dist/logs
RUN mkdir -p /azerothcore/env/dist/temp
RUN mkdir -p /azerothcore/env/dist/etc
@@ -59,10 +63,14 @@ RUN chown -R $DOCKER_USER:$DOCKER_USER /azerothcore
USER $DOCKER_USER
# copy everything so we can work directly within the container
# using tools such as vscode dev-container
# NOTE: this folder is different by the /azerothcore (which is binded instead)
COPY --chown=$DOCKER_USER:$DOCKER_USER . /azerothcore
# copy only necessary files for the acore dashboard
COPY --chown=$DOCKER_USER:$DOCKER_USER apps /azerothcore/apps
COPY --chown=$DOCKER_USER:$DOCKER_USER bin /azerothcore/bin
COPY --chown=$DOCKER_USER:$DOCKER_USER conf /azerothcore/conf
COPY --chown=$DOCKER_USER:$DOCKER_USER data /azerothcore/data
COPY --chown=$DOCKER_USER:$DOCKER_USER deps /azerothcore/deps
COPY --chown=$DOCKER_USER:$DOCKER_USER acore.json /azerothcore/acore.json
COPY --chown=$DOCKER_USER:$DOCKER_USER acore.sh /azerothcore/acore.sh
# Download deno and make sure the dashboard works
RUN bash /azerothcore/acore.sh quit
@@ -79,6 +87,13 @@ FROM base as dev
LABEL description="AC dev image for dev containers"
USER $DOCKER_USER
# copy everything so we can work directly within the container
# using tools such as vscode dev-container
# NOTE: this folder is different by the /azerothcore (which is binded instead)
COPY --chown=$DOCKER_USER:$DOCKER_USER . /azerothcore
#================================================================
#
# SERVICE BASE: prepare the OS for the production-ready services
@@ -115,26 +130,21 @@ RUN apt-get update && apt-get install -y dos2unix gdb gdbserver google-perftools
# change timezone in container
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && dpkg-reconfigure --frontend noninteractive tzdata
# copy the sources from the host machine
COPY --chown=$DOCKER_USER:$DOCKER_USER apps /azerothcore/apps
COPY --chown=$DOCKER_USER:$DOCKER_USER bin /azerothcore/bin
COPY --chown=$DOCKER_USER:$DOCKER_USER conf /azerothcore/conf
COPY --chown=$DOCKER_USER:$DOCKER_USER data /azerothcore/data
COPY --chown=$DOCKER_USER:$DOCKER_USER deps /azerothcore/deps
COPY --chown=$DOCKER_USER:$DOCKER_USER acore.json /azerothcore/acore.json
COPY --chown=$DOCKER_USER:$DOCKER_USER acore.sh /azerothcore/acore.sh
# Correct permissions for non-root operations
RUN chown -R $DOCKER_USER:$DOCKER_USER /home/acore
RUN chown -R $DOCKER_USER:$DOCKER_USER /run
RUN chown -R $DOCKER_USER:$DOCKER_USER /opt
RUN chown $DOCKER_USER:$DOCKER_USER /azerothcore
COPY --chown=$DOCKER_USER:$DOCKER_USER --from=base /azerothcore /azerothcore
USER $DOCKER_USER
# must be created to avoid permissions errors
RUN mkdir -p /azerothcore/env/dist/data
RUN mkdir -p /azerothcore/env/dist/data/Cameras
RUN mkdir -p /azerothcore/env/dist/data/dbc
RUN mkdir -p /azerothcore/env/dist/data/maps
RUN mkdir -p /azerothcore/env/dist/data/mmaps
RUN mkdir -p /azerothcore/env/dist/data/vmaps
RUN mkdir -p /azerothcore/env/dist/logs
RUN mkdir -p /azerothcore/env/dist/etc
RUN mkdir -p /azerothcore/env/dist/bin
@@ -157,12 +167,16 @@ LABEL description="AC authserver image for local environment"
CMD ./acore.sh run-authserver
USER $DOCKER_USER
FROM servicebase as worldserver-local
LABEL description="AC worldserver image for local environment"
CMD ./acore.sh run-worldserver
USER $DOCKER_USER
#================================================================
#
# BUILD: compile sources
@@ -171,12 +185,20 @@ CMD ./acore.sh run-worldserver
FROM base as build
ARG DOCKER_USER=acore
USER $DOCKER_USER
LABEL description="AC Image used by the build stage to generate production images"
RUN mkdir -p /azerothcore/env/etc/
# .git is needed by the compiler
COPY --chown=$DOCKER_USER:$DOCKER_USER ./.git /azerothcore/.git
COPY --chown=$DOCKER_USER:$DOCKER_USER ./CMakeLists.txt /azerothcore/CMakeLists.txt
COPY --chown=$DOCKER_USER:$DOCKER_USER ./deps /azerothcore/deps
COPY --chown=$DOCKER_USER:$DOCKER_USER ./src /azerothcore/src
COPY --chown=$DOCKER_USER:$DOCKER_USER ./modules /azerothcore/modules
# check if we have ccache files available outside
RUN rm -rf /azerothcore/var/ccache/*
COPY --chown=$DOCKER_USER:$DOCKER_USER var/docker/ccache /azerothcore/var/ccache
COPY --chown=$DOCKER_USER:$DOCKER_USER env/docker/etc/authserver.conf.dockerdist /azerothcore/env/dist/etc/authserver.conf.dockerdist
COPY --chown=$DOCKER_USER:$DOCKER_USER env/docker/etc/worldserver.conf.dockerdist /azerothcore/env/dist/etc/worldserver.conf.dockerdist
@@ -207,6 +229,7 @@ FROM authserver-local as authserver
LABEL description="AC Production: authserver"
ARG DOCKER_USER=acore
USER $DOCKER_USER
COPY --chown=$DOCKER_USER:$DOCKER_USER --from=build /azerothcore/env/dist/etc /azerothcore/env/dist/etc
COPY --chown=$DOCKER_USER:$DOCKER_USER --from=build /azerothcore/env/dist/bin/authserver /azerothcore/env/dist/bin/authserver
@@ -222,6 +245,7 @@ FROM worldserver-local as worldserver
LABEL description="AC Production: worldserver"
ARG DOCKER_USER=acore
USER $DOCKER_USER
RUN mkdir -p /azerothcore/env/dist/bin/lua_scripts
COPY --chown=$DOCKER_USER:$DOCKER_USER --from=build /azerothcore/env/dist/etc /azerothcore/env/dist/etc
@@ -258,9 +282,8 @@ RUN addgroup --gid $GROUP_ID acore && \
ENV DATAPATH=/azerothcore/env/dist/data
ENV DATAPATH_ZIP=/tmp/data.zip
RUN --mount=type=bind,target=/azerothcore-temp,readwrite /azerothcore-temp/acore.sh client-data && chown -R $DOCKER_USER:$DOCKER_USER /azerothcore
RUN apt-get remove --purge -y tzdata curl unzip && apt-get autoremove -y
RUN mkdir -p "$DATAPATH"
RUN --mount=type=bind,target=/azerothcore-temp,readwrite --mount=type=cache,target=/azerothcore/env/dist/data /azerothcore-temp/acore.sh client-data && chown -R $DOCKER_USER:$DOCKER_USER /azerothcore
USER $DOCKER_USER
@@ -302,14 +325,14 @@ USER $DOCKER_USER
WORKDIR /azerothcore/env/client/
RUN mkdir -p /azerothcore/env/client/Cameras
RUN mkdir -p /azerothcore/env/client/dbc
RUN mkdir -p /azerothcore/env/client/maps
RUN mkdir -p /azerothcore/env/client/mmaps
RUN mkdir -p /azerothcore/env/client/vmaps
# Need fix
# COPY --chown=$DOCKER_USER:$DOCKER_USER --from=build /azerothcore/env/dist/bin/mapextractor /azerothcore/env/client/mapextractor
# COPY --chown=$DOCKER_USER:$DOCKER_USER --from=build /azerothcore/env/dist/bin/mmaps_generator /azerothcore/env/client/mmaps_generator
# COPY --chown=$DOCKER_USER:$DOCKER_USER --from=build /azerothcore/env/dist/bin/vmap4assembler /azerothcore/env/client/vmap4assembler
# COPY --chown=$DOCKER_USER:$DOCKER_USER --from=build /azerothcore/env/dist/bin/vmap4extractor /azerothcore/env/client/vmap4extractor
COPY --chown=$DOCKER_USER:$DOCKER_USER --from=build /azerothcore/env/dist/bin/map_extractor /azerothcore/env/client/map_extractor
COPY --chown=$DOCKER_USER:$DOCKER_USER --from=build /azerothcore/env/dist/bin/mmaps_generator /azerothcore/env/client/mmaps_generator
COPY --chown=$DOCKER_USER:$DOCKER_USER --from=build /azerothcore/env/dist/bin/vmap4_assembler /azerothcore/env/client/vmap4_assembler
COPY --chown=$DOCKER_USER:$DOCKER_USER --from=build /azerothcore/env/dist/bin/vmap4_extractor /azerothcore/env/client/vmap4_extractor

View File

@@ -1,5 +1,7 @@
CUR_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CTOOLS_BUILD=all
# allow the user to override configs
if [ -f "$AC_PATH_CONF/config.sh" ]; then
source "$AC_PATH_CONF/config.sh" # should overwrite previous

View File

@@ -39,9 +39,19 @@ shellCommandFactory(
"build",
"Build the authserver and worldserver",
[
"docker compose --profile local build --parallel",
"docker compose --profile local --profile dev --profile dev-build build --parallel",
"docker image prune -f",
"docker compose run --rm --no-deps ac-dev-build bash apps/docker/docker-build-dev.sh",
],
env
);
shellCommandFactory(
"pull",
"Pull build and local images",
[
"docker compose --profile local --profile dev --profile dev-build pull --parallel",
"docker image prune -f",
"docker compose run --rm ac-build bash apps/docker/docker-build-dev.sh",
],
env
);
@@ -50,20 +60,9 @@ shellCommandFactory(
"build:nocache",
"Build the authserver and worldserver without docker cache",
[
"docker compose --profile local build --no-cache --parallel",
"docker compose --profile local --profile dev --profile dev-build build --no-cache --parallel",
"docker image prune -f",
"docker compose run --rm ac-build bash apps/docker/docker-build-dev.sh",
],
env
);
shellCommandFactory(
"build:compile",
"Run the compilation process only, without rebuilding all docker images",
[
"docker compose build --parallel ac-build",
"docker image prune -f",
"docker compose run --rm ac-build bash apps/docker/docker-build-dev.sh",
"docker compose run --rm --no-deps ac-dev-build bash apps/docker/docker-build-dev.sh",
],
env
);
@@ -73,7 +72,8 @@ shellCommandFactory(
"Clean build files",
[
"docker image prune -f",
`docker compose run --rm ac-build bash acore.sh compiler clean`,
`docker compose run --rm --no-deps ac-dev-server bash acore.sh compiler clean`,
`docker compose run --rm --no-deps ac-dev-server bash acore.sh compiler ccacheClean`,
],
env
);
@@ -81,7 +81,7 @@ shellCommandFactory(
shellCommandFactory(
"client-data",
"Download client data inside the ac-data volume",
["docker compose run --rm ac-build bash acore.sh client-data"],
["docker compose run --rm --no-deps ac-dev-server bash acore.sh client-data"],
env
);
@@ -94,7 +94,7 @@ shellCommandFactory(
shellCommandFactory(
"dev:build",
"Build using the dev server, it uses volumes to compile which can be faster on linux & WSL",
"Build using the dev server",
["docker compose run --rm ac-dev-server bash acore.sh compiler build"],
env
);
@@ -118,28 +118,28 @@ shellCommandFactory(
shellCommandFactory(
"prod:build",
"Build producion services",
"[TEST ONLY] Build producion services",
["docker compose --profile prod build --parallel", "docker image prune -f"],
env
);
shellCommandFactory(
"prod:pull",
"Pull production services from the remote registry",
"[TEST ONLY] Pull production services from the remote registry",
["docker compose --profile prod pull"],
env
);
shellCommandFactory(
"prod:up",
"Start production services (foreground)",
"[TEST ONLY] Start production services (foreground)",
["docker compose --profile prod-app up"],
env
);
shellCommandFactory(
"prod:up:d",
"Start production services (background)",
"[TEST ONLY] Start production services (background)",
["docker compose --profile prod-app up -d"],
env
);
@@ -176,7 +176,7 @@ program
}
services.pop();
services = services.slice(2);
services = services.slice(1);
res.close(); // Don't forget to close it
@@ -304,8 +304,6 @@ async function checkDockerVersion() {
}
async function main() {
// Handle it however you like
// e.g. display usage
while (true) {
const version = await checkDockerVersion();
if (version !== true) {