Skip to content

Commit 62b6f20

Browse files
committed
feat: add backward compatibility layer
1 parent 55664bc commit 62b6f20

File tree

6 files changed

+37
-7
lines changed

6 files changed

+37
-7
lines changed

Dockerfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ LABEL org.opencontainers.image.source=https://github.com/dunglas/mercure
88
LABEL org.opencontainers.image.licenses=AGPL-3.0-or-later
99
LABEL org.opencontainers.image.vendor="Kévin Dunglas"
1010

11-
ENV MERCURE_TRANSPORT_URL=bolt:///data/mercure.db
12-
1311
COPY mercure /usr/bin/caddy
1412
COPY Caddyfile /etc/caddy/Caddyfile
1513
COPY dev.Caddyfile /etc/caddy/dev.Caddyfile

caddy/caddy.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99
"net/http"
1010
"net/url"
11+
"os"
1112
"strconv"
1213
"strings"
1314
"time"
@@ -153,7 +154,7 @@ func (m *Mercure) populateJWTConfig() error {
153154
//
154155
//nolint:wrapcheck,ireturn
155156
func createTransportLegacy(m *Mercure) (mercure.Transport, error) {
156-
m.logger.Warn(`Setting transport_url is deprecated, use the "transport" directive instead`)
157+
m.logger.Warn(`Setting the transport_url or the MERCURE_TRANSPORT_URL environment variable is deprecated, use the "transport" directive instead`)
157158

158159
destructor, _, err := transports.LoadOrNew(m.TransportURL, func() (caddy.Destructor, error) {
159160
u, err := url.Parse(m.TransportURL)
@@ -490,6 +491,15 @@ func (m *Mercure) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { //nolint:fu
490491
}
491492
}
492493

494+
// BC layer with old versions of the built-in Caddyfile
495+
if m.TransportRaw == nil && m.TransportURL == "" {
496+
deprecatedTransportURL := os.Getenv("MERCURE_TRANSPORT_URL")
497+
498+
if deprecatedTransportURL != "" {
499+
m.TransportURL = deprecatedTransportURL
500+
}
501+
}
502+
493503
return nil
494504
}
495505

charts/mercure/templates/deployment.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,13 @@ spec:
5757
secretKeyRef:
5858
name: {{ include "mercure.secretName" . }}
5959
key: caddy-extra-directives
60+
{{- if .Values.transportUrl }}
6061
- name: MERCURE_TRANSPORT_URL
6162
valueFrom:
6263
secretKeyRef:
6364
name: {{ include "mercure.secretName" . }}
6465
key: transport-url
66+
{{- end }}
6567
- name: MERCURE_PUBLISHER_JWT_KEY
6668
valueFrom:
6769
secretKeyRef:
@@ -92,6 +94,9 @@ spec:
9294
secretKeyRef:
9395
name: {{ include "mercure.secretName" . }}
9496
key: license
97+
{{- if .Values.extraEnvs }}
98+
{{- toYaml .Values.extraEnvs | nindent 12 }}
99+
{{- end }}
95100
{{- if .Values.persistence.enabled }}
96101
volumeMounts:
97102
- mountPath: /data

charts/mercure/templates/secrets.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ metadata:
77
{{- include "mercure.labels" . | nindent 4 }}
88
type: Opaque
99
data:
10+
{{- if .Values.transportUrl }}
1011
transport-url: {{ .Values.transportUrl | b64enc | quote }}
12+
{{- end }}
1113
publisher-jwt-key: {{ .Values.publisherJwtKey | default (randAlphaNum 40) | b64enc | quote }}
1214
subscriber-jwt-key: {{ .Values.subscriberJwtKey | default (randAlphaNum 40) | b64enc | quote }}
1315
extra-directives: {{ .Values.extraDirectives | b64enc | quote }}

charts/mercure/values.yaml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ globalOptions: ""
88
caddyExtraConfig: ""
99
# -- Enable the development mode, including the debug UI and the demo.
1010
dev: false
11-
# -- The URL representation of the transport to use.
12-
transportUrl: bolt:///data/mercure.db
11+
# -- Deprecated: The URL representation of the transport to use.
12+
transportUrl: ""
1313
# -- Inject extra Mercure directives in the Caddyfile.
1414
extraDirectives: ""
1515
# -- Inject extra Caddy directives in the Caddyfile.
@@ -25,10 +25,18 @@ subscriberJwtKey: ""
2525
# -- The JWT algorithm to use for subscribers.
2626
subscriberJwtAlg: HS256
2727

28+
# -- Additional environment variables to set
29+
extraEnvs: []
30+
# extraEnvs:
31+
# - name: FOO
32+
# valueFrom:
33+
# secretKeyRef:
34+
# key: FOO
35+
# name: secret-resource
36+
2837
# -- Allows to pass an existing secret name, the above values will be used if empty.
2938
existingSecret: ""
3039
# These keys must exist in the provided secret:
31-
# - transport-url
3240
# - publisher-jwt-key
3341
# - subscriber-jwt-key
3442
# - extra-directives:

docs/UPGRADE.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@
22

33
## 0.17
44

5-
The `TRANSPORT_URL` environment variable has been removed and the `transport_url` directive has been deprecated.
5+
The `MERCURE_TRANSPORT_URL` environment variable and the `transport_url` directive have been deprecated.
66
Use the new `transport` directive instead.
77

8+
The `MERCURE_TRANSPORT_URL` environement variable has been removed from the default `Caddyfile`s,
9+
but a backward compatibility layer is provided.
10+
11+
If both the `transport` and the deprecated `transport_url` are not explicitly set
12+
and the `MERCURE_TRANSPORT_URL` environement variable is set, the `transport_url` will be automatically populated.
13+
To disable this behavior, unset `MERCURE_TRANSPORT_URL` or set it to an empty string.
14+
815
Before:
916

1017
```caddyfile

0 commit comments

Comments
 (0)