From d22bd1480d97ddddeeb6d0d14baee6e95bde5fca Mon Sep 17 00:00:00 2001 From: Andy Thompson Date: Thu, 8 Aug 2024 14:27:25 +0100 Subject: [PATCH] Add harness for Alokai --- Jenkinsfile | 7 +- README.md | 2 + build | 2 +- .../service/middleware.yml.twig | 22 ++++ .../service/nextjs.yml.twig | 26 +++++ src/alokai/_twig/middleware.env.twig | 5 + src/alokai/_twig/nextjs.env.twig | 8 ++ .../root/etc/nginx/conf.d/default.conf.twig | 47 ++++++++ src/alokai/harness.yml | 106 ++++++++++++++++++ src/alokai/harness/config/confd.yml | 39 +++++++ 10 files changed, 261 insertions(+), 3 deletions(-) create mode 100644 src/alokai/_twig/docker-compose.yml/service/middleware.yml.twig create mode 100644 src/alokai/_twig/docker-compose.yml/service/nextjs.yml.twig create mode 100644 src/alokai/_twig/middleware.env.twig create mode 100644 src/alokai/_twig/nextjs.env.twig create mode 100644 src/alokai/docker/image/nginx/root/etc/nginx/conf.d/default.conf.twig create mode 100644 src/alokai/harness.yml create mode 100644 src/alokai/harness/config/confd.yml diff --git a/Jenkinsfile b/Jenkinsfile index 5b95d50..7323205 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -31,7 +31,7 @@ pipeline { } stage('Build and Test') { parallel { - stage('1. NextJS') { + stage('1. NextJS, Alokai') { agent { docker { // Reuse the same agent selected at the top of the file @@ -60,12 +60,15 @@ pipeline { } steps { sh './test nextjs dynamic mutagen' + sh './test alokai dynamic mutagen' sh './test nextjs static' + sh './test alokai static' sh './test nextjs dynamic' + sh './test alokai dynamic' } - post { failure { script { failureMessages << 'NextJS quality checks' } } } + post { failure { script { failureMessages << 'NextJS and Alokai quality checks' } } } } stage('Acceptance Tests') { environment { diff --git a/README.md b/README.md index 7b09d34..002ad23 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ Each framework will fully override a base harness file if differing behaviour is ## Available Frameworks - [NextJs](src/nextjs/) +- [Alokai](src/alokai/) ## Features of each harness @@ -185,4 +186,5 @@ When you're ready to release: [Workspace]: https://github.com/my127/workspace [inviqa/harness-nextjs]: https://github.com/inviqa/harness-base-node/tree/main/src/nextjs +[inviqa/harness-alokai]: https://github.com/inviqa/harness-base-node/tree/main/src/alokai [my127/my127.io]: https://github.com/my127/my127.io diff --git a/build b/build index cc617d2..c3aedda 100755 --- a/build +++ b/build @@ -9,7 +9,7 @@ $0 [--archive] EOF } -HARNESSES=(nextjs) +HARNESSES=(nextjs alokai) ARCHIVE=0 ARGS=() diff --git a/src/alokai/_twig/docker-compose.yml/service/middleware.yml.twig b/src/alokai/_twig/docker-compose.yml/service/middleware.yml.twig new file mode 100644 index 0000000..61965ff --- /dev/null +++ b/src/alokai/_twig/docker-compose.yml/service/middleware.yml.twig @@ -0,0 +1,22 @@ +services: + middleware: +{% if @('app.build' == 'static') %} + build: + context: ./ + dockerfile: .vuestorefrontcloud/docker/middleware/Dockerfile-middleware + args: {{ to_nice_yaml(@('services.middleware.build.args'), 2, 8) }} +{% else %} + extends: console + working_dir: /app/apps/storefront-middleware + command: [ {{ @('node.packageManager') | json_encode }}, run, dev ] +{% endif %} + labels: + # Traefik 1, deprecated + - traefik.enable=false + environment: {{ to_nice_yaml(deep_merge([ + @('services.middleware.environment'), + @('services.middleware.environment_dynamic'), + @('services.middleware.environment_secrets') + ]), 2, 6) }} + networks: + - private diff --git a/src/alokai/_twig/docker-compose.yml/service/nextjs.yml.twig b/src/alokai/_twig/docker-compose.yml/service/nextjs.yml.twig new file mode 100644 index 0000000..4c052f6 --- /dev/null +++ b/src/alokai/_twig/docker-compose.yml/service/nextjs.yml.twig @@ -0,0 +1,26 @@ +services: + nextjs: +{% if @('app.build' == 'static') %} + build: + context: ./ + dockerfile: .vuestorefrontcloud/docker/nextjs/Dockerfile-frontend + args: {{ to_nice_yaml(deep_merge([ + @('services.nextjs.build.args'), + @('services.nextjs.environment') + ]), 2, 8) }} +{% else %} + extends: console + working_dir: /app/apps/storefront-unified-nextjs + command: [ {{ @('node.packageManager') | json_encode }}, run, dev ] +{% endif %} + labels: + # Traefik 1, deprecated + - traefik.enable=false + environment: {{ to_nice_yaml(deep_merge([ + @('app.build') == 'dynamic' ? @('services.nextjs.build.args') : [], + @('services.nextjs.environment'), + @('services.nextjs.environment_dynamic'), + @('services.nextjs.environment_secrets') + ]), 2, 6) }} + networks: + - private diff --git a/src/alokai/_twig/middleware.env.twig b/src/alokai/_twig/middleware.env.twig new file mode 100644 index 0000000..0b733a5 --- /dev/null +++ b/src/alokai/_twig/middleware.env.twig @@ -0,0 +1,5 @@ +{% if @('app.build') == 'host' %} +{% for name, value in @('services.middleware.environment')|merge(@('services.middleware.environment_secrets')) %} +{{ name }}={{ value }} +{% endfor %} +{% endif %} diff --git a/src/alokai/_twig/nextjs.env.twig b/src/alokai/_twig/nextjs.env.twig new file mode 100644 index 0000000..a3920ab --- /dev/null +++ b/src/alokai/_twig/nextjs.env.twig @@ -0,0 +1,8 @@ +{% if @('app.build') == 'host' %} +{% for name, value in @('services.nextjs.build.args') | filter((value, key) => key starts with 'NEXT_PUBLIC_') %} +{{ name }}={{ value }} +{% endfor %} +{% for name, value in @('services.nextjs.environment')|merge(@('services.nextjs.environment_secrets')) %} +{{ name }}={{ value }} +{% endfor %} +{% endif %} diff --git a/src/alokai/docker/image/nginx/root/etc/nginx/conf.d/default.conf.twig b/src/alokai/docker/image/nginx/root/etc/nginx/conf.d/default.conf.twig new file mode 100644 index 0000000..d9b1d61 --- /dev/null +++ b/src/alokai/docker/image/nginx/root/etc/nginx/conf.d/default.conf.twig @@ -0,0 +1,47 @@ +map $http_upgrade $connection_upgrade { + default upgrade; + '' close; +} + +server { + + listen 80 default_server; + listen 443 ssl default_server; + http2 on; + + server_name _; + + ssl_certificate /etc/ssl/certs/app.crt; + ssl_certificate_key /etc/ssl/private/app.key; + + set $custom_https $https; + set $custom_scheme $scheme; + + if ($http_x_forwarded_proto) { + set $custom_scheme $http_x_forwarded_proto; + } + + location / { + proxy_pass http://nextjs:3000; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $custom_scheme; + proxy_buffers 4 256k; + proxy_buffer_size 128k; + proxy_busy_buffers_size 256k; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $connection_upgrade; + } + + location /api/ { + proxy_pass http://middleware:4000/; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $custom_scheme; + proxy_buffers 4 256k; + proxy_buffer_size 128k; + proxy_busy_buffers_size 256k; + } + +} diff --git a/src/alokai/harness.yml b/src/alokai/harness.yml new file mode 100644 index 0000000..218f68d --- /dev/null +++ b/src/alokai/harness.yml @@ -0,0 +1,106 @@ +harness('inviqa/alokai'): + description: A docker based development environment for Alokai + harnessLayers: + - inviqa/docker:v0.4.0 + require: + services: + - proxy + confd: + - harness:/ +--- +attributes: + alokai: + multistore: + enabled: false + + node: + packageManager: yarn + version: '18' + + npm: + login: true + registry: + # username: + # password: + # email: # email address ignored but field required + url: https://registrynpm.storefrontcloud.io + scope: '@vsf-enterprise' + + services: + console: + build: + from: = 'node:' ~ @('node.version') ~ '-slim' + args: + NPM_USER: = @('npm.registry.username') + NPM_PASS: = @('npm.registry.password') + NPM_EMAIL: = @('npm.registry.email') + NPM_REGISTRY: = @('npm.registry.url') + NPM_SCOPE: = @('npm.registry.scope') + publish: false + nginx: + enabled: true + relay: + enabled: false + middleware: + enabled: true + build: + args: + NPM_USER: = @('npm.registry.username') + NPM_PASS: = @('npm.registry.password') + NPM_EMAIL: = @('npm.registry.email') + NPM_REGISTRY: = @('npm.registry.url') + NPM_SCOPE: = @('npm.registry.scope') + environment: + ### Commerce + IS_MULTISTORE_ENABLED: > + = @('app.build') == 'host' ? 'false' + : @('alokia.multistore.enabled') ? 'true' + : false + # BIGCOMMERCE_API_CLIENT_ID: + # BIGCOMMERCE_API_URL: + # BIGCOMMERCE_STORE_ID: + + ### CMS + # Contentful config + # CNTF_SPACE: + # CNTF_ENVIRONMENT: + environment_secrets: + # BIGCOMMERCE_API_CLIENT_SECRET: + # BIGCOMMERCE_API_ACCESS_TOKEN: + # BIGCOMMERCE_STORE_GUEST_TOKEN: + # CNTF_TOKEN: + nextjs: + enabled: true + build: + args: + NPM_USER: = @('npm.registry.username') + NPM_PASS: = @('npm.registry.password') + NPM_EMAIL: = @('npm.registry.email') + NPM_REGISTRY: = @('npm.registry.url') + NPM_SCOPE: = @('npm.registry.scope') + + NEXT_PUBLIC_API_BASE_URL: > + = @('app.build') == 'host' ? 'http://localhost:4000' + : @('alokia.multistore.enabled') ? '/api' + : 'https://' ~ @('hostname') ~ '/api' + NEXT_PUBLIC_IS_MULTISTORE_ENABLED: > + = @('app.build') == 'host' ? 'false' + : @('alokia.multistore.enabled') ? 'true' + : false + + # Default Image Loader fetch url. + # For Cloudinary check https://cloudinary.com/documentation/fetch_remote_images#fetch_and_deliver_remote_files + # NEXT_PUBLIC_IMAGE_LOADER_FETCH_URL: https://res.cloudinary.com/dcqchkrzw/image/fetch/ + + # Optional. Will be used when image url will not start with http. + # For Cloudinary check https://cloudinary.com/documentation/migration#lazy_migration_with_auto_upload + # NEXT_PUBLIC_IMAGE_LOADER_UPLOAD_URL: https://res.cloudinary.com/vsf-sap/image/upload/ + environment: {} # no NEXT_PUBLIC variables supported for runtime + environment_secrets: + # to allow nextjs server-side talking to nginx https locally for middleware routing + NODE_TLS_REJECT_UNAUTHORIZED: '0' +--- +import: + - harness/config/*.yml + - harness/attributes/*.yml + - harness/attributes/environment/={env('MY127WS_ENV','local')}.yml diff --git a/src/alokai/harness/config/confd.yml b/src/alokai/harness/config/confd.yml new file mode 100644 index 0000000..daf575b --- /dev/null +++ b/src/alokai/harness/config/confd.yml @@ -0,0 +1,39 @@ +# this file is not considered part of the public API so changes aren't considered breaking +confd('harness:/'): + # inviqa/docker templates + - { src: docker/image/console/Dockerfile } + - { src: docker/image/console/home/.my.cnf } + - { src: docker/image/console/root/entrypoint.sh } + - { src: docker/image/console/root/usr/lib/task/build.sh } + - { src: docker/image/console/root/usr/lib/task/database/import.sh } + - { src: docker/image/console/root/usr/lib/task/init.sh } + - { src: docker/image/console/root/usr/lib/task/install.sh } + - { src: docker/image/console/root/usr/lib/task/migrate.sh } + - { src: docker/image/console/root/usr/lib/task/rabbitmq/vhosts.sh } + - { src: docker/image/console/root/usr/lib/task/welcome.sh } + - { src: docker/image/lighthouse/Dockerfile } + - { src: docker/image/lighthouse/root/app/run.sh } + - { src: docker/image/solr/Dockerfile } + - { src: docker/image/tls-offload/root/etc/nginx/conf.d/0-nginx.conf } + - { src: docker/image/tls-offload/root/etc/nginx/conf.d/default.conf } + - { src: docker/image/tls-offload/root/etc/ssl/certs/app.crt } + - { src: docker/image/tls-offload/root/etc/ssl/private/app.key } + - { src: docker/image/varnish/root/etc/varnish/default.vcl } + - { src: application/overlay/Jenkinsfile } + - { src: application/overlay/.dockerignore, dst: workspace:/.dockerignore } + - { src: application/skeleton/README.md } + - { src: mutagen.yml, dst: workspace:/mutagen.yml } # docker-compose.yml render reads this file + - { src: docker-compose.yml, dst: workspace:/docker-compose.yml } + - { src: harness/scripts/enable.sh } + - { src: helm/app/_twig/templates/service/varnish/configmap.yaml, dst: harness:/helm/app/templates/service/varnish/configmap.yaml } + - { src: helm/app/values.yaml } + - { src: helm/app/values-production.yaml } + - { src: helm/app/values-preview.yaml } + - { src: helm/app/Chart.yaml } + # node/_base templates + - { src: docker/image/nginx/root/etc/nginx/conf.d/default.conf } + - { src: docker/image/nginx/root/etc/ssl/certs/app.crt } + - { src: docker/image/nginx/root/etc/ssl/private/app.key } + # node/alokai templates + - { src: _twig/middleware.env, dst: workspace:/apps/storefront-middleware/.env } + - { src: _twig/nextjs.env, dst: workspace:/apps/storefront-unified-nextjs/.env }