diff options
author | Yehonal <yehonal.azeroth@gmail.com> | 2022-11-07 13:20:48 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-07 13:20:48 +0100 |
commit | e4016823d7ee5e77aa6cb162a3eed584d7b35a87 (patch) | |
tree | e7f6d18ac7a28b6c097b999efed93bf7e052a505 /apps | |
parent | 6177ce4688fc34af7cebb0d47a15be1553fbffc1 (diff) |
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
Diffstat (limited to 'apps')
-rw-r--r-- | apps/bash_shared/common.sh | 2 | ||||
-rw-r--r-- | apps/ci/ci-conf-core.sh | 3 | ||||
-rw-r--r-- | apps/ci/ci-conf-db.sh | 3 | ||||
-rw-r--r-- | apps/ci/ci-install.sh | 3 | ||||
-rwxr-xr-x | apps/compiler/compiler.sh | 2 | ||||
-rw-r--r-- | apps/compiler/includes/functions.sh | 4 | ||||
-rw-r--r-- | apps/docker/Dockerfile | 71 | ||||
-rw-r--r-- | apps/docker/config-docker.sh | 2 | ||||
-rw-r--r-- | apps/docker/docker-cmd.ts | 38 | ||||
-rw-r--r-- | apps/installer/main.sh | 6 | ||||
-rw-r--r-- | apps/installer/main.ts | 43 | ||||
-rw-r--r-- | apps/installer/utils.ts | 17 |
12 files changed, 139 insertions, 55 deletions
diff --git a/apps/bash_shared/common.sh b/apps/bash_shared/common.sh index c8d8880cf8..027a49bed3 100644 --- a/apps/bash_shared/common.sh +++ b/apps/bash_shared/common.sh @@ -9,7 +9,7 @@ USER_CONF_PATH=${USER_CONF_PATH:-"$AC_PATH_CONF/config.sh"} if [ -f "$USER_CONF_PATH" ]; then source "$USER_CONF_PATH" # should overwrite previous else - echo "NOTICE: file <$USER_CONF_PATH> has not been found, you should create and configure it." + echo "NOTICE: file <$USER_CONF_PATH> not found, we use default configuration only." fi # diff --git a/apps/ci/ci-conf-core.sh b/apps/ci/ci-conf-core.sh index 4fd3fa4c23..591ad7078d 100644 --- a/apps/ci/ci-conf-core.sh +++ b/apps/ci/ci-conf-core.sh @@ -14,9 +14,6 @@ CBUILD_TESTING=ON CSCRIPTPCH=OFF CCOREPCH=OFF CCUSTOMOPTIONS='-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_FLAGS="-Werror" -DCMAKE_CXX_FLAGS="-Werror"' -DB_CHARACTERS_CONF="MYSQL_USER='root'; MYSQL_PASS='root'; MYSQL_HOST='localhost';" -DB_AUTH_CONF="MYSQL_USER='root'; MYSQL_PASS='root'; MYSQL_HOST='localhost';" -DB_WORLD_CONF="MYSQL_USER='root'; MYSQL_PASS='root'; MYSQL_HOST='localhost';" CONFIG_SH case $COMPILER in diff --git a/apps/ci/ci-conf-db.sh b/apps/ci/ci-conf-db.sh index e0fc17bce7..2bcfb9deb2 100644 --- a/apps/ci/ci-conf-db.sh +++ b/apps/ci/ci-conf-db.sh @@ -12,9 +12,6 @@ CTOOLS_BUILD=db-only CSCRIPTPCH=OFF CCOREPCH=OFF CCUSTOMOPTIONS='-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_FLAGS="-Werror" -DCMAKE_CXX_FLAGS="-Werror"' -DB_CHARACTERS_CONF="MYSQL_USER='root'; MYSQL_PASS='root'; MYSQL_HOST='localhost';" -DB_AUTH_CONF="MYSQL_USER='root'; MYSQL_PASS='root'; MYSQL_HOST='localhost';" -DB_WORLD_CONF="MYSQL_USER='root'; MYSQL_PASS='root'; MYSQL_HOST='localhost';" CONFIG_SH case $COMPILER in diff --git a/apps/ci/ci-install.sh b/apps/ci/ci-install.sh index c333d9685c..ce0372cb8b 100644 --- a/apps/ci/ci-install.sh +++ b/apps/ci/ci-install.sh @@ -14,9 +14,6 @@ CTOOLS=ON CSCRIPTPCH=OFF CCOREPCH=OFF CCUSTOMOPTIONS='-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_FLAGS="-Werror" -DCMAKE_CXX_FLAGS="-Werror"' -DB_CHARACTERS_CONF="MYSQL_USER='root'; MYSQL_PASS='root'; MYSQL_HOST='localhost';" -DB_AUTH_CONF="MYSQL_USER='root'; MYSQL_PASS='root'; MYSQL_HOST='localhost';" -DB_WORLD_CONF="MYSQL_USER='root'; MYSQL_PASS='root'; MYSQL_HOST='localhost';" CONFIG_SH time sudo apt-get update -y diff --git a/apps/compiler/compiler.sh b/apps/compiler/compiler.sh index 140d5fa974..dcb94a6b65 100755 --- a/apps/compiler/compiler.sh +++ b/apps/compiler/compiler.sh @@ -29,6 +29,7 @@ comp_options=( "compile: Compile only" "all: clean, configure and compile" "ccacheClean: Clean ccache files, normally not needed" + "ccacheShowStats: show ccache statistics" "quit: Close this menu") comp_functions=( "comp_build" @@ -37,6 +38,7 @@ comp_functions=( "comp_compile" "comp_all" "comp_ccacheClean" + "comp_ccacheShowStats" "comp_quit") PS3='[ Please enter your choice ]: ' diff --git a/apps/compiler/includes/functions.sh b/apps/compiler/includes/functions.sh index 842f65b85b..25cc507bcc 100644 --- a/apps/compiler/includes/functions.sh +++ b/apps/compiler/includes/functions.sh @@ -17,6 +17,8 @@ function comp_ccacheEnable() { export CCACHE_CPP2=${CCACHE_CPP2:-true} # optimization for clang export CCACHE_COMPRESS=${CCACHE_COMPRESS:-1} export CCACHE_COMPRESSLEVEL=${CCACHE_COMPRESSLEVEL:-9} + export CCACHE_COMPILERCHECK=${CCACHE_COMPILERCHECK:-content} + export CCACHE_LOGFILE=${CCACHE_LOGFILE:-"$CCACHE_DIR/cache.debug"} #export CCACHE_NODIRECT=true export CCUSTOMOPTIONS="$CCUSTOMOPTIONS -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache" @@ -106,6 +108,8 @@ function comp_compile() { cd $BUILDPATH + comp_ccacheEnable + comp_ccacheResetStats time cmake --build . --config $CTYPE -j $MTHREADS diff --git a/apps/docker/Dockerfile b/apps/docker/Dockerfile index c70a2b1187..97aed784eb 100644 --- a/apps/docker/Dockerfile +++ b/apps/docker/Dockerfile @@ -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 diff --git a/apps/docker/config-docker.sh b/apps/docker/config-docker.sh index 8c3ac42067..7f5482480d 100644 --- a/apps/docker/config-docker.sh +++ b/apps/docker/config-docker.sh @@ -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 diff --git a/apps/docker/docker-cmd.ts b/apps/docker/docker-cmd.ts index ce03f34ced..43884f956d 100644 --- a/apps/docker/docker-cmd.ts +++ b/apps/docker/docker-cmd.ts @@ -39,31 +39,30 @@ 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 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 ); shellCommandFactory( - "build:nocache", - "Build the authserver and worldserver without docker cache", + "pull", + "Pull build and local images", [ - "docker compose --profile local build --no-cache --parallel", + "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 ); shellCommandFactory( - "build:compile", - "Run the compilation process only, without rebuilding all docker images", + "build:nocache", + "Build the authserver and worldserver without docker cache", [ - "docker compose build --parallel ac-build", + "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", + "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) { diff --git a/apps/installer/main.sh b/apps/installer/main.sh index 7475c8f2ff..91d6cb1dc6 100644 --- a/apps/installer/main.sh +++ b/apps/installer/main.sh @@ -67,7 +67,11 @@ function _switch() { DOCKER=1 denoRunFile "$AC_PATH_APPS/docker/docker-cmd.ts" "${@:2}" exit ;; - ""|"quit"|"14") + ""|"v"|"version"|"14") + denoRunFile "$AC_PATH_APPS/installer/main.ts" "version" + exit + ;; + ""|"quit"|"15") echo "Goodbye!" exit ;; diff --git a/apps/installer/main.ts b/apps/installer/main.ts new file mode 100644 index 0000000000..135ccc6452 --- /dev/null +++ b/apps/installer/main.ts @@ -0,0 +1,43 @@ +import { Command } from "https://cdn.deno.land/cmd/versions/v1.2.0/raw/mod.ts"; +import { getAcoreReleaseVersion } from "./utils.ts"; +import { Input } from "https://deno.land/x/cliffy@v0.25.2/prompt/mod.ts"; + +const program = new Command(); + +program + .name("acore.sh") + .description("Shell scripts for docker") + .version("1.0.0"); + +// program +// .command("quit") +// .description("Close docker command") +// .action(() => { +// process.exit(0); +// }); + +program + .command("version") + .description("Get the version of the current AzerothCore revision") + .action(async () => { + console.log(await getAcoreReleaseVersion()); + }); + +async function main() { + let exit = false; + do { + if (Deno.args.length === 0) { + program.outputHelp(); + const command = await Input.prompt({ + message: "Enter the command:", + }); + console.log(command); + await program.parseAsync(command.split(" ")); + } else { + exit = true; + await program.parseAsync(Deno.args); + process.exit(0); + } + } while (!exit); +} +main(); diff --git a/apps/installer/utils.ts b/apps/installer/utils.ts new file mode 100644 index 0000000000..90d70ec6a8 --- /dev/null +++ b/apps/installer/utils.ts @@ -0,0 +1,17 @@ +import * as path from "https://deno.land/std/path/mod.ts"; +import makeloc from "https://deno.land/x/dirname@1.1.2/mod.ts"; + +const { __dirname } = makeloc(import.meta); + +// specify the needed paths here +const ACORE_JSON = path.resolve(__dirname + "/../../acore.json"); + +export async function getAcoreReleaseVersion() { + // read the acore.json file to work with the versioning + const decoder = new TextDecoder("utf-8"); + //console.debug(`Open ${ACORE_JSON}`) + const data = await Deno.readFile(ACORE_JSON); + const acoreInfo = JSON.parse(decoder.decode(data)); + + return `AzerothCore Rev. ${acoreInfo.version}`; +} |