diff --git a/UPGRADE.md b/UPGRADE.md index 47b58bc..378aa7e 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -12,6 +12,7 @@ ## Upgrade from v5.0.0 to v5.1.0 +- cache warmup is now run as an init container instead of a `postStart` lifecycle hook ([#73](https://github.com/shopsys/deployment/pull/73)) - cron pod is now always deleted gracefully ([#72](https://github.com/shopsys/deployment/pull/72)) - health check for webserver now uses PHP-FPM `ping` endpoint instead of nginx `stub_status` ([#71](https://github.com/shopsys/deployment/pull/71)) - update the `/health` location block in `project-nginx.conf` in your project's `app/orchestration/kubernetes/configmap/nginx.yaml` file to pass the request to PHP-FPM: diff --git a/deploy/parts/environment-variables.sh b/deploy/parts/environment-variables.sh index e9b3792..6c28277 100644 --- a/deploy/parts/environment-variables.sh +++ b/deploy/parts/environment-variables.sh @@ -39,6 +39,14 @@ for key in "${!ENVIRONMENT_VARIABLES[@]}"; do } " "${CONFIGURATION_TARGET_PATH}/deployments/webserver-php-fpm.yaml" + # Webserver PHP-FPM warmup container + yq e -i " + .spec.template.spec.initContainers[1].env[${ITERATOR}] = { + \"name\": \"${key}\", + \"value\": \"${ENVIRONMENT_VARIABLES[$key]}\" + } + " "${CONFIGURATION_TARGET_PATH}/deployments/webserver-php-fpm.yaml" + # Cron deployment yq e -i " .spec.template.spec.containers[0].env[${ITERATOR}] = { @@ -145,4 +153,4 @@ yq e -i " unset YQ_KEY unset YQ_VALUE -echo -e "[${GREEN}OK${NO_COLOR}]" \ No newline at end of file +echo -e "[${GREEN}OK${NO_COLOR}]" diff --git a/kubernetes/deployments/webserver-php-fpm.yaml b/kubernetes/deployments/webserver-php-fpm.yaml index c8c5cc0..0d50252 100644 --- a/kubernetes/deployments/webserver-php-fpm.yaml +++ b/kubernetes/deployments/webserver-php-fpm.yaml @@ -83,15 +83,21 @@ spec: - name: domains-urls mountPath: /var/www/html/{{DOMAINS_URLS_FILEPATH}} subPath: "{{DOMAINS_URLS_FILENAME}}" + - name: warmup + image: "{{TAG}}" + command: ["/var/www/html/phing", "-S", "warmup"] + volumeMounts: + - name: source-codes + mountPath: /var/www/html + - name: domains-urls + mountPath: /var/www/html/{{DOMAINS_URLS_FILEPATH}} + subPath: "{{DOMAINS_URLS_FILENAME}}" containers: - image: "{{TAG}}" name: php-fpm imagePullPolicy: IfNotPresent workingDir: /var/www/html lifecycle: - postStart: - exec: - command: ["/var/www/html/phing", "-S", "warmup"] preStop: exec: command: ["/bin/sh","-lc","sleep 10; kill -QUIT 1 || true"] diff --git a/tests/scenarios/basic-production/expected/webserver.yaml b/tests/scenarios/basic-production/expected/webserver.yaml index 4829d3f..9ea6305 100644 --- a/tests/scenarios/basic-production/expected/webserver.yaml +++ b/tests/scenarios/basic-production/expected/webserver.yaml @@ -741,12 +741,6 @@ spec: image: v1.0.0 imagePullPolicy: IfNotPresent lifecycle: - postStart: - exec: - command: - - /var/www/html/phing - - -S - - warmup preStop: exec: command: @@ -854,6 +848,53 @@ spec: - mountPath: /var/www/html/config/domains_urls.yaml name: domains-urls subPath: domains_urls.yaml + - command: + - /var/www/html/phing + - -S + - warmup + env: + - name: ELASTICSEARCH_HOST + value: http://elasticsearch:9200 + - name: TRUSTED_PROXY + value: 10.0.0.0/8 + - name: DATABASE_NAME + value: myproject-production + - name: S3_ENDPOINT + value: https://s3.example.com + - name: MAILER_FORCE_WHITELIST + value: "false" + - name: DATABASE_USER + value: myproject-production + - name: DATABASE_PORT + value: "5432" + - name: MESSENGER_TRANSPORT_DSN + value: amqp://guest:guest@rabbitmq:5672/%2f/messages + - name: REDIS_PREFIX + value: myproject-production + - name: DATABASE_PASSWORD + value: test-db-password + - name: DATABASE_HOST + value: 10.0.0.100 + - name: ELASTIC_SEARCH_INDEX_PREFIX + value: myproject-production + - name: S3_SECRET + value: test-s3-secret + - name: MAILER_DSN + value: smtp://mailhog:1025 + - name: S3_BUCKET_NAME + value: myproject-production + - name: S3_ACCESS_KEY + value: myproject-production + - name: APP_SECRET + value: test-app-secret-key + image: v1.0.0 + name: warmup + volumeMounts: + - mountPath: /var/www/html + name: source-codes + - mountPath: /var/www/html/config/domains_urls.yaml + name: domains-urls + subPath: domains_urls.yaml terminationGracePeriodSeconds: 120 volumes: - emptyDir: {} diff --git a/tests/scenarios/development-single-domain/expected/webserver.yaml b/tests/scenarios/development-single-domain/expected/webserver.yaml index 071b317..86d00b3 100644 --- a/tests/scenarios/development-single-domain/expected/webserver.yaml +++ b/tests/scenarios/development-single-domain/expected/webserver.yaml @@ -735,12 +735,6 @@ spec: image: dev-latest imagePullPolicy: IfNotPresent lifecycle: - postStart: - exec: - command: - - /var/www/html/phing - - -S - - warmup preStop: exec: command: @@ -848,6 +842,53 @@ spec: - mountPath: /var/www/html/config/domains_urls.yaml name: domains-urls subPath: domains_urls.yaml + - command: + - /var/www/html/phing + - -S + - warmup + env: + - name: ELASTICSEARCH_HOST + value: http://elasticsearch:9200 + - name: TRUSTED_PROXY + value: 10.0.0.0/8 + - name: DATABASE_NAME + value: myproject-dev + - name: S3_ENDPOINT + value: https://s3.example.com + - name: MAILER_FORCE_WHITELIST + value: "true" + - name: DATABASE_USER + value: myproject-dev + - name: DATABASE_PORT + value: "5432" + - name: MESSENGER_TRANSPORT_DSN + value: amqp://guest:guest@rabbitmq:5672/%2f/messages + - name: REDIS_PREFIX + value: myproject-dev + - name: DATABASE_PASSWORD + value: test-db-password + - name: DATABASE_HOST + value: 10.0.0.100 + - name: ELASTIC_SEARCH_INDEX_PREFIX + value: myproject-dev + - name: S3_SECRET + value: test-s3-secret + - name: MAILER_DSN + value: smtp://mailhog:1025 + - name: S3_BUCKET_NAME + value: myproject-dev + - name: S3_ACCESS_KEY + value: myproject-dev + - name: APP_SECRET + value: test-app-secret-key + image: dev-latest + name: warmup + volumeMounts: + - mountPath: /var/www/html + name: source-codes + - mountPath: /var/www/html/config/domains_urls.yaml + name: domains-urls + subPath: domains_urls.yaml terminationGracePeriodSeconds: 120 volumes: - emptyDir: {} diff --git a/tests/scenarios/escaping-env/expected/webserver.yaml b/tests/scenarios/escaping-env/expected/webserver.yaml index fe02564..97d9950 100644 --- a/tests/scenarios/escaping-env/expected/webserver.yaml +++ b/tests/scenarios/escaping-env/expected/webserver.yaml @@ -748,12 +748,6 @@ spec: image: v1.0.0 imagePullPolicy: IfNotPresent lifecycle: - postStart: - exec: - command: - - /var/www/html/phing - - -S - - warmup preStop: exec: command: @@ -861,6 +855,55 @@ spec: - mountPath: /var/www/html/config/domains_urls.yaml name: domains-urls subPath: domains_urls.yaml + - command: + - /var/www/html/phing + - -S + - warmup + env: + - name: ELASTICSEARCH_HOST + value: http://elasticsearch:9200 + - name: TRUSTED_PROXY + value: 10.0.0.0/8 + - name: DATABASE_NAME + value: myproject-production + - name: S3_ENDPOINT + value: https://s3.example.com + - name: MAILER_FORCE_WHITELIST + value: "false" + - name: DATABASE_USER + value: myproject-production + - name: DATABASE_PORT + value: "5432" + - name: MESSENGER_TRANSPORT_DSN + value: amqp://guest:guest@rabbitmq:5672/%2f/messages + - name: REDIS_PREFIX + value: myproject-production + - name: DATABASE_PASSWORD + value: test-db-password + - name: DATABASE_HOST + value: 10.0.0.100 + - name: ELASTIC_SEARCH_INDEX_PREFIX + value: myproject-production + - name: SENTRY_RELEASE + value: "479411e7" + - name: S3_SECRET + value: test-s3-secret + - name: MAILER_DSN + value: smtp://mailhog:1025 + - name: S3_BUCKET_NAME + value: myproject-production + - name: S3_ACCESS_KEY + value: myproject-production + - name: APP_SECRET + value: test-app-secret-key + image: v1.0.0 + name: warmup + volumeMounts: + - mountPath: /var/www/html + name: source-codes + - mountPath: /var/www/html/config/domains_urls.yaml + name: domains-urls + subPath: domains_urls.yaml terminationGracePeriodSeconds: 120 volumes: - emptyDir: {} diff --git a/tests/scenarios/production-with-cloudflare/expected/webserver.yaml b/tests/scenarios/production-with-cloudflare/expected/webserver.yaml index 92cbd9e..af0b676 100644 --- a/tests/scenarios/production-with-cloudflare/expected/webserver.yaml +++ b/tests/scenarios/production-with-cloudflare/expected/webserver.yaml @@ -742,12 +742,6 @@ spec: image: v2.5.0 imagePullPolicy: IfNotPresent lifecycle: - postStart: - exec: - command: - - /var/www/html/phing - - -S - - warmup preStop: exec: command: @@ -855,6 +849,53 @@ spec: - mountPath: /var/www/html/config/domains_urls.yaml name: domains-urls subPath: domains_urls.yaml + - command: + - /var/www/html/phing + - -S + - warmup + env: + - name: ELASTICSEARCH_HOST + value: http://elasticsearch:9200 + - name: TRUSTED_PROXY + value: 10.0.0.0/8 + - name: DATABASE_NAME + value: shop-production + - name: S3_ENDPOINT + value: https://s3.example.com + - name: MAILER_FORCE_WHITELIST + value: "false" + - name: DATABASE_USER + value: shop-production + - name: DATABASE_PORT + value: "5432" + - name: MESSENGER_TRANSPORT_DSN + value: amqp://guest:guest@rabbitmq:5672/%2f/messages + - name: REDIS_PREFIX + value: shop-production + - name: DATABASE_PASSWORD + value: test-db-password + - name: DATABASE_HOST + value: 10.0.0.100 + - name: ELASTIC_SEARCH_INDEX_PREFIX + value: shop-production + - name: S3_SECRET + value: test-s3-secret + - name: MAILER_DSN + value: smtp://mailhog:1025 + - name: S3_BUCKET_NAME + value: shop-production + - name: S3_ACCESS_KEY + value: shop-production + - name: APP_SECRET + value: test-app-secret-key + image: v2.5.0 + name: warmup + volumeMounts: + - mountPath: /var/www/html + name: source-codes + - mountPath: /var/www/html/config/domains_urls.yaml + name: domains-urls + subPath: domains_urls.yaml terminationGracePeriodSeconds: 120 volumes: - emptyDir: {}