快速 rebuild 的办法

(frankfang) #1

我这周才接触到 Discourse,非常喜欢。

但我遇到一个问题:每次 rebuild 都要很久。而且如果被墙了,那么就根本无法 rebuild。

要加速 rebuild,我用了如下办法,最终效果是一次 build 只要 4 分钟:

sudo ./launcher rebuild app  0.49s user 0.49s system 0% cpu 4:16.86 total

1 将 /var/discourse 目录下所有的 git pull 相关命令都注释了

diff --git a/image/discourse_bench/run_bench.sh b/image/discourse_bench/run_bench.sh
index d1f9c6a..084781c 100644
--- a/image/discourse_bench/run_bench.sh
+++ b/image/discourse_bench/run_bench.sh
@@ -7,7 +7,7 @@ redis-server /etc/redis/redis.conf
 /etc/init.d/postgresql start
 
 # get latest source
-git pull
+# git pull
 
 # install needed gems
 sudo -E -u discourse bundle install
diff --git a/launcher b/launcher
index f2658ad..e04901f 100755
--- a/launcher
+++ b/launcher
@@ -554,9 +554,9 @@ run_bootstrap() {
   rm -f $cidbootstrap
 
   run_command="cd /pups &&"
-  if [[ ! "false" =  $update_pups ]]; then
-    run_command="$run_command git pull &&"
-  fi
+  #if [[ ! "false" =  $update_pups ]]; then
+    #run_command="$run_command git pull &&"
+  #fi
   run_command="$run_command /pups/bin/pups --stdin"
 
   echo $run_command
@@ -632,7 +632,7 @@ case "$command" in
       if [ "$(git symbolic-ref --short HEAD)" == "master" ]; then
         echo "Ensuring launcher is up to date"
 
-        git remote update
+        #git remote update
 
         LOCAL=$(git rev-parse @)
         REMOTE=$(git rev-parse @{u})
@@ -643,7 +643,7 @@ case "$command" in
 
         elif [ $LOCAL = $BASE ]; then
           echo "Updating Launcher"
-          git pull || (echo 'failed to update' && exit 1)
+          #git pull || (echo 'failed to update' && exit 1)
           
           for (( i=${#BASH_ARGV[@]}-1,j=0; i>=0,j<${#BASH_ARGV[@]}; i--,j++ ))
           do
diff --git a/templates/web.template.yml b/templates/web.template.yml
index faacaf8..7a7c4f5 100644
--- a/templates/web.template.yml
+++ b/templates/web.template.yml
@@ -122,8 +122,8 @@ run:
         - git reset --hard
         - git clean -f
         - git remote set-branches --add origin master
-        - git pull
-        - git fetch origin $version
+          #- git pull
+          #- git fetch origin $version
         - git checkout $version
         - mkdir -p tmp/pids
         - mkdir -p tmp/sockets

2 从本地安装 plugins,app.yml 改动如下

volumes:
  - volume:
      host: /var/discourse/shared/standalone
      guest: /shared
  - volume:
      host: /var/shared/standalone/log/var-log
      guest: /var/log
  - volume:
      host: /var/discourse/plugins
      guest: /plugins


hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - cp -r /plugins/docker_manager ./docker_manager

3 将插件事先放到 /var/discourse/plugins 目录下

plugins
└── docker_manager

4 去掉不需要的语言包,将 web.template.yml 改成这样(我只保留了中英两种语言包):

  ...
  - exec:
      cd: $home
      hook: code
      cmd:
        # - git reset --hard
        # - git clean -f
        # - git remote set-branches --add origin master
        # - git pull
        # - git fetch origin $version
        # - git checkout $version
        - find config/locales/ -name "server.*.yml" -not -path "*.zh*" -not -path "*.en.*" -type f -delete
        - find config/locales/ -name "client.*.yml" -not -path "*.zh*" -not -path "*.en.*" -type f -delete
        - find config/locales/ -name "transliterate.*.yml" -not -path "*.zh*" -not -path "*.en.*" -type f -delete
        - find app/assets/javascripts/locales/ -name "*.js.erb" -not -path "*/zh*.js.erb" -not -path "*/en.*" -type f -delete
        - mkdir -p tmp/pids
  ...

这样一来再 rebuild,就快很多了,当然还是需要好几分钟,但至少不会因为网络问题而卡住。

现在最费时的就是压缩 JS 了,如果你是在本地使用,那么你其实不需要压缩 JS,你可以搜索 production 环境变量,将其改为 development,这样就更快了。

遇到的问题:Groups 相关的翻译不见了,不过只有管理员能看到。

当然,这种加速缺点是显而易见的。希望你至少每周一次真正的 rebuild,以保持最新版本。

2赞
(Dante) #2

6666666:+1: