From 3885a455d12a4e37ce829e590a763b4a3194e22f Mon Sep 17 00:00:00 2001 From: Kazunori Kimura Date: Thu, 18 Jan 2024 02:02:41 +0900 Subject: [PATCH] Add build patch to prevent rake task assets:compile to remove assets dir GitLab does not launch after second run if relative url is used. This is caused by following upstream change to remove assets directory on assets compile. See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/103715 This is introduced on v15.6.0 ````sh $ git -C ../gitlab.git/ tag --contains e46d92c0 | sort --version-sort | head -n 1 v15.6.0-ee ```` 1. `sameersbn/gitlab` create symbolic link /home/git/gitlab/public/assets/ to point /home/git/data/tmp/assets if relative url is used. This is to store assets in the docker volume to avoid unnecessary recompilations. These assets are removed and recompiled only when the gitlab version or relative url root is changed. 2. By the change provided by gitlab.com/gitlab-org/gitlab!103715, rake task `gitlab:assets:compile` became to remove assets directory directly (by `FileUtils.rm_rf()`). It does not remove compiled assets itself, but remove symlink /home/git/gitlab/public/assets . Then it compiles assets as usual, but they will be stored in newly-created normal directory /home/git/gitlab/public/assets/ 3. On container down, whole container statement (except volumes) will be reset. These compiled assets will be removed as well because they are not in docker volume. 4. As we store version info and relative url root path to /home/git/data/tmp/, we cannot recognize we have to recompile assets (that have been removed by mistake) To avoid the issue, this commit add a build time patch to change the behavior of rake task `gitlab:assets:compile` to empty assets instead of removing assets directory itself. --- ...4-fix-raketask-gitlab-assets-compile.patch | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 assets/build/patches/0004-fix-raketask-gitlab-assets-compile.patch diff --git a/assets/build/patches/0004-fix-raketask-gitlab-assets-compile.patch b/assets/build/patches/0004-fix-raketask-gitlab-assets-compile.patch new file mode 100644 index 00000000..f03bf8e5 --- /dev/null +++ b/assets/build/patches/0004-fix-raketask-gitlab-assets-compile.patch @@ -0,0 +1,20 @@ +diff --git a/lib/tasks/gitlab/assets.rake b/lib/tasks/gitlab/assets.rake +index b8a6e7018767..5096d81ea63f 100644 +--- a/lib/tasks/gitlab/assets.rake ++++ b/lib/tasks/gitlab/assets.rake +@@ -96,7 +96,14 @@ namespace :gitlab do + puts "Assets SHA256 for `HEAD`: #{Tasks::Gitlab::Assets.head_assets_sha256.inspect}" + + if Tasks::Gitlab::Assets.head_assets_sha256 != Tasks::Gitlab::Assets.master_assets_sha256 +- FileUtils.rm_rf([Tasks::Gitlab::Assets::PUBLIC_ASSETS_DIR] + Dir.glob('app/assets/javascripts/locale/**/app.js')) ++ # sameersbn/gitlab takes a cache of public_assets_dir by symlinking to volume to speedup relaunch (if relative url is used) ++ # so do not remove the directory directly, empty instead ++ # Dir.glob("*") ignores dotfiles (even it is fine to remove here), so list up children manually ++ removal_targets = Dir.glob('app/assets/javascripts/locale/**/app.js') ++ if Dir.exists?(Tasks::Gitlab::Assets::PUBLIC_ASSETS_DIR) ++ removal_targets += Dir.children(Tasks::Gitlab::Assets::PUBLIC_ASSETS_DIR).map {|child| File.join(Tasks::Gitlab::Assets::PUBLIC_ASSETS_DIR, child)} ++ end ++ FileUtils.rm_rf(removal_targets, secure: true) + + # gettext:compile needs to run before rake:assets:precompile because + # app/assets/javascripts/locale/**/app.js are pre-compiled by Sprockets