Skip to content

Commit

Permalink
feat: Discourse v3 rock (#141)
Browse files Browse the repository at this point in the history
* feat(v3): Bump discourse to v3 tag
  • Loading branch information
merkata authored Dec 11, 2023
1 parent 8a27e9e commit 2999154
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 119 deletions.
4 changes: 4 additions & 0 deletions discourse_rock/bundler/config
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ BUNDLE_CACHE_ALL: "true"
BUNDLE_DISABLE_SHARED_GEMS: "true"
BUNDLE_FROZEN: "true"
BUNDLE_DISABLE_VERSION_CHECK: "true"
BUNDLE_DEPLOYMENT: "true"
BUNDLE_PATH: "./vendor/bundle"
BUNDLE_WITHOUT: "test:development"
BUNDLE_JOBS: "4"
14 changes: 8 additions & 6 deletions discourse_rock/patches/lp1903695.patch
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
diff --git a/lib/middleware/anonymous_cache.rb b/lib/middleware/anonymous_cache.rb
index d41069c92e..fe968c6d64 100644
--- a/lib/middleware/anonymous_cache.rb
+++ b/lib/middleware/anonymous_cache.rb
@@ -318,7 +318,7 @@ module Middleware
@@ -347,7 +347,7 @@ module Middleware
return @app.call(env) if defined?(@@disabled) && @@disabled

def call(env)
if PAYLOAD_INVALID_REQUEST_METHODS.include?(env[Rack::REQUEST_METHOD]) &&
- env[Rack::RACK_INPUT].size > 0
+ env[Rack::RACK_INPUT].respond_to?(:size) && env[Rack::RACK_INPUT].size > 0

return [413, { "Cache-Control" => "private, max-age=0, must-revalidate" }, []]
- env[Rack::RACK_INPUT].size > 0
+ env[Rack::RACK_INPUT].respond_to?(:size) && env[Rack::RACK_INPUT].size > 0
return 413, { "Cache-Control" => "private, max-age=0, must-revalidate" }, []
end

209 changes: 98 additions & 111 deletions discourse_rock/rockcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,19 @@
name: discourse
summary: Discourse rock
description: Discourse OCI image for the Discourse charm
base: ubuntu:20.04
run-user: _daemon_
base: ubuntu@22.04
run-user: _daemon_ # UID/GID 584792
license: Apache-2.0
version: "1.0"
platforms:
amd64:
parts:
install-node:
# We need nodejs so that yarn works correctly
# This allows us to control the version of node
plugin: nil
source: .
build-environment:
- NODE_VERSION: "18.18.2"
- ARCH: "x64"
overlay-script: |
node_uri="https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-${ARCH}.tar.gz"
curl -Ls $node_uri | tar xzf - -C $CRAFT_OVERLAY/ --skip-old-files --no-same-owner --strip-components=1
install-yarn:
# We need yarn to compile discourse's assets
plugin: nil
after:
- install-node
source: .
build-environment:
- YARN_VERSION: "1.22.19"
- ARCH: "x64"
overlay-script: |
yarn_uri="https://github.com/yarnpkg/yarn/releases/download/v${YARN_VERSION}/yarn-v${YARN_VERSION}.tar.gz"
curl -Ls $yarn_uri | tar xzf - -C $CRAFT_OVERLAY/ --skip-old-files --no-same-owner --strip-components=1
install-terser:
# Terser is needed to compile discourse's assets
# We don't use the system package to avoid pulling ubuntu's nodejs package
# Related to: https://git.launchpad.net/~weii-wang/charm-k8s-discourse/commit/?h=fix-terser-precompile&id=ada4ba97b28ab53dd0a619b3a9325b7a981afac1
plugin: nil
source: .
after:
- install-node
overlay-script: |
$CRAFT_OVERLAY/usr/bin/node $CRAFT_OVERLAY/usr/bin/npm --prefix $CRAFT_OVERLAY/usr/local/ i -g terser
install-runtime-packages:
tooling:
plugin: nil
overlay-packages:
- brotli
- g++
- gcc
- gettext-base
- gifsicle
- git
Expand All @@ -59,23 +28,41 @@ parts:
- libssl-dev
- libxml2-dev
- libxslt1-dev
- libyaml-dev
- libz-dev
- optipng
- pngquant
- redis-tools
- ruby2.7
- ruby2.7-dev
- tzdata
- ubuntu-dev-tools
- zlib1g-dev
get-discourse:
build-environment:
- ARCH: "x64"
- NODE_VERSION: "18.18.2"
- YARN_VERSION: "1.22.19"
- RUBY_VERSION: "3.2.2"
- RUBY_INSTALL_VERSION: "0.9.2"
- RAILS_ENV: "production"
override-build: |
node_uri="https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-${ARCH}.tar.gz"
curl -Ls $node_uri | tar xzf - -C $CRAFT_OVERLAY/ --skip-old-files --no-same-owner --strip-components=1
yarn_uri="https://github.com/yarnpkg/yarn/releases/download/v${YARN_VERSION}/yarn-v${YARN_VERSION}.tar.gz"
curl -Ls $yarn_uri | tar xzf - -C $CRAFT_OVERLAY/ --skip-old-files --no-same-owner --strip-components=1
$CRAFT_OVERLAY/usr/bin/node $CRAFT_OVERLAY/usr/bin/npm install --verbose --prefix $CRAFT_OVERLAY/usr/local/ --global terser
$CRAFT_OVERLAY/usr/bin/node $CRAFT_OVERLAY/usr/bin/npm install --verbose --prefix $CRAFT_OVERLAY/usr/local/ --global svgo
ruby_install_uri="https://github.com/postmodern/ruby-install/releases/download/v${RUBY_INSTALL_VERSION}/ruby-install-${RUBY_INSTALL_VERSION}.tar.gz"
curl -fLO $ruby_install_uri
tar -xzvf ruby-install-${RUBY_INSTALL_VERSION}.tar.gz
cd ruby-install-${RUBY_INSTALL_VERSION}/
make install
ruby-install --system ruby $RUBY_VERSION
cp -pR /usr/local/ ${CRAFT_OVERLAY}/usr/
discourse:
after: [tooling]
plugin: dump
after:
- install-yarn
- install-runtime-packages
source: https://github.com/discourse/discourse.git
source-depth: 1
source-tag: v2.8.14
source-tag: v3.1.3
source-type: git
override-build: |
craftctl default
Expand All @@ -84,53 +71,58 @@ parts:
mkdir -p public/uploads/default
mkdir -p log/production.log
mkdir -p srv/discourse/app/bin
mkdir -p srv/discourse/app/vendor/bundle
touch log/production.log
touch log/unicorn-stderr.log
yarn install --production --frozen-lockfile
# rexml version is forced to avoid conflicting transient dependency issue
sed -i 's/rexml (3.2.5)/rexml (3.2.6)/' Gemfile.lock
# The following is a fix for https://github.com/discourse/discourse-prometheus/blob/72fff206ba18ad5ca3112fed2f5f0ce6a17ca6f8/plugin.rb#L13C1-L13C105
sed -i "s/gem 'prometheus_exporter', .*/gem 'prometheus_exporter', '0.5.0'/g" Gemfile
organize:
"*.*": srv/discourse/app/
"*": srv/discourse/app/
".*": srv/discourse/app/
get-rad-plugin-source:
bundler-config:
plugin: dump
after: [discourse]
source: bundler
organize:
"*": srv/discourse/app/.bundle/
discourse-rad-plugin:
plugin: dump
after: [discourse, bundler-config]
source: https://github.com/canonical/discourse-rad-plugin.git
source-commit: 8612594e1bbbfbba7b9166d09c03b4a7fb4afbe9
source-depth: 1
after:
- get-discourse
organize:
"*": srv/discourse/app/plugins/discourse-rad-plugin/
get-solved-plugin-source:
discourse-solved:
plugin: dump
after: [discourse, bundler-config]
source: https://github.com/discourse/discourse-solved.git
source-commit: e6cce5486df906ede74aa1b17ab308a145a99b88
source-depth: 1
after:
- get-discourse
organize:
"*": srv/discourse/app/plugins/discourse-solved/
get-markdown-note-plugin-source:
discourse-markdown-note:
plugin: dump
after:
- get-discourse
after: [discourse, bundler-config]
source: https://github.com/canonical-web-and-design/discourse-markdown-note.git
source-commit: f4426d5929de067f123659dc690e9438a324817a
source-depth: 1
organize:
"*": srv/discourse/app/plugins/discourse-markdown-note/
get-mermaid-plugin-source:
"*": srv/discourse/app/plugins/markdown-note/
discourse-mermaid:
plugin: dump
after:
- get-discourse
after: [discourse, bundler-config]
source: https://github.com/unfoldingWord-dev/discourse-mermaid.git
source-commit: 341e1b08608ed0262bae6dffded2eddfae91f67a
source-depth: 1
organize:
"*": srv/discourse/app/plugins/discourse-mermaid/
get-saml-plugin-source:
discourse-saml:
plugin: dump
after:
- get-discourse
after: [discourse, bundler-config]
source: https://github.com/discourse/discourse-saml.git
source-commit: 15a8274bbec438768fb020d4f20462db476b0f29
source-depth: 1
Expand All @@ -139,10 +131,9 @@ parts:
grep -e ^gem plugin.rb >> Gemfile
organize:
"*": srv/discourse/app/plugins/discourse-saml/
get-prometheus-plugin-source:
discourse-prometheus:
plugin: dump
after:
- get-discourse
after: [discourse, bundler-config]
source: https://github.com/discourse/discourse-prometheus.git
source-commit: 72fff206ba18ad5ca3112fed2f5f0ce6a17ca6f8
source-depth: 1
Expand All @@ -151,84 +142,80 @@ parts:
grep -e ^gem plugin.rb >> Gemfile
organize:
"*": srv/discourse/app/plugins/discourse-prometheus/
get-data-explorer:
discourse-data-explorer:
plugin: dump
after:
- get-discourse
after: [discourse, bundler-config]
source: https://github.com/discourse/discourse-data-explorer.git
source-commit: e7c19ac107dcd37618c7ac7b98530e99c7fe31db
source-depth: 1
organize:
"*": srv/discourse/app/plugins/discourse-data-explorer/
get-patches:
patches:
plugin: dump
after: [discourse]
source: patches
organize:
"*": srv/discourse/app/patches/
apply-patches:
plugin: nil
build-packages:
- git
after:
- get-discourse
- get-patches
after: [discourse, patches]
override-stage: |
git -C srv/discourse/app apply patches/lp1903695.patch
git -C srv/discourse/app apply patches/anonymize_user.patch
# The following is a fix for UglifierJS assets compilation
# https://github.com/lautis/uglifier/issues/127#issuecomment-352224986
sed -i 's/config.assets.js_compressor = :uglifier/config.assets.js_compressor = Uglifier.new(:harmony => true)/g' srv/discourse/app/config/environments/production.rb
sed -i '1s/^/require "uglifier"\n/' srv/discourse/app/config/environments/production.rb
get-bundler-config:
scripts:
plugin: dump
source: bundler
source: scripts
organize:
"*": srv/discourse/app/.bundle/
install-gems:
"*": srv/scripts/
setup:
plugin: nil
after:
- get-discourse
- get-saml-plugin-source
- get-prometheus-plugin-source
- get-data-explorer
- apply-patches
- get-bundler-config
- bundler-config
- discourse
- discourse-data-explorer
- discourse-markdown-note
- discourse-mermaid
- discourse-prometheus
- discourse-rad-plugin
- discourse-saml
- discourse-solved
- patches
- scripts
- tooling
build-packages:
- libpq-dev
- ruby2.7
- ruby2.7-dev
- git
- libpq-dev
- libssl-dev
override-build: |
cd $CRAFT_STAGE/srv/discourse/app
gem install -n "bin" bundler
# rexml version is forced to avoid conflicting transient dependency issue
sed -i 's/rexml (3.2.5)/rexml (3.2.6)/' Gemfile.lock
# The following is a fix for https://github.com/discourse/discourse-prometheus/blob/72fff206ba18ad5ca3112fed2f5f0ce6a17ca6f8/plugin.rb#L13C1-L13C105
sed -i "s/gem 'prometheus_exporter', .*/gem 'prometheus_exporter', '0.5.0'/g" Gemfile
override-prime: |
cd srv/discourse/app
gem install -n "bin" bundler -v 2.4.13
bin/bundle install
bin/bundle install --gemfile="plugins/discourse-prometheus/Gemfile"
bin/bundle install --gemfile="plugins/discourse-saml/Gemfile"
organize:
'/var/lib/gems': var/lib/gems
'srv/discourse/app/bin/*': srv/discourse/app/bin/
'srv/discourse/app/Rakefile': srv/discourse/app/
'srv/discourse/app/bundle': srv/discourse/app/
get-scripts:
plugin: dump
source: scripts
organize:
"*": srv/scripts/
adjust-ownership:
bin/bundle install --gemfile="plugins/discourse-data-explorer/Gemfile"
bin/bundle install --gemfile="plugins/discourse-prometheus/Gemfile"
bin/bundle install --gemfile="plugins/discourse-solved/Gemfile"
yarn install --immutable
perms:
plugin: nil
after:
- get-markdown-note-plugin-source
- get-mermaid-plugin-source
- get-scripts
- get-rad-plugin-source
- get-solved-plugin-source
- install-gems
- install-terser
after: [tooling, discourse, setup]
override-prime: |
craftctl default
chown 584792 -R srv/discourse
chown -R 584792:584792 srv/discourse
mkdir -p var/lib/pebble/default/.npm
mkdir -p var/lib/pebble/default/.cache
mkdir -p var/lib/pebble/default/.config
mkdir -p var/lib/pebble/default/.local
mkdir -p var/lib/pebble/default/.yarn
touch var/lib/pebble/default/.yarnrc
chown -R 584792:584792 var/lib/pebble/default/.npm
chown -R 584792:584792 var/lib/pebble/default/.cache
chown -R 584792:584792 var/lib/pebble/default/.config
chown -R 584792:584792 var/lib/pebble/default/.local
chown -R 584792:584792 var/lib/pebble/default/.yarn
chown 584792:584792 var/lib/pebble/default/.yarnrc
2 changes: 0 additions & 2 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,6 @@ def _create_discourse_environment_settings(self) -> typing.Dict[str, str]:
"DISCOURSE_SMTP_PASSWORD": self.config["smtp_password"],
"DISCOURSE_SMTP_PORT": str(self.config["smtp_port"]),
"DISCOURSE_SMTP_USER_NAME": self.config["smtp_username"],
"GEM_HOME": "/var/lib/gems/2.7.0/",
"GEM_PATH": "/var/lib/gems/2.7.0/",
"RAILS_ENV": "production",
}
pod_config.update(self._get_saml_config())
Expand Down

0 comments on commit 2999154

Please sign in to comment.