diff --git a/Dockerfile b/Dockerfile index 2db4e28b6fa67599eecef9e5b5ac6615a8074161..a834a64701a49e43463dfd842b3980dd9838da61 100644 --- a/Dockerfile +++ b/Dockerfile @@ -69,51 +69,40 @@ WORKDIR $HOME ### Plugins # # - OAuth -RUN git clone --depth=1 https://github.com/discourse/discourse-oauth2-basic.git /discourse/plugins/discourse-oauth2-basic - +RUN \ + git clone --depth=1 https://github.com/discourse/discourse-oauth2-basic.git /discourse/plugins/discourse-oauth2-basic && \ # - Chat Integration -RUN git clone --depth=1 https://github.com/discourse/discourse-chat-integration.git /discourse/plugins/discourse-chat-integration - + git clone --depth=1 https://github.com/discourse/discourse-chat-integration.git /discourse/plugins/discourse-chat-integration && \ # - Discourse Solved -RUN git clone --depth=1 https://github.com/discourse/discourse-solved.git /discourse/plugins/discourse-solved - + git clone --depth=1 https://github.com/discourse/discourse-solved.git /discourse/plugins/discourse-solved && \ # - Trade buttons (used on Marketplace) -RUN git clone --depth=1 https://github.com/jannolii/discourse-topic-trade-buttons.git /discourse/plugins/discourse-topic-trade-buttons - + git clone --depth=1 https://github.com/jannolii/discourse-topic-trade-buttons.git /discourse/plugins/discourse-topic-trade-buttons && \ # - Saved Searches -RUN git clone --depth=1 https://github.com/discourse/discourse-saved-searches.git /discourse/plugins/discourse-saved-searches - + git clone --depth=1 https://github.com/discourse/discourse-saved-searches.git /discourse/plugins/discourse-saved-searches && \ # - Migrate Password -RUN git clone --depth=1 https://github.com/discoursehosting/discourse-migratepassword.git /discourse/plugins/discourse-migratepassword - + git clone --depth=1 https://github.com/discoursehosting/discourse-migratepassword.git /discourse/plugins/discourse-migratepassword && \ # - Discourse Math -RUN git clone --depth=1 https://github.com/discourse/discourse-math.git /discourse/plugins/discourse-math - + git clone --depth=1 https://github.com/discourse/discourse-math.git /discourse/plugins/discourse-math && \ # - Discourse Askimet -RUN git clone --depth=1 https://github.com/discourse/discourse-akismet.git /discourse/plugins/discourse-akismet - + git clone --depth=1 https://github.com/discourse/discourse-akismet.git /discourse/plugins/discourse-akismet && \ # - Canned replies -RUN git clone --depth=1 https://github.com/discourse/discourse-canned-replies.git /discourse/plugins/discourse-canned-replies - + git clone --depth=1 https://github.com/discourse/discourse-canned-replies.git /discourse/plugins/discourse-canned-replies && \ # - Discourse JIRA -RUN git clone --depth=1 https://github.com/karies/discourse-jira.git /discourse/plugins/discourse-jira - + git clone --depth=1 https://github.com/karies/discourse-jira.git /discourse/plugins/discourse-jira && \ # - Prometheus -RUN git clone --depth=1 https://github.com/discourse/discourse-prometheus.git /discourse/plugins/discourse-prometheus - + git clone --depth=1 https://github.com/discourse/discourse-prometheus.git /discourse/plugins/discourse-prometheus && \ # - Calendar -RUN git clone --depth=1 https://github.com/discourse/discourse-calendar.git /discourse/plugins/discourse-calendar - + git clone --depth=1 https://github.com/discourse/discourse-calendar.git /discourse/plugins/discourse-calendar && \ # - Assign -RUN git clone --depth=1 https://github.com/discourse/discourse-assign.git /discourse/plugins/discourse-assign + git clone --depth=1 https://github.com/discourse/discourse-assign.git /discourse/plugins/discourse-assign ### Gem installation RUN exec bundle install --deployment --jobs 4 --without test --without development && \ exec bundle exec rake maxminddb:get && \ find /discourse/vendor/bundle -name tmp -type d -exec rm -rf {} + -COPY ["cgroup-limits","init-assets.sh","init-dbmigration.sh","run-discourse.sh","run-nginx.sh","run-redis.sh","./"] -RUN chmod +x ./run-discourse.sh ./run-nginx.sh ./run-redis.sh ./init-assets.sh ./init-dbmigration.sh && \ +COPY ["cgroup-limits","init-dbmigration.sh","run-discourse.sh","run-nginx.sh","run-redis.sh","./"] +RUN chmod +x ./run-discourse.sh ./run-nginx.sh ./run-redis.sh ./init-dbmigration.sh && \ chgrp -R 0 /discourse && chmod -R g=u /discourse && \ chmod +x /discourse/config/unicorn_launcher diff --git a/init-assets.sh b/init-assets.sh deleted file mode 100644 index a12b6ffc100df735a6c82c7d517d849c12333a14..0000000000000000000000000000000000000000 --- a/init-assets.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -# Replace environment variables -# This is mandatory as at the time of doing the migration, discourse needs to know redis IP, -# which is set thanks to discourse.conf file. -echo "--> Overwritting env variables ..." -envsubst < /tmp/discourse-configmap/discourse.conf > /discourse/config/discourse.conf -echo "--> DONE" - -# Always precompile assets -exec env RAILS_ENV="production" bundle exec rake assets:precompile \ No newline at end of file diff --git a/run-discourse.sh b/run-discourse.sh index 0c393ffd392276abe881d2dc82230f386b3e783d..af7bfbac224ff4ac2f689b7c2bd16d13de20615e 100644 --- a/run-discourse.sh +++ b/run-discourse.sh @@ -6,11 +6,14 @@ envsubst < /tmp/discourse-configmap/discourse.conf > /discourse/config/discourse envsubst < /tmp/discourse-configmap/sidekiq.yml > /discourse/config/sidekiq.yml echo "--> DONE" -# Puma is installed, so get memory information +# Get memory information export_vars=$(python cgroup-limits) ; export $export_vars export RAILS_ENV="production" -echo "--> Running Unicorn ..." -# Run discourse with Unicorn -exec env LD_PRELOAD=$RUBY_ALLOCATOR thpoff bundle exec config/unicorn_launcher -E production -c config/unicorn.conf.rb \ No newline at end of file +if bundle exec rake assets:precompile; +then + echo "--> Running Unicorn ..." + # Run discourse with Unicorn + exec env LD_PRELOAD=$RUBY_ALLOCATOR thpoff bundle exec config/unicorn_launcher -E production -c config/unicorn.conf.rb +fi \ No newline at end of file diff --git a/run-nginx.sh b/run-nginx.sh index 179f656d44f151959b87da1c2028d23a75a4fec7..a68d74b2c6e33eec0101d535d2a9e66d4ad9b95a 100644 --- a/run-nginx.sh +++ b/run-nginx.sh @@ -1,4 +1,18 @@ #!/bin/bash -echo "--> Running nginx ..." -exec nginx -g "daemon off;" \ No newline at end of file +# Replace environment variables +echo "--> Overwritting env variables ..." +envsubst < /tmp/discourse-configmap/discourse.conf > /discourse/config/discourse.conf +echo "--> DONE" + +# Get memory information +export_vars=$(python cgroup-limits) ; export $export_vars + +export RAILS_ENV="production" + +# Precompile assets. If succees, proceed with Nginx. +if bundle exec rake assets:precompile; +then + echo "--> Running nginx ..." + exec nginx -g "daemon off;" +fi diff --git a/templates/discourse-cern.yaml b/templates/discourse-cern.yaml index 447bb369f512c447660dddd2450f9e31a7fd741b..56744be81a5cf0c4b6ffe1c005b27d65797bc4b6 100644 --- a/templates/discourse-cern.yaml +++ b/templates/discourse-cern.yaml @@ -108,6 +108,54 @@ objects: name: nginx command: - ./run-nginx.sh + env: + - name: NAMESPACE + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.namespace + - name: HOSTNAME + value: $(NAMESPACE).web.cern.ch + - name: DISCOURSE_CONFIG_DB_HOST + valueFrom: + configMapKeyRef: + key: DISCOURSE_DB_HOST_KEY + name: env-configmap + - name: DISCOURSE_CONFIG_DB_PORT + valueFrom: + configMapKeyRef: + key: DISCOURSE_DB_PORT_KEY + name: env-configmap + - name: DISCOURSE_CONFIG_DB_NAME + valueFrom: + configMapKeyRef: + key: DISCOURSE_DB_NAME_KEY + name: env-configmap + - name: DISCOURSE_CONFIG_DB_USERNAME + valueFrom: + configMapKeyRef: + key: DISCOURSE_DB_USERNAME_KEY + name: env-configmap + - name: DISCOURSE_CONFIG_DB_PASSWORD + valueFrom: + configMapKeyRef: + key: DISCOURSE_DB_PASSWORD_KEY + name: env-configmap + - name: DISCOURSE_CONFIG_DEVELOPER_EMAILS + valueFrom: + configMapKeyRef: + key: DISCOURSE_DEVELOPER_EMAILS_KEY + name: env-configmap + - name: DISCOURSE_CONFIG_DB_POOL + valueFrom: + configMapKeyRef: + key: DISCOURSE_DB_POOL_KEY + name: env-configmap + - name: LANG + valueFrom: + configMapKeyRef: + key: LANG + name: env-configmap image: gitlab-registry.cern.ch/webservices/discourse-cern:stable imagePullPolicy: IfNotPresent ports: @@ -115,35 +163,33 @@ objects: protocol: TCP resources: limits: - memory: 400Mi - cpu: 200m + memory: 1Gi + cpu: 1 requests: - memory: 20Mi - cpu: 50m + memory: 320Mi + cpu: 150m terminationMessagePath: /dev/termination-log volumeMounts: - mountPath: /discourse/public/uploads name: discourse-uploads - mountPath: /discourse/public/assets name: discourse-public-assets - - mountPath: /discourse/public/plugins - name: discourse-public-plugins - mountPath: /discourse/public/backups name: discourse-backups - mountPath: /var/cache/nginx name: var-cache-nginx readinessProbe: - failureThreshold: 3 - initialDelaySeconds: 30 - periodSeconds: 10 + failureThreshold: 10 + initialDelaySeconds: 180 + periodSeconds: 20 successThreshold: 1 tcpSocket: port: 8080 timeoutSeconds: 10 livenessProbe: - failureThreshold: 3 - initialDelaySeconds: 10 - periodSeconds: 10 + failureThreshold: 5 + initialDelaySeconds: 900 + periodSeconds: 20 successThreshold: 1 tcpSocket: port: 8080 @@ -171,16 +217,12 @@ objects: name: discourse-backups - mountPath: /discourse/public/assets name: discourse-public-assets - - mountPath: /discourse/public/plugins - name: discourse-public-plugins - - mountPath: /discourse/tmp - name: discourse-tmp - mountPath: /discourse/logs name: discourse-logs readinessProbe: - failureThreshold: 3 - initialDelaySeconds: 30 - periodSeconds: 10 + failureThreshold: 10 + initialDelaySeconds: 180 + periodSeconds: 20 successThreshold: 1 tcpSocket: port: 3000 @@ -188,7 +230,7 @@ objects: livenessProbe: failureThreshold: 3 initialDelaySeconds: 900 - periodSeconds: 10 + periodSeconds: 20 successThreshold: 1 tcpSocket: port: 3000 @@ -286,7 +328,6 @@ objects: configMapKeyRef: key: LANG name: env-configmap - dnsPolicy: ClusterFirst restartPolicy: Always securityContext: @@ -357,80 +398,9 @@ objects: volumeMounts: - mountPath: /discourse/public/uploads name: discourse-uploads - - - name: init-assets - command: - - ./init-assets.sh - env: - - name: NAMESPACE - valueFrom: - fieldRef: - apiVersion: v1 - fieldPath: metadata.namespace - - name: HOSTNAME - value: $(NAMESPACE).web.cern.ch - - name: DISCOURSE_CONFIG_DB_HOST - valueFrom: - configMapKeyRef: - key: DISCOURSE_DB_HOST_KEY - name: env-configmap - - name: DISCOURSE_CONFIG_DB_PORT - valueFrom: - configMapKeyRef: - key: DISCOURSE_DB_PORT_KEY - name: env-configmap - - name: DISCOURSE_CONFIG_DB_NAME - valueFrom: - configMapKeyRef: - key: DISCOURSE_DB_NAME_KEY - name: env-configmap - - name: DISCOURSE_CONFIG_DB_USERNAME - valueFrom: - configMapKeyRef: - key: DISCOURSE_DB_USERNAME_KEY - name: env-configmap - - name: DISCOURSE_CONFIG_DB_PASSWORD - valueFrom: - configMapKeyRef: - key: DISCOURSE_DB_PASSWORD_KEY - name: env-configmap - - name: DISCOURSE_CONFIG_DEVELOPER_EMAILS - valueFrom: - configMapKeyRef: - key: DISCOURSE_DEVELOPER_EMAILS_KEY - name: env-configmap - - name: DISCOURSE_CONFIG_DB_POOL - valueFrom: - configMapKeyRef: - key: DISCOURSE_DB_POOL_KEY - name: env-configmap - - name: LANG - valueFrom: - configMapKeyRef: - key: LANG - name: env-configmap - image: gitlab-registry.cern.ch/webservices/discourse-cern:stable - imagePullPolicy: IfNotPresent - resources: - limits: - cpu: '1' - memory: 1Gi - requests: - cpu: 200m - memory: 320Mi - volumeMounts: - - mountPath: /discourse/public/assets - name: discourse-public-assets - - mountPath: /discourse/public/plugins - name: discourse-public-plugins - volumes: - name: discourse-public-assets emptyDir: {} - - name: discourse-public-plugins - emptyDir: {} - - name: discourse-tmp - emptyDir: {} - name: discourse-logs emptyDir: {} - name: var-cache-nginx