From e910e3024c376872ffdb8f115d970c78a642120d Mon Sep 17 00:00:00 2001 From: Kazunori Kimura Date: Thu, 16 Jan 2025 17:51:35 +0900 Subject: [PATCH] Stop recompiling assets to enable relative url As a result, an Internet connection is no longer required to use relative URLs. To enable relative url, we execute `gitlab:assets:compile`. This have been removed in official documentation in v10.0.0 (first committed to gitlab-foss, then ported to gitlab(-ee)) - EE: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/1139/ - CE: https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/8831 An internet connection was required when enabling relative urls to install the node modules required for compilation. I reviewed the rake task `gitlab:assets:compile` and investigated whether it was necessary to compile all assets just because the relative url changed, and found that this rake task is internally a separate rake task `gitlab:assets :fix_urls` which rewrite the reference URL in the css. I removed rake task `gitlab:assets:compile` at runtime and confirmed that the gitlab application worked normally as before. I have confirmed that at least the following functions work properly. - Administrator password reset at first login - Create empty project - Edit/add and commit files using web IDE - Create merge request/issue - Attach files to comments - Create empty group - Move existing project to group In addition, we no longer need to do following things - persist node_modules, recompiled assets and caches - apply patches to gitlab itself to avoid removing (symlink to) node_modules/ This change also reduces startup time in certain cases when the relative URL feature is enabled (when assets are compiled; for example, when performing a version upgrade or changing the relative URL) (on my environment, `gitlab:assets:fix_urls` took about 20 seconds) --- Dockerfile | 2 +- ...avoid-removing-node_modules_dir.patch.bak} | 0 ...-raketask-gitlab-assets-compile.patch.bak} | 0 assets/runtime/functions | 32 ------------------- 4 files changed, 1 insertion(+), 33 deletions(-) rename assets/build/patches/gitlabhq/{0003-fix_preinstall.mjs-to-avoid-removing-node_modules_dir.patch => 0003-fix_preinstall.mjs-to-avoid-removing-node_modules_dir.patch.bak} (100%) rename assets/build/patches/gitlabhq/{0004-fix-raketask-gitlab-assets-compile.patch => 0004-fix-raketask-gitlab-assets-compile.patch.bak} (100%) diff --git a/Dockerfile b/Dockerfile index ebf60257..db9a17ff 100644 --- a/Dockerfile +++ b/Dockerfile @@ -84,7 +84,7 @@ LABEL \ EXPOSE 22/tcp 80/tcp 443/tcp -VOLUME ["${GITLAB_DATA_DIR}", "${GITLAB_LOG_DIR}","${GITLAB_HOME}/gitlab/node_modules"] +VOLUME ["${GITLAB_DATA_DIR}", "${GITLAB_LOG_DIR}"] WORKDIR ${GITLAB_INSTALL_DIR} ENTRYPOINT ["/sbin/entrypoint.sh"] CMD ["app:start"] diff --git a/assets/build/patches/gitlabhq/0003-fix_preinstall.mjs-to-avoid-removing-node_modules_dir.patch b/assets/build/patches/gitlabhq/0003-fix_preinstall.mjs-to-avoid-removing-node_modules_dir.patch.bak similarity index 100% rename from assets/build/patches/gitlabhq/0003-fix_preinstall.mjs-to-avoid-removing-node_modules_dir.patch rename to assets/build/patches/gitlabhq/0003-fix_preinstall.mjs-to-avoid-removing-node_modules_dir.patch.bak diff --git a/assets/build/patches/gitlabhq/0004-fix-raketask-gitlab-assets-compile.patch b/assets/build/patches/gitlabhq/0004-fix-raketask-gitlab-assets-compile.patch.bak similarity index 100% rename from assets/build/patches/gitlabhq/0004-fix-raketask-gitlab-assets-compile.patch rename to assets/build/patches/gitlabhq/0004-fix-raketask-gitlab-assets-compile.patch.bak diff --git a/assets/runtime/functions b/assets/runtime/functions index de90c30a..31da143c 100644 --- a/assets/runtime/functions +++ b/assets/runtime/functions @@ -1756,25 +1756,6 @@ initialize_datadir() { chmod 700 ${GITLAB_DATA_DIR}/.ssh chmod 600 ${GITLAB_DATA_DIR}/.ssh/authorized_keys chown -R ${GITLAB_USER}: ${GITLAB_DATA_DIR}/.ssh - - # recompile and persist assets when relative_url is in use - if [[ -n ${GITLAB_RELATIVE_URL_ROOT} ]]; then - mkdir -p ${GITLAB_TEMP_DIR}/cache - chmod 755 ${GITLAB_TEMP_DIR}/cache - chown ${GITLAB_USER}: ${GITLAB_TEMP_DIR}/cache - - mkdir -p ${GITLAB_TEMP_DIR}/assets - chmod 755 ${GITLAB_TEMP_DIR}/assets - chown ${GITLAB_USER}: ${GITLAB_TEMP_DIR}/assets - - # symlink ${GITLAB_INSTALL_DIR}/tmp/cache -> ${GITLAB_TEMP_DIR}/cache - rm -rf ${GITLAB_INSTALL_DIR}/tmp/cache - exec_as_git ln -s ${GITLAB_TEMP_DIR}/cache ${GITLAB_INSTALL_DIR}/tmp/cache - - # symlink ${GITLAB_INSTALL_DIR}/public/assets -> ${GITLAB_TEMP_DIR}/assets - rm -rf ${GITLAB_INSTALL_DIR}/public/assets - exec_as_git ln -s ${GITLAB_TEMP_DIR}/assets ${GITLAB_INSTALL_DIR}/public/assets - fi } sanitize_datadir() { @@ -2250,19 +2231,6 @@ migrate_database() { # clear cache if relative_url has changed. [[ -f ${GITLAB_TEMP_DIR}/GITLAB_RELATIVE_URL_ROOT ]] && CACHE_GITLAB_RELATIVE_URL_ROOT=$(cat ${GITLAB_TEMP_DIR}/GITLAB_RELATIVE_URL_ROOT) if [[ ! -f ${GITLAB_TEMP_DIR}/GITLAB_RELATIVE_URL_ROOT || ${GITLAB_RELATIVE_URL_ROOT} != ${CACHE_GITLAB_RELATIVE_URL_ROOT} ]]; then - # assets need to be recompiled when GITLAB_RELATIVE_URL_ROOT is used - if [[ -n ${GITLAB_RELATIVE_URL_ROOT} ]]; then - if [[ ! -d ${GITLAB_HOME}/gitlab/node_modules ]]; then - mkdir -p ${GITLAB_HOME}/gitlab/node_modules - chown -R ${GITLAB_USER}: ${GITLAB_HOME}/gitlab/node_modules - fi - echo "Prepare recompile assets... Installing missing node_modules for assets" - chown -R ${GITLAB_USER}: ${GITLAB_HOME}/gitlab/node_modules - exec_as_git yarn install --production --pure-lockfile - echo "Recompiling assets (relative_url in use), this could take a while..." - exec_as_git bundle exec rake gitlab:assets:compile NODE_OPTIONS="--max-old-space-size=8192" >/dev/null 2>&1 - fi - echo "Clearing cache..." exec_as_git bundle exec rake cache:clear >/dev/null 2>&1 echo "${GITLAB_RELATIVE_URL_ROOT}" > ${GITLAB_TEMP_DIR}/GITLAB_RELATIVE_URL_ROOT