Skip to content

Commit cdf76c8

Browse files
committed
Add support for bootstrapping Sulu projects
1 parent 16e3d2f commit cdf76c8

File tree

1 file changed

+206
-0
lines changed

1 file changed

+206
-0
lines changed

upsun/10-sulu-upsun.yaml

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
requirements:
2+
- type: file_exists
3+
value: composer.json
4+
- type: has_composer_package
5+
value: sulu/sulu
6+
7+
template: |
8+
{{- $varnishServiceName := "" -}}
9+
{{- $hasRedisSession := false -}}
10+
{{- range $service := $.Services -}}
11+
{{- if eq $service.Type "varnish" -}}
12+
{{- $varnishServiceName = $service.Name -}}
13+
{{- end -}}
14+
{{- if eq $service.Name "redissession" -}}
15+
{{- $hasRedisSession = true -}}
16+
{{- end -}}
17+
{{- end -}}
18+
routes:
19+
{{ if $varnishServiceName -}}
20+
"https://{all}/admin": { type: upstream, upstream: "{{.Slug}}:http", cache: { enabled: false } }
21+
"https://{all}/": { type: upstream, upstream: "{{ $varnishServiceName }}:http", cache: { enabled: false } }
22+
{{- else -}}
23+
"https://{all}/": { type: upstream, upstream: "{{.Slug}}:http", cache: { enabled: false } }
24+
{{- end }}
25+
"http://{all}/": { type: redirect, to: "https://{all}/" }
26+
27+
services:{{ if not $.Services }} {}{{ end }}
28+
{{- range $service := $.Services }}
29+
{{ $service.Name }}:
30+
type: {{ $service.Type }}{{ if $service.Version }}:{{ $service.Version }}{{ end }}
31+
{{- if eq $service.Type "varnish" }}
32+
relationships:
33+
application: "{{$.Slug}}:http"
34+
configuration:
35+
vcl: !include
36+
type: string
37+
path: varnish.vcl
38+
{{- end }}
39+
{{- end }}
40+
41+
applications:
42+
{{.Slug}}:
43+
source:
44+
root: "/"
45+
46+
type: php:{{.PhpVersion}}
47+
48+
runtime:
49+
extensions:
50+
{{ range $ext := $.PHPExtensions -}}
51+
{{- if php_extension_available $ext $.PhpVersion -}}
52+
- {{ $ext }}
53+
{{ end -}}
54+
{{- end }}
55+
56+
variables:
57+
php:
58+
{{- if php_at_least "7.4" }}
59+
opcache.preload: config/preload.php
60+
{{- end }}
61+
{{- if $hasRedisSession }}
62+
session.save_handler: redis
63+
session.save_path: "tcp://${REDISSESSION_HOST}:${REDISSESSION_PORT}"
64+
{{- end }}
65+
66+
build:
67+
flavor: none
68+
69+
web:
70+
locations:
71+
"/":
72+
root: "{{.PublicDirectory}}"
73+
passthru: "/{{.FrontController}}"
74+
"/uploads":
75+
root: "{{.PublicDirectory}}"
76+
passthru: "/{{.FrontController}}"
77+
expires: 30d
78+
scripts: false
79+
allow: true
80+
81+
mounts:
82+
"/var/cache": { source: instance, source_path: var/cache }
83+
"/var/cache/common/prod/pools/app": { source: storage, source_path: var/cache/common/prod/pools/app }
84+
"/var/storage": { source: storage, source_path: var/storage }
85+
"/var/indexes": { source: storage, source_path: var/indexes }
86+
"/public/uploads": { source: storage, source_path: public/uploads }
87+
88+
{{- if $.Services }}
89+
relationships:
90+
{{- range $service := $.Services }}
91+
{{- if ne $service.Type "varnish" }}
92+
{{ $service.Name }}: "{{ $service.Name }}:{{ with $service.Endpoint }}{{ . }}{{ else }}{{ $service.Type }}{{ end }}"
93+
{{- end }}
94+
{{- end }}
95+
{{- end }}
96+
97+
hooks:
98+
build: |
99+
set -x -e
100+
101+
curl -fs https://get.symfony.com/cloud/configurator | bash
102+
{{ range $ext := $.PHPExtensions -}}
103+
{{- if not (php_extension_available $ext $.PhpVersion) -}}
104+
# php-ext-install {{ $ext }} X.Y.Z
105+
{{ end -}}
106+
{{- end }}
107+
NODE_VERSION=22 symfony-build
108+
109+
deploy: |
110+
set -x -e
111+
112+
symfony-deploy
113+
114+
crons:
115+
security-check:
116+
# Check that no security issues have been found for PHP packages deployed in production
117+
spec: '50 23 * * *'
118+
cmd: if [ "$PLATFORM_ENVIRONMENT_TYPE" = "production" ]; then croncape COMPOSER_ROOT_VERSION=1.0.0 COMPOSER_AUDIT_ABANDONED=ignore composer audit --no-cache; fi
119+
clean-expired-sessions:
120+
spec: '17,47 * * * *'
121+
cmd: croncape php-session-clean
122+
123+
{{ if has_composer_package "symfony/messenger" -}}
124+
workers:
125+
messenger:
126+
commands:
127+
# Consume "async" messages (as configured in the routing section of config/packages/messenger.yaml)
128+
start: symfony console --time-limit=3600 --memory-limit=64M messenger:consume async
129+
{{- end }}
130+
131+
extra_files:
132+
".upsun/varnish.vcl": |
133+
# Varnish configuration for Sulu CMS on Upsun
134+
# This configuration handles cache invalidation and Sulu-specific requirements
135+
136+
import std;
137+
import xkey;
138+
139+
acl invalidators {
140+
"localhost";
141+
# TODO add outbound IPs for the your region
142+
}
143+
144+
sub vcl_recv {
145+
# Define the backend
146+
set req.backend_hint = application.backend();
147+
148+
if (req.method == "PURGE") {
149+
if (!std.ip(req.http.X-Client-IP, "0.0.0.0") ~ invalidators) {
150+
return (synth(405, "Not allowed"));
151+
}
152+
153+
return (purge);
154+
}
155+
156+
if (req.method == "PURGEKEYS") {
157+
if (!std.ip(req.http.X-Client-IP, "0.0.0.0") ~ invalidators) {
158+
return (synth(405, "Not allowed"));
159+
}
160+
161+
# If neither of the headers are provided we return 400 to simplify detecting wrong configuration
162+
if (!req.http.xkey-purge && !req.http.xkey-softpurge) {
163+
return (synth(400, "Neither header XKey-Purge or XKey-SoftPurge set"));
164+
}
165+
166+
# Based on provided header invalidate (purge) and/or expire (softpurge) the tagged content
167+
set req.http.n-gone = 0;
168+
set req.http.n-softgone = 0;
169+
if (req.http.xkey-purge) {
170+
set req.http.n-gone = xkey.purge(req.http.xkey-purge);
171+
}
172+
173+
if (req.http.xkey-softpurge) {
174+
set req.http.n-softgone = xkey.softpurge(req.http.xkey-softpurge);
175+
}
176+
177+
return (synth(200, "Purged " + req.http.n-gone + " objects, expired " + req.http.n-softgone + " objects"));
178+
}
179+
}
180+
181+
sub vcl_backend_response {
182+
# Set grace period
183+
set beresp.grace = 2m;
184+
set beresp.keep = 8m;
185+
186+
if (beresp.http.X-Reverse-Proxy-TTL) {
187+
set beresp.ttl = std.duration(beresp.http.X-Reverse-Proxy-TTL + "s", 0s);
188+
}
189+
}
190+
191+
sub vcl_deliver {
192+
# Add debug headers in development
193+
if (resp.http.X-Cache-Debug) {
194+
if (obj.hits > 0) {
195+
set resp.http.X-Cache = "HIT";
196+
} else {
197+
set resp.http.X-Cache = "MISS";
198+
}
199+
}
200+
201+
if (!resp.http.X-Cache-Debug) {
202+
# Remove tag headers when delivering to non debug client
203+
unset resp.http.xkey;
204+
unset resp.http.X-Reverse-Proxy-TTL;
205+
}
206+
}

0 commit comments

Comments
 (0)