diff --git a/.simplecov b/.simplecov index 49889aa450..fcb17c2de8 100644 --- a/.simplecov +++ b/.simplecov @@ -7,6 +7,7 @@ SimpleCov.start "rails" do add_filter "lib/tasks/helpers/cfe_payload_recorder.rb" add_filter "lib/tasks/helpers/cy_helper.rb" add_filter "lib/utilities/redis_scanner.rb" + add_filter "app/jobs/test_mail_job.rb" enable_coverage :branch diff --git a/app/jobs/test_mail_job.rb b/app/jobs/test_mail_job.rb new file mode 100644 index 0000000000..e5bb65aeed --- /dev/null +++ b/app/jobs/test_mail_job.rb @@ -0,0 +1,19 @@ +class TestMailJob + include Sidekiq::Worker + sidekiq_options queue: :default + + CLIENT_CONFIRMATION_EMAIL = "3b18efe5-7d09-4042-927c-7d1ae03fdd7e".freeze + + def perform(email, name) + client = Notifications::Client.new(Rails.configuration.x.govuk_notify_api_key) + + client.send_email( + email_address: email, + template_id: CLIENT_CONFIRMATION_EMAIL, + personalisation: { + client_name: name, + ref_number: "testing-whatever", + }, + ) + end +end diff --git a/config/application.rb b/config/application.rb index 9ea61db7bd..97bba71407 100644 --- a/config/application.rb +++ b/config/application.rb @@ -142,7 +142,16 @@ class Application < Rails::Application production: [], } - config.x.redis.base_url = ENV["REDIS_HOST"].present? && ENV["REDIS_PASSWORD"].present? ? "rediss://:#{ENV.fetch('REDIS_PASSWORD', nil)}@#{ENV.fetch('REDIS_HOST', nil)}:6379" : "redis://localhost:6379" + redis_protocol = ENV.fetch("REDIS_PROTOCOL", "rediss") + redis_password = ENV.fetch("REDIS_PASSWORD", nil) + redis_host = ENV.fetch("REDIS_HOST", nil) + + redis_url = if redis_host.present? && redis_password.present? + "#{redis_protocol}://:#{redis_password}@#{redis_host}:6379" + else + "redis://localhost:6379" + end + config.x.redis.base_url = redis_url config.x.redis.page_history_url = "#{config.x.redis.base_url}/1" config.x.redis.oauth_session_url = "#{config.x.redis.base_url}/2" config.x.redis.rack_attack_url = "#{config.x.redis.base_url}/3" diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb index ce03f2251b..dc353d30a7 100644 --- a/config/initializers/sidekiq.rb +++ b/config/initializers/sidekiq.rb @@ -3,20 +3,26 @@ require "prometheus_exporter/client" require "prometheus_exporter/instrumentation" -redis_url = "rediss://:#{ENV.fetch('REDIS_PASSWORD', nil)}@#{ENV.fetch('REDIS_HOST', nil)}:6379" if ENV["REDIS_HOST"].present? && ENV["REDIS_PASSWORD"].present? +redis_url = Rails.configuration.x.redis.base_url namespace = ENV.fetch("HOST", "laa-apply") module Dashboard; end Sidekiq.configure_client do |config| - config.redis = { url: redis_url, namespace: } if redis_url + config.redis = { url: redis_url } if redis_url # accepts :expiration (optional) Sidekiq::Status.configure_client_middleware config, expiration: 30.minutes end Sidekiq.configure_server do |config| - config.redis = { url: redis_url, namespace: } if redis_url + if redis_url + config.redis = if ENV.fetch("NAMEPSPACED_SIDEKIQ_DRAINER", nil) + { url: redis_url, namespace: } # continue to poll for old scheduled jobs and retries + else + { url: redis_url } + end + end # accepts :expiration (optional) Sidekiq::Status.configure_server_middleware config, expiration: 30.minutes diff --git a/helm_deploy/apply-for-legal-aid/Chart.lock b/helm_deploy/apply-for-legal-aid/Chart.lock index dede4da068..7b6a450057 100644 --- a/helm_deploy/apply-for-legal-aid/Chart.lock +++ b/helm_deploy/apply-for-legal-aid/Chart.lock @@ -2,5 +2,8 @@ dependencies: - name: postgresql repository: https://charts.bitnami.com/bitnami version: 11.9.13 -digest: sha256:63f0418b276607f2047c1ea7d149ac904de530404e74ef4f7558da6f645137b9 -generated: "2023-02-20T17:20:40.628833Z" +- name: redis + repository: https://charts.bitnami.com/bitnami + version: 16.13.2 +digest: sha256:334d2a8d2b464929a6c9534bdd4efb53e3f1c9a9a3f172c7851286dcfeda53fd +generated: "2023-10-13T14:00:08.90648+01:00" diff --git a/helm_deploy/apply-for-legal-aid/Chart.yaml b/helm_deploy/apply-for-legal-aid/Chart.yaml index 5edefa56e6..bb59f4082a 100644 --- a/helm_deploy/apply-for-legal-aid/Chart.yaml +++ b/helm_deploy/apply-for-legal-aid/Chart.yaml @@ -1,3 +1,5 @@ +# see https://levelup.gitconnected.com/helm-dependencies-1907facbe410 +# for decent documentation. apiVersion: v2 name: apply-for-legal-aid description: A Helm chart for Kubernetes @@ -15,15 +17,19 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.2.0 +version: 0.3.0 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to # follow Semantic Versioning. They should reflect the version the application is using. -appVersion: 1.17.0 +appVersion: 1.18.0 dependencies: - name: postgresql version: ^11.0.0 condition: postgresql.enabled repository: https://charts.bitnami.com/bitnami + - name: redis + version: ^16.0.0 # redis 6.x.x + condition: redis.enabled + repository: https://charts.bitnami.com/bitnami diff --git a/helm_deploy/apply-for-legal-aid/charts/redis-16.13.2.tgz b/helm_deploy/apply-for-legal-aid/charts/redis-16.13.2.tgz new file mode 100644 index 0000000000..33b5e967b8 Binary files /dev/null and b/helm_deploy/apply-for-legal-aid/charts/redis-16.13.2.tgz differ diff --git a/helm_deploy/apply-for-legal-aid/templates/_envs.tpl b/helm_deploy/apply-for-legal-aid/templates/_envs.tpl index 18ce1a452a..ebe08c2bfc 100644 --- a/helm_deploy/apply-for-legal-aid/templates/_envs.tpl +++ b/helm_deploy/apply-for-legal-aid/templates/_envs.tpl @@ -220,6 +220,17 @@ env: secretKeyRef: name: {{ template "apply-for-legal-aid.fullname" . }} key: sidekiqWebUiPassword + {{ if .Values.redis.enabled }} + - name: REDIS_PROTOCOL + value: "redis" + - name: REDIS_HOST + value: {{ template "apply-for-legal-aid.redis-uat-host" . }} + - name: REDIS_PASSWORD + valueFrom: + secretKeyRef: + name: {{ template "apply-for-legal-aid.fullname" . }} + key: redisPassword + {{ else }} - name: REDIS_HOST valueFrom: secretKeyRef: @@ -230,6 +241,7 @@ env: secretKeyRef: name: apply-for-legal-aid-elasticache-instance-output key: auth_token + {{ end }} - name: S3_BUCKET valueFrom: secretKeyRef: diff --git a/helm_deploy/apply-for-legal-aid/templates/_helpers.tpl b/helm_deploy/apply-for-legal-aid/templates/_helpers.tpl index b1c148aee2..4aa29b957e 100644 --- a/helm_deploy/apply-for-legal-aid/templates/_helpers.tpl +++ b/helm_deploy/apply-for-legal-aid/templates/_helpers.tpl @@ -46,3 +46,20 @@ https://pauladamsmith.com/blog/2011/05/go_time.html {{ "* * * * *" }} {{- end -}} {{- end -}} + +{{/* +Function to return the name for a UAT redis chart master node host +This duplicates bitnami/redis chart's internal logic whereby +If branch name contains "redis" then the redis-release-name appends "-master", otherwise it appends "-redis-master" +*/}} +{{- define "apply-for-legal-aid.redis-uat-host" -}} + {{- $redis_chart_name := "redis" -}} + + {{- if contains $redis_chart_name .Release.Name -}} + {{- $redis_release_name := (.Release.Name | trunc 63 | trimSuffix "-") -}} + {{- printf "%s-master.%s.svc.cluster.local" $redis_release_name .Release.Namespace -}} + {{- else -}} + {{- $redis_release_name := (printf "%s-%s" .Release.Name $redis_chart_name | trunc 63 | trimSuffix "-") -}} + {{- printf "%s-master.%s.svc.cluster.local" $redis_release_name .Release.Namespace -}} + {{- end -}} +{{- end -}} diff --git a/helm_deploy/apply-for-legal-aid/templates/deployment_drainer.yaml b/helm_deploy/apply-for-legal-aid/templates/deployment_drainer.yaml new file mode 100644 index 0000000000..6ec124a944 --- /dev/null +++ b/helm_deploy/apply-for-legal-aid/templates/deployment_drainer.yaml @@ -0,0 +1,59 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ template "apply-for-legal-aid.fullname" . }}-drainer + labels: + app: {{ template "apply-for-legal-aid.name" . }} + chart: {{ template "apply-for-legal-aid.chart" . }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +spec: + replicas: {{ .Values.worker.replicaCount }} + strategy: + type: RollingUpdate + rollingUpdate: + maxUnavailable: 0 + maxSurge: 100% + selector: + matchLabels: + app: {{ template "apply-for-legal-aid.name" . }}-drainer + release: {{ .Release.Name }} + template: + metadata: + labels: + app: {{ template "apply-for-legal-aid.name" . }}-drainer + release: {{ .Release.Name }} + spec: + serviceAccountName: "{{ .Values.service_account.name }}" + containers: + - name: drainer + image: '{{ .Values.image.repository }}:{{ .Values.image.tag }}' + imagePullPolicy: IfNotPresent + command: ['bundle', 'exec', 'sidekiq'] +{{ include "apply-for-legal-aid.envs" . | nindent 10 }} + - name: NAMEPSPACED_SIDEKIQ_DRAINER + value: "true" + resources: + limits: + cpu: 500m + memory: 1Gi + requests: + cpu: 10m + memory: 512Mi + ports: + - containerPort: 7433 + livenessProbe: + exec: + command: ['bin/sidekiq_health_check'] + initialDelaySeconds: 60 + timeoutSeconds: 5 + readinessProbe: + exec: + command: ['bin/sidekiq_health_check'] + initialDelaySeconds: 60 + timeoutSeconds: 5 + lifecycle: + preStop: + exec: + command: ['bundle', 'exec', 'sidekiqctl', 'quiet'] + terminationGracePeriodSeconds: 60 diff --git a/helm_deploy/apply-for-legal-aid/templates/secret.yaml b/helm_deploy/apply-for-legal-aid/templates/secret.yaml index b501b2ab08..89b297935e 100644 --- a/helm_deploy/apply-for-legal-aid/templates/secret.yaml +++ b/helm_deploy/apply-for-legal-aid/templates/secret.yaml @@ -11,6 +11,9 @@ data: postgresqlUsername: {{ .Values.postgresql.postgresqlUsername | b64enc | quote }} postgresqlPassword: {{ .Values.postgresql.auth.postgresPassword | b64enc | quote }} {{ end }} + {{if .Values.redis.enabled }} + redisPassword: {{ .Values.redis.auth.password | b64enc | quote }} + {{ end }} sentryDsn: {{ .Values.sentry.dsn | b64enc | quote }} govukNotifyApiKey: {{ .Values.govuk_notify.api_key | b64enc | quote }} ordnanceSurveyApiKey: {{ .Values.ordnance_survey.api_key | b64enc | quote }} diff --git a/helm_deploy/apply-for-legal-aid/values-production.yaml b/helm_deploy/apply-for-legal-aid/values-production.yaml index f42c076bf5..5e81c6ccc5 100644 Binary files a/helm_deploy/apply-for-legal-aid/values-production.yaml and b/helm_deploy/apply-for-legal-aid/values-production.yaml differ diff --git a/helm_deploy/apply-for-legal-aid/values-staging.yaml b/helm_deploy/apply-for-legal-aid/values-staging.yaml index 175c486093..366ef50864 100644 Binary files a/helm_deploy/apply-for-legal-aid/values-staging.yaml and b/helm_deploy/apply-for-legal-aid/values-staging.yaml differ diff --git a/helm_deploy/apply-for-legal-aid/values-uat.yaml b/helm_deploy/apply-for-legal-aid/values-uat.yaml index 50efcca79b..2f81e508e5 100644 Binary files a/helm_deploy/apply-for-legal-aid/values-uat.yaml and b/helm_deploy/apply-for-legal-aid/values-uat.yaml differ