From b9a66d9e03f6c84ac0a2d1167c7bfe6354cd3e64 Mon Sep 17 00:00:00 2001 From: Niels Robin-Aubertin Date: Thu, 14 Sep 2023 10:00:51 -0400 Subject: [PATCH] Create a rockfile to replace the current Dockerfile (#75) * Add rockfile and adapt the charm for it * Try to separate tests as before * Revert to the old way of running the tests with secrets * Build rockcraft image for integ tests w/ secrets * Switch to operator-workflow again * Re-run CI * Try to pass secrets as args * Revert "Try to pass secrets as args" This reverts commit a32e7fa3965f8d1596590e61f9a761c267c2f7fd. * Change name of default integ tests workflow * Improve rockfile * Add some comments to the rockfile * Use run-user _daemon_ * Use the discourse-prometheus plugin * Remove remaining dockerfile from merge --- .../integration_test_with_secrets.yaml | 49 ++--- .gitignore | 1 + .licenserc.yaml | 2 +- discourse.Dockerfile | 112 ---------- .../patches/anonymize_user.patch | 0 .../patches/lp1903695.patch | 0 discourse_rock/rockcraft.yaml | 204 ++++++++++++++++++ .../scripts/app_launch.sh | 4 +- src/charm.py | 19 +- tests/integration/conftest.py | 4 +- tests/unit/test_charm.py | 16 +- 11 files changed, 240 insertions(+), 171 deletions(-) delete mode 100644 discourse.Dockerfile rename {image => discourse_rock}/patches/anonymize_user.patch (100%) rename {image => discourse_rock}/patches/lp1903695.patch (100%) create mode 100644 discourse_rock/rockcraft.yaml rename {image => discourse_rock}/scripts/app_launch.sh (67%) diff --git a/.github/workflows/integration_test_with_secrets.yaml b/.github/workflows/integration_test_with_secrets.yaml index ab8ccf92..10ae1000 100644 --- a/.github/workflows/integration_test_with_secrets.yaml +++ b/.github/workflows/integration_test_with_secrets.yaml @@ -4,40 +4,15 @@ on: pull_request: jobs: - integration-test-with-secrets: - runs-on: ubuntu-latest - name: Integration Tests (require secrets) - steps: - - uses: actions/checkout@v4 - - - name: Setup operator environment - uses: charmed-kubernetes/actions-operator@main - with: - provider: microk8s - - - name: Enable microk8s plugins - run: | - sudo microk8s enable hostpath-storage ingress registry - sudo microk8s kubectl -n kube-system rollout status -w deployment/hostpath-provisioner - sudo microk8s kubectl -n ingress rollout status -w daemonset.apps/nginx-ingress-microk8s-controller - sudo microk8s kubectl -n container-registry rollout status -w deployment/registry - - - name: Install tox - run: python3 -m pip install tox - - - name: Config iptables - run: | - sudo iptables -I DOCKER-USER -j ACCEPT - - - name: Build docker image - run: | - docker build -f discourse.Dockerfile -t localhost:32000/discourse:test . - docker push localhost:32000/discourse:test - - - name: Run integration tests - run: | - tox -e integration -- \ - -m requires_secrets \ - --saml-email ${{ secrets.TEST_SAML_EMAIL }} \ - --saml-password ${{ secrets.TEST_SAML_PASSWORD }} \ - --discourse-image=localhost:32000/discourse:test + integration-tests-with-secrets: + uses: canonical/operator-workflows/.github/workflows/integration_test.yaml@main + secrets: inherit + with: + chaos-app-label: app.kubernetes.io/name=discourse-k8s + chaos-duration: 600 + chaos-enabled: false + chaos-experiments: pod-delete + chaos-status-duration: 300 + extra-arguments: --localstack-address 172.17.0.1 -m "requires_secrets" + pre-run-script: localstack-installation.sh + trivy-image-config: "trivy.yaml" diff --git a/.gitignore b/.gitignore index d680bd7a..b3ed3272 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ venv env .pytest_cache .mypy_cache +*.rock diff --git a/.licenserc.yaml b/.licenserc.yaml index 2e85f8d1..f83cb351 100644 --- a/.licenserc.yaml +++ b/.licenserc.yaml @@ -32,6 +32,6 @@ header: - 'LICENSE' - 'trivy.yaml' - 'zap_rules.tsv' - - 'image/patches/**' + - 'discourse_rock/patches/**' - 'lib/**' comment: on-failure diff --git a/discourse.Dockerfile b/discourse.Dockerfile deleted file mode 100644 index a1098076..00000000 --- a/discourse.Dockerfile +++ /dev/null @@ -1,112 +0,0 @@ -# Copyright 2023 Canonical Ltd. -# See LICENSE file for licensing details. -FROM ubuntu:focal - -# Used in Launchpad OCI Recipe build to tag the image. -LABEL org.label-schema.version=v2.8.14 - -# Copy any args we got into the environment. -ENV CONTAINER_APP_VERSION v2.8.14 -ENV CONTAINER_APP_USERNAME discourse -ENV CONTAINER_APP_UID 200 -ENV CONTAINER_APP_GROUP discourse -ENV CONTAINER_APP_GID 200 - -# CONTAINER_APP_ROOT is where files related to this application go. -ENV CONTAINER_APP_ROOT=/srv/discourse -ENV GEM_HOME ${CONTAINER_APP_ROOT}/.gem - -# We don't want packages prompting us during install. -ENV DEBIAN_FRONTEND=noninteractive - -RUN ln -s /usr/share/zoneinfo/UTC /etc/localtime \ - && addgroup --gid "${CONTAINER_APP_GID}" "${CONTAINER_APP_GROUP}" \ - && adduser --uid "${CONTAINER_APP_UID}" --home "${CONTAINER_APP_ROOT}" --gid "${CONTAINER_APP_GID}" --system "${CONTAINER_APP_USERNAME}" \ - && apt-get update \ - && apt-get install -y brotli \ - curl \ - gettext-base \ - gifsicle \ - git \ - imagemagick \ - jhead \ - jpegoptim \ - libjpeg-turbo-progs \ - libpq-dev \ - libssl-dev \ - libxml2-dev \ - libxslt1-dev \ - libz-dev \ - optipng \ - pngquant \ - postgresql-client \ - postgresql-client-common \ - redis-tools \ - ruby2.7 \ - ruby2.7-dev \ - tzdata \ - ubuntu-dev-tools \ - zlib1g-dev \ - && curl --silent --location https://deb.nodesource.com/setup_18.x | bash - \ - && apt-get update \ - && apt-get install -y nodejs \ - && rm -rf /var/lib/apt/lists/* \ - && npm install -g terser uglify-js pnpm yarn \ - && git -C "${CONTAINER_APP_ROOT}" clone --depth 1 --branch "${CONTAINER_APP_VERSION}" https://github.com/discourse/discourse.git app - -# Apply patches -# https://github.com/discourse/discourse/pull/20522 -# https://github.com/discourse/discourse/pull/20523 LP#1903695 -COPY image/patches /srv/patches -RUN git -C "${CONTAINER_APP_ROOT}/app" apply /srv/patches/lp1903695.patch \ - && git -C "${CONTAINER_APP_ROOT}/app" apply /srv/patches/anonymize_user.patch \ - && rm -rf /srv/patches \ - && mkdir -p "${CONTAINER_APP_ROOT}/.gem" \ -# Create the backup and upload directories as Discourse doesn't like it -# when they are missing and won't auto-create them at runtime - && mkdir -p "${CONTAINER_APP_ROOT}/app/tmp/backups/default" \ - && mkdir -p "${CONTAINER_APP_ROOT}/app/public/backups/default" \ - && mkdir -p "${CONTAINER_APP_ROOT}/app/public/uploads/default" \ - && touch "${CONTAINER_APP_ROOT}/app/log/production.log" \ - && touch "${CONTAINER_APP_ROOT}/app/log/unicorn-stderr.log" \ - && chown -R "${CONTAINER_APP_USERNAME}:${CONTAINER_APP_GROUP}" "${CONTAINER_APP_ROOT}" \ -# This must be done as the discourse user in order to avoid permission -# problems later. - && su -s /bin/bash -c 'gem install bundler' "${CONTAINER_APP_USERNAME}" \ - && su -s /bin/bash -c '${CONTAINER_APP_ROOT}/app/bin/bundle install' "${CONTAINER_APP_USERNAME}" \ -# If intermediate files are generated by the build process or other files are -# generated that are not needed at runtime, remove them here to save image size. -# If we don't do this they will become part of the image even if removed later. - && find "${CONTAINER_APP_ROOT}" -name tmp -type d -exec rm -rf {} + \ - && apt-get autoremove \ - && apt-get clean - -RUN su -s /bin/bash -c 'yarn --cwd ${CONTAINER_APP_ROOT}/app install --production --frozen-lockfile' \ - && su -s /bin/bash -c 'yarn --cwd ${CONTAINER_APP_ROOT}/app cache clean' "${CONTAINER_APP_USERNAME}" - -# Copy run-time scripts into the container. -COPY --chown="${CONTAINER_APP_UID}:${CONTAINER_APP_GID}" image/scripts /srv/scripts - -ENV PLUGINS_DIR="${CONTAINER_APP_ROOT}/app/plugins" -RUN git clone https://github.com/discourse/discourse-saml.git "${PLUGINS_DIR}/discourse-saml" \ - && git clone https://github.com/discourse/discourse-solved.git "${PLUGINS_DIR}/discourse-solved" \ -# Checkout commit prior to migration error introduced by renaming a variable in 882dd61e11f9bab8e99510296938b0cdbc3269c4 - && git -C "${PLUGINS_DIR}/discourse-solved" reset --hard d6c8089ca38611b09a8edb29d64f359bcef11f11 \ - && git clone https://github.com/canonical-web-and-design/discourse-markdown-note.git "${PLUGINS_DIR}/discourse-markdown-note" \ - && git clone https://github.com/unfoldingWord-dev/discourse-mermaid.git "${PLUGINS_DIR}/discourse-mermaid" \ - && git clone https://github.com/discourse/discourse-prometheus.git "${PLUGINS_DIR}/discourse-prometheus" \ - && mkdir -p "${PLUGINS_DIR}/discourse-saml/gems" \ - && mkdir -p "${PLUGINS_DIR}/discourse-prometheus/gems" \ - && chown -R "${CONTAINER_APP_USERNAME}:${CONTAINER_APP_GROUP}" "${PLUGINS_DIR}" \ -# Have to determine the gems needed and install them now, otherwise Discourse will -# try to install them at runtime, which may not work due to network access issues. - && su -s /bin/bash -c 'gem install bundler' "${CONTAINER_APP_USERNAME}" \ - && grep -e ^gem "${PLUGINS_DIR}/discourse-saml/plugin.rb" >> "${PLUGINS_DIR}/discourse-saml/Gemfile" \ - && su -s /bin/bash -c '${CONTAINER_APP_ROOT}/app/bin/bundle install --gemfile=${PLUGINS_DIR}/discourse-saml/Gemfile --path=${PLUGINS_DIR}/discourse-saml/gems' "${CONTAINER_APP_USERNAME}" \ - && ln -s "${PLUGINS_DIR}/discourse-saml/gems/ruby/"* "${PLUGINS_DIR}/discourse-saml/gems/" \ - && grep -e ^gem "${PLUGINS_DIR}/discourse-prometheus/plugin.rb" >> "${PLUGINS_DIR}/discourse-prometheus/Gemfile" \ - && su -s /bin/bash -c '${CONTAINER_APP_ROOT}/app/bin/bundle install --gemfile=${PLUGINS_DIR}/discourse-prometheus/Gemfile --path=${PLUGINS_DIR}/discourse-prometheus/gems' "${CONTAINER_APP_USERNAME}" \ - && ln -s "${PLUGINS_DIR}/discourse-prometheus/gems/ruby/"* "${PLUGINS_DIR}/discourse-prometheus/gems/" \ - && sed -i 's/rexml (3.2.5)/rexml (3.2.6)/' "${CONTAINER_APP_ROOT}/app/Gemfile.lock" \ - && echo "gem 'rexml', '3.2.6'" >> "${CONTAINER_APP_ROOT}/app/Gemfile" \ - && su -s /bin/bash -c '${CONTAINER_APP_ROOT}/app/bin/bundle install' "${CONTAINER_APP_USERNAME}" diff --git a/image/patches/anonymize_user.patch b/discourse_rock/patches/anonymize_user.patch similarity index 100% rename from image/patches/anonymize_user.patch rename to discourse_rock/patches/anonymize_user.patch diff --git a/image/patches/lp1903695.patch b/discourse_rock/patches/lp1903695.patch similarity index 100% rename from image/patches/lp1903695.patch rename to discourse_rock/patches/lp1903695.patch diff --git a/discourse_rock/rockcraft.yaml b/discourse_rock/rockcraft.yaml new file mode 100644 index 00000000..2d8683fc --- /dev/null +++ b/discourse_rock/rockcraft.yaml @@ -0,0 +1,204 @@ +# Copyright 2023 Canonical Ltd. +# See LICENSE file for licensing details. + +name: discourse +summary: Discourse rock +description: Discourse OCI image for the Discourse charm +base: ubuntu:20.04 +run-user: _daemon_ +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.17.1" + - 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: + plugin: nil + overlay-packages: + - brotli + - gettext-base + - gifsicle + - git + - imagemagick + - jhead + - jpegoptim + - libjpeg-turbo-progs + - libpq-dev + - libssl-dev + - libxml2-dev + - libxslt1-dev + - libz-dev + - optipng + - pngquant + - redis-tools + - ruby2.7 + - ruby2.7-dev + - tzdata + - ubuntu-dev-tools + - zlib1g-dev + get-discourse: + plugin: dump + after: + - install-yarn + - install-runtime-packages + source: https://github.com/discourse/discourse.git + source-depth: 1 + source-tag: v2.8.14 + source-type: git + override-build: | + craftctl default + mkdir -p tmp/backups/default + mkdir -p public/backups/default + mkdir -p public/uploads/default + mkdir -p log/production.log + mkdir -p srv/discourse/app/bin + touch log/production.log + touch log/unicorn-stderr.log + yarn install --production --frozen-lockfile + organize: + "*.*": srv/discourse/app/ + "*": srv/discourse/app/ + ".*": srv/discourse/app/ + get-solved-plugin-source: + plugin: dump + source: https://github.com/discourse/discourse-solved.git + source-depth: 1 + source-commit: d6c8089ca38611b09a8edb29d64f359bcef11f11 + after: + - get-discourse + organize: + "*": srv/discourse/app/plugins/discourse-solved/ + get-markdown-note-plugin-source: + plugin: dump + after: + - get-discourse + source: https://github.com/canonical-web-and-design/discourse-markdown-note.git + source-depth: 1 + organize: + "*": srv/discourse/app/plugins/discourse-markdown-note/ + get-mermaid-plugin-source: + plugin: dump + after: + - get-discourse + source: https://github.com/unfoldingWord-dev/discourse-mermaid.git + source-depth: 1 + organize: + "*": srv/discourse/app/plugins/discourse-mermaid/ + get-saml-plugin-source: + plugin: dump + after: + - get-discourse + source: https://github.com/discourse/discourse-saml.git + source-depth: 1 + override-build: | + craftctl default + grep -e ^gem plugin.rb >> Gemfile + organize: + "*": srv/discourse/app/plugins/discourse-saml/ + get-prometheus-plugin-source: + plugin: dump + after: + - get-discourse + source: https://github.com/discourse/discourse-prometheus.git + source-depth: 1 + override-build: | + craftctl default + grep -e ^gem plugin.rb >> Gemfile + organize: + "*": srv/discourse/app/plugins/discourse-prometheus/ + get-patches: + plugin: dump + source: patches + organize: + "*": srv/discourse/app/patches/ + apply-patches: + plugin: nil + build-packages: + - git + after: + - get-discourse + - get-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 + install-gems: + plugin: nil + after: + - get-discourse + - get-saml-plugin-source + - get-prometheus-plugin-source + - apply-patches + build-packages: + - libpq-dev + - ruby2.7 + - ruby2.7-dev + - git + - 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 + # rexml version is forced to avoid conflicting transient dependency issue + echo "gem 'rexml', '3.2.6'" >> Gemfile + bin/bundle install + bin/bundle install --gemfile="plugins/discourse-saml/Gemfile" + bin/bundle install --gemfile="plugins/discourse-prometheus/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: + plugin: nil + after: + - get-markdown-note-plugin-source + - get-mermaid-plugin-source + - get-scripts + - get-solved-plugin-source + - install-gems + - install-terser + override-prime: | + craftctl default + chown 584792 -R srv/discourse diff --git a/image/scripts/app_launch.sh b/discourse_rock/scripts/app_launch.sh similarity index 67% rename from image/scripts/app_launch.sh rename to discourse_rock/scripts/app_launch.sh index 9ee6a953..ac706185 100755 --- a/image/scripts/app_launch.sh +++ b/discourse_rock/scripts/app_launch.sh @@ -5,7 +5,9 @@ export UNICORN_BIND_ALL=0.0.0.0 export UNICORN_SIDEKIQS=1 -su -s /bin/bash -c "${CONTAINER_APP_ROOT}/app/bin/unicorn -c ${CONTAINER_APP_ROOT}/app/config/unicorn.conf.rb" "${CONTAINER_APP_USERNAME}" & +cd "$CONTAINER_APP_ROOT/app" || exit + +bin/unicorn -c config/unicorn.conf.rb & # If one of the processes exits, the other one will be killed so that the pod will be restarted by the failing probes wait -n diff --git a/src/charm.py b/src/charm.py index 3fb7221b..afa2c868 100755 --- a/src/charm.py +++ b/src/charm.py @@ -8,7 +8,6 @@ import typing from collections import defaultdict, namedtuple -import ops import ops.lib from charms.data_platform_libs.v0.data_interfaces import ( DatabaseCreatedEvent, @@ -330,7 +329,7 @@ def _create_discourse_environment_settings(self) -> typing.Dict[str, str]: # I need to take the required envVars for the application to work properly "CONTAINER_APP_NAME": "discourse", "CONTAINER_APP_ROOT": "/srv/discourse", - "CONTAINER_APP_USERNAME": "discourse", + "CONTAINER_APP_USERNAME": "_daemon_", "DISCOURSE_CORS_ORIGIN": self.config["cors_origin"], "DISCOURSE_DB_HOST": database_relation_data["POSTGRES_HOST"], "DISCOURSE_DB_NAME": database_relation_data["POSTGRES_DB"], @@ -350,7 +349,7 @@ 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": "/srv/discourse/.gem", + "GEM_HOME": "/var/lib/gems/2.7.0", "RAILS_ENV": "production", } pod_config.update(self._get_saml_config()) @@ -462,7 +461,7 @@ def _set_up_discourse(self, event: HookEvent) -> None: [f"{DISCOURSE_PATH}/bin/bundle", "exec", "rake", "--trace", "db:migrate"], environment=env_settings, working_dir=DISCOURSE_PATH, - user="discourse", + user="_daemon_", ) migration_process.wait_output() self.model.unit.status = MaintenanceStatus("Compiling assets") @@ -470,7 +469,7 @@ def _set_up_discourse(self, event: HookEvent) -> None: [f"{DISCOURSE_PATH}/bin/bundle", "exec", "rake", "assets:precompile"], environment=env_settings, working_dir=DISCOURSE_PATH, - user="discourse", + user="_daemon_", ) precompile_process.wait_output() self._set_setup_completed() @@ -478,7 +477,7 @@ def _set_up_discourse(self, event: HookEvent) -> None: [f"{DISCOURSE_PATH}/bin/rails", "runner", "puts Discourse::VERSION::STRING"], environment=env_settings, working_dir=DISCOURSE_PATH, - user="discourse", + user="_daemon_", ) version, _ = get_version_process.wait_output() self.unit.set_workload_version(version) @@ -524,7 +523,7 @@ def _config_changed(self, event: HookEvent) -> None: [f"{DISCOURSE_PATH}/bin/bundle", "exec", "rake", "s3:upload_assets"], environment=env_settings, working_dir=DISCOURSE_PATH, - user="discourse", + user="_daemon_", ) process.wait_output() except ExecError as cmd_err: @@ -569,8 +568,8 @@ def _on_add_admin_user_action(self, event: ActionEvent) -> None: "admin:create", ], stdin=f"{email}\n{password}\n{password}\nY\n", - user="discourse", working_dir=DISCOURSE_PATH, + user="_daemon_", environment=self._create_discourse_environment_settings(), timeout=60, ) @@ -595,8 +594,8 @@ def _config_force_https(self) -> None: "runner", f"SiteSetting.force_https={force_bool}", ], - user="discourse", working_dir=DISCOURSE_PATH, + user="_daemon_", environment=self._create_discourse_environment_settings(), ) process.wait_output() @@ -616,8 +615,8 @@ def _on_anonymize_user_action(self, event: ActionEvent) -> None: "-c", f"./bin/bundle exec rake users:anonymize[{username}]", ], - user="discourse", working_dir=DISCOURSE_PATH, + user="_daemon_", environment=self._create_discourse_environment_settings(), ) try: diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 4c7d1842..c30b04ed 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -178,7 +178,7 @@ async def app_fixture( "plugin_pg_trgm_enable": "true", } ) - await model.wait_for_idle(apps=[postgres_app.name], status="active") + await model.wait_for_idle(apps=[postgres_app.name], status="active", raise_on_error=False) # Add required relations unit = model.applications[app_name].units[0] @@ -188,7 +188,7 @@ async def app_fixture( model.add_relation(app_name, "redis-k8s"), model.add_relation(app_name, "nginx-ingress-integrator"), ) - await model.wait_for_idle(status="active") + await model.wait_for_idle(status="active", raise_on_error=False) yield application diff --git a/tests/unit/test_charm.py b/tests/unit/test_charm.py index 54be8526..0e2f8560 100644 --- a/tests/unit/test_charm.py +++ b/tests/unit/test_charm.py @@ -275,7 +275,7 @@ def test_config_changed_when_valid_no_s3_backup_nor_cdn(self): [f"{DISCOURSE_PATH}/bin/bundle", "exec", "rake", "s3:upload_assets"], environment=self.harness._charm._create_discourse_environment_settings(), working_dir=DISCOURSE_PATH, - user="discourse", + user="_daemon_", ) updated_plan = self.harness.get_container_pebble_plan("discourse").to_dict() updated_plan_env = updated_plan["services"]["discourse"]["environment"] @@ -469,8 +469,8 @@ def test_add_admin_user(self, mock_exec): "rake", "admin:create", ], - user="discourse", working_dir=DISCOURSE_PATH, + user="_daemon_", environment=charm._create_discourse_environment_settings(), stdin=f"{email}\n{password}\n{password}\nY\n", timeout=60, @@ -496,8 +496,8 @@ def test_anonymize_user(self, mock_exec): "-c", f"./bin/bundle exec rake users:anonymize[{username}]", ], - user="discourse", working_dir=DISCOURSE_PATH, + user="_daemon_", environment=charm._create_discourse_environment_settings(), ) @@ -519,19 +519,19 @@ def test_install_when_leader(self): [f"{DISCOURSE_PATH}/bin/bundle", "exec", "rake", "--trace", "db:migrate"], environment=updated_plan_env, working_dir=DISCOURSE_PATH, - user="discourse", + user="_daemon_", ) mock_exec.assert_any_call( [f"{DISCOURSE_PATH}/bin/bundle", "exec", "rake", "assets:precompile"], environment=updated_plan_env, working_dir=DISCOURSE_PATH, - user="discourse", + user="_daemon_", ) mock_exec.assert_any_call( [f"{DISCOURSE_PATH}/bin/rails", "runner", "puts Discourse::VERSION::STRING"], environment=updated_plan_env, working_dir=DISCOURSE_PATH, - user="discourse", + user="_daemon_", ) def test_install_when_not_leader(self): @@ -552,13 +552,13 @@ def test_install_when_not_leader(self): [f"{DISCOURSE_PATH}/bin/bundle", "exec", "rake", "assets:precompile"], environment=updated_plan_env, working_dir=DISCOURSE_PATH, - user="discourse", + user="_daemon_", ) mock_exec.assert_any_call( [f"{DISCOURSE_PATH}/bin/rails", "runner", "puts Discourse::VERSION::STRING"], environment=updated_plan_env, working_dir=DISCOURSE_PATH, - user="discourse", + user="_daemon_", ) def _add_postgres_relation(self):