Skip to content

Commit

Permalink
Add harness for Alokai
Browse files Browse the repository at this point in the history
  • Loading branch information
andytson-inviqa committed Aug 8, 2024
1 parent 3fa1ffa commit d22bd14
Show file tree
Hide file tree
Showing 10 changed files with 261 additions and 3 deletions.
7 changes: 5 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion build
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ $0 [--archive]
EOF
}

HARNESSES=(nextjs)
HARNESSES=(nextjs alokai)
ARCHIVE=0
ARGS=()

Expand Down
22 changes: 22 additions & 0 deletions src/alokai/_twig/docker-compose.yml/service/middleware.yml.twig
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions src/alokai/_twig/docker-compose.yml/service/nextjs.yml.twig
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions src/alokai/_twig/middleware.env.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% if @('app.build') == 'host' %}
{% for name, value in @('services.middleware.environment')|merge(@('services.middleware.environment_secrets')) %}
{{ name }}={{ value }}
{% endfor %}
{% endif %}
8 changes: 8 additions & 0 deletions src/alokai/_twig/nextjs.env.twig
Original file line number Diff line number Diff line change
@@ -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 %}
Original file line number Diff line number Diff line change
@@ -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;
}

}
106 changes: 106 additions & 0 deletions src/alokai/harness.yml
Original file line number Diff line number Diff line change
@@ -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
39 changes: 39 additions & 0 deletions src/alokai/harness/config/confd.yml
Original file line number Diff line number Diff line change
@@ -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 }

0 comments on commit d22bd14

Please sign in to comment.