diff --git a/ct/discourse.sh b/ct/discourse.sh index 89ff57623..59fbda6ae 100644 --- a/ct/discourse.sh +++ b/ct/discourse.sh @@ -51,16 +51,33 @@ function update_script() { cd /opt/discourse export PATH="$HOME/.rbenv/bin:$HOME/.rbenv/shims:$PATH" export COREPACK_ENABLE_DOWNLOAD_PROMPT=0 + export BUNDLE_SILENCE_ROOT_WARNING=1 set -a source /opt/discourse/.env set +a $STD git pull origin main - $STD bundle install + msg_ok "Updated Discourse" + + # Discourse ships no .ruby-version, the required Ruby is pinned in Gemfile.lock + RUBY_TARGET=$(grep -A1 '^RUBY VERSION' /opt/discourse/Gemfile.lock | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -n1) + RUBY_VERSION="${RUBY_TARGET:-4.0.7}" RUBY_INSTALL_RAILS="false" setup_ruby + export PATH="$HOME/.rbenv/bin:$HOME/.rbenv/shims:$PATH" + hash -r + + msg_info "Updating Dependencies" + cd /opt/discourse + $STD bundle install -j"$(nproc)" $STD pnpm install + msg_ok "Updated Dependencies" + + msg_info "Running Database Migrations" $STD runuser -u postgres -- psql -d discourse -c "CREATE EXTENSION IF NOT EXISTS vector;" $STD bundle exec rails db:migrate + msg_ok "Ran Database Migrations" + + msg_info "Precompiling Assets" $STD bundle exec rails assets:precompile - msg_ok "Updated Discourse" + msg_ok "Precompiled Assets" msg_info "Starting Services" systemctl start discourse discourse-sidekiq diff --git a/install/discourse-install.sh b/install/discourse-install.sh index ac2687517..b60a4814b 100644 --- a/install/discourse-install.sh +++ b/install/discourse-install.sh @@ -28,9 +28,15 @@ $STD apt install -y \ redis-server msg_ok "Installed Dependencies" +msg_info "Cloning Discourse" +$STD git clone --depth 1 https://github.com/discourse/discourse.git /opt/discourse +msg_ok "Cloned Discourse" + PG_VERSION="17" PG_MODULES="pgvector" setup_postgresql NODE_VERSION="24" setup_nodejs -RUBY_VERSION="3.4.4" setup_ruby +# Discourse ships no .ruby-version, the required Ruby is pinned in Gemfile.lock +RUBY_TARGET=$(grep -A1 '^RUBY VERSION' /opt/discourse/Gemfile.lock | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -n1) +RUBY_VERSION="${RUBY_TARGET:-4.0.7}" RUBY_INSTALL_RAILS="false" setup_ruby msg_info "Configuring PostgreSQL for Discourse" DISCOURSE_DB_PASS=$(random_password 13) @@ -42,7 +48,6 @@ msg_ok "Configured PostgreSQL for Discourse" msg_info "Configuring Discourse" DISCOURSE_SECRET_KEY=$(openssl rand -hex 64) -$STD git clone --depth 1 https://github.com/discourse/discourse.git /opt/discourse cd /opt/discourse cat </opt/discourse/.env RAILS_ENV=production @@ -77,6 +82,7 @@ export PATH="$HOME/.rbenv/bin:$HOME/.rbenv/shims:$PATH" eval "$(rbenv init - bash)" 2>/dev/null || true export RAILS_ENV=production export COREPACK_ENABLE_DOWNLOAD_PROMPT=0 +export BUNDLE_SILENCE_ROOT_WARNING=1 $STD corepack enable $STD bundle config set --local deployment true $STD bundle config set --local without 'test development'