From ba058cc560cbf42be07d7ff1988a3b94eb7e166a Mon Sep 17 00:00:00 2001 From: Niels Robin-Aubertin Date: Tue, 24 Oct 2023 16:13:08 -0400 Subject: [PATCH] Pin plugins to specific commits (#125) * Pin plugins to specific commits * Save lockfiles for plugins during image creation * Try to handle GEM_HOME issues * Revisit pinned commits, install all gems at the root of the app * Fixes * Moar fixes! * Add missing bundler config * Ignore license warning in bundler config for ROCK * Revert "feat(runners): Use edge runners (#119)" This reverts commit e712459d5bd3cc8719644faace867c8470300c56. * Fix rexml patch * Upgrade nodejs version --------- Co-authored-by: Tom Haddon --- .github/workflows/test.yaml | 3 --- .licenserc.yaml | 1 + discourse_rock/bundler/config | 6 ++++++ discourse_rock/rockcraft.yaml | 30 +++++++++++++++++++++++++----- src/charm.py | 3 ++- 5 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 discourse_rock/bundler/config diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index bd1426cc..ee5fa3ee 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -7,6 +7,3 @@ jobs: unit-tests: uses: canonical/operator-workflows/.github/workflows/test.yaml@main secrets: inherit - with: - self-hosted-runner: true - self-hosted-runner-label: "edge" diff --git a/.licenserc.yaml b/.licenserc.yaml index f83cb351..f407bdd4 100644 --- a/.licenserc.yaml +++ b/.licenserc.yaml @@ -32,6 +32,7 @@ header: - 'LICENSE' - 'trivy.yaml' - 'zap_rules.tsv' + - 'discourse_rock/bundler/config' - 'discourse_rock/patches/**' - 'lib/**' comment: on-failure diff --git a/discourse_rock/bundler/config b/discourse_rock/bundler/config new file mode 100644 index 00000000..ee993f0b --- /dev/null +++ b/discourse_rock/bundler/config @@ -0,0 +1,6 @@ +--- +BUNDLE_ALLOW_OFFLINE_INSTALL: "true" +BUNDLE_CACHE_ALL: "true" +BUNDLE_DISABLE_SHARED_GEMS: "true" +BUNDLE_FROZEN: "true" +BUNDLE_DISABLE_VERSION_CHECK: "true" diff --git a/discourse_rock/rockcraft.yaml b/discourse_rock/rockcraft.yaml index 2d8683fc..3afd898e 100644 --- a/discourse_rock/rockcraft.yaml +++ b/discourse_rock/rockcraft.yaml @@ -17,7 +17,7 @@ parts: plugin: nil source: . build-environment: - - NODE_VERSION: "18.17.1" + - 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" @@ -94,8 +94,8 @@ parts: get-solved-plugin-source: plugin: dump source: https://github.com/discourse/discourse-solved.git + source-commit: e6cce5486df906ede74aa1b17ab308a145a99b88 source-depth: 1 - source-commit: d6c8089ca38611b09a8edb29d64f359bcef11f11 after: - get-discourse organize: @@ -105,6 +105,7 @@ parts: after: - get-discourse 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/ @@ -113,6 +114,7 @@ parts: after: - get-discourse source: https://github.com/unfoldingWord-dev/discourse-mermaid.git + source-commit: 341e1b08608ed0262bae6dffded2eddfae91f67a source-depth: 1 organize: "*": srv/discourse/app/plugins/discourse-mermaid/ @@ -121,6 +123,7 @@ parts: after: - get-discourse source: https://github.com/discourse/discourse-saml.git + source-commit: 15a8274bbec438768fb020d4f20462db476b0f29 source-depth: 1 override-build: | craftctl default @@ -132,12 +135,22 @@ parts: after: - get-discourse source: https://github.com/discourse/discourse-prometheus.git + source-commit: 72fff206ba18ad5ca3112fed2f5f0ce6a17ca6f8 source-depth: 1 override-build: | craftctl default grep -e ^gem plugin.rb >> Gemfile organize: "*": srv/discourse/app/plugins/discourse-prometheus/ + get-data-explorer: + plugin: dump + after: + - get-discourse + 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: plugin: dump source: patches @@ -157,13 +170,20 @@ parts: # 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: + plugin: dump + source: bundler + organize: + "*": srv/discourse/app/.bundle/ install-gems: plugin: nil after: - get-discourse - get-saml-plugin-source - get-prometheus-plugin-source + - get-data-explorer - apply-patches + - get-bundler-config build-packages: - libpq-dev - ruby2.7 @@ -175,11 +195,11 @@ parts: 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 - # rexml version is forced to avoid conflicting transient dependency issue - echo "gem 'rexml', '3.2.6'" >> Gemfile + # 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 bin/bundle install - bin/bundle install --gemfile="plugins/discourse-saml/Gemfile" 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/ diff --git a/src/charm.py b/src/charm.py index 3dac77ca..ca02a418 100755 --- a/src/charm.py +++ b/src/charm.py @@ -353,7 +353,8 @@ 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_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())