Skip to content

Commit 786e6c2

Browse files
authored
Merge pull request #10 from toddaheath/fix/urls-cors-config
fix: wire correct URLs and CORS for dev and prod environments
2 parents fd238cf + d164d6c commit 786e6c2

File tree

11 files changed

+84
-9
lines changed

11 files changed

+84
-9
lines changed

.github/workflows/deploy-dev.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ jobs:
8888
run: |
8989
helm upgrade --install shed-builder deploy/helm/shed-builder \
9090
--namespace dev --create-namespace \
91+
-f deploy/helm/shed-builder/values-dev.yaml \
9192
--set api.image.repository=${{ vars.ACR_LOGIN_SERVER }}/shed-builder-api \
9293
--set api.image.tag=${{ needs.build-and-push.outputs.image-tag }} \
9394
--set ui.image.repository=${{ vars.ACR_LOGIN_SERVER }}/shed-builder-ui \

.github/workflows/deploy-prod.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,10 @@ jobs:
9393
run: |
9494
helm upgrade --install shed-builder deploy/helm/shed-builder \
9595
--namespace production --create-namespace \
96+
-f deploy/helm/shed-builder/values-prod.yaml \
9697
--set api.image.repository=${{ env.REGISTRY }}/${{ github.repository_owner }}/shed-builder-api \
9798
--set api.image.tag=${{ needs.build-and-push.outputs.image-tag }} \
9899
--set ui.image.repository=${{ env.REGISTRY }}/${{ github.repository_owner }}/shed-builder-ui \
99100
--set ui.image.tag=${{ needs.build-and-push.outputs.image-tag }} \
100101
--set postgres.password=${{ secrets.DB_PASSWORD }} \
101-
--set ingress.enabled=true \
102-
--set ingress.host=${{ vars.PRODUCTION_HOST }} \
103102
--wait --timeout 5m

deploy/helm/shed-builder/templates/api-deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ spec:
3535
value: "Host={{ include "shed-builder.fullname" . }}-postgres;Database={{ .Values.postgres.database }};Username={{ .Values.postgres.username }};Password=$(DB_PASSWORD)"
3636
- name: ASPNETCORE_ENVIRONMENT
3737
value: Production
38+
- name: Cors__AllowedOrigins
39+
value: {{ .Values.api.corsAllowedOrigins | quote }}
3840
resources:
3941
{{- toYaml .Values.api.resources | nindent 12 }}
4042
livenessProbe:

deploy/helm/shed-builder/templates/ingress.yaml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,30 @@ metadata:
55
name: {{ include "shed-builder.fullname" . }}
66
labels:
77
{{- include "shed-builder.labels" . | nindent 4 }}
8+
{{- with .Values.ingress.annotations }}
9+
annotations:
10+
{{- toYaml . | nindent 4 }}
11+
{{- end }}
812
spec:
913
ingressClassName: {{ .Values.ingress.className }}
14+
{{- if .Values.ingress.tls }}
15+
tls:
16+
{{- toYaml .Values.ingress.tls | nindent 4 }}
17+
{{- end }}
1018
rules:
11-
- host: {{ .Values.ingress.host }}
19+
- host: {{ .Values.ingress.apiHost }}
1220
http:
1321
paths:
14-
- path: /api
22+
- path: /
1523
pathType: Prefix
1624
backend:
1725
service:
1826
name: {{ include "shed-builder.fullname" . }}-api
1927
port:
2028
number: {{ .Values.api.port }}
29+
- host: {{ .Values.ingress.uiHost }}
30+
http:
31+
paths:
2132
- path: /
2233
pathType: Prefix
2334
backend:

deploy/helm/shed-builder/templates/ui-deployment.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,11 @@ spec:
2727
- containerPort: {{ .Values.ui.port }}
2828
resources:
2929
{{- toYaml .Values.ui.resources | nindent 12 }}
30+
volumeMounts:
31+
- name: nginx-config
32+
mountPath: /etc/nginx/conf.d/default.conf
33+
subPath: default.conf
34+
volumes:
35+
- name: nginx-config
36+
configMap:
37+
name: {{ include "shed-builder.fullname" . }}-nginx
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: {{ include "shed-builder.fullname" . }}-nginx
5+
labels:
6+
{{- include "shed-builder.labels" . | nindent 4 }}
7+
data:
8+
default.conf: |
9+
server {
10+
listen 80;
11+
root /usr/share/nginx/html;
12+
index index.html;
13+
14+
location /api/ {
15+
proxy_pass http://{{ include "shed-builder.fullname" . }}-api:{{ .Values.api.port }}/api/;
16+
proxy_set_header Host $host;
17+
proxy_set_header X-Real-IP $remote_addr;
18+
}
19+
20+
location / {
21+
try_files $uri $uri/ /index.html;
22+
}
23+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
api:
2+
corsAllowedOrigins: "https://ballistics-calc.dev.heathrobotics.io"
3+
4+
ingress:
5+
enabled: true
6+
apiHost: shed-builder-api.dev.heathrobotics.io
7+
uiHost: ballistics-calc.dev.heathrobotics.io
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
api:
2+
corsAllowedOrigins: "https://shed-builder.heathrobotics.io"
3+
4+
ingress:
5+
enabled: true
6+
apiHost: shed-builder-api.heathrobotics.io
7+
uiHost: shed-builder.heathrobotics.io

deploy/helm/shed-builder/values.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ api:
55
pullPolicy: IfNotPresent
66
replicas: 1
77
port: 8080
8+
corsAllowedOrigins: ""
89
resources:
910
requests:
1011
cpu: 100m
@@ -49,4 +50,7 @@ autoscaling:
4950
ingress:
5051
enabled: false
5152
className: nginx
52-
host: shed-builder.local
53+
annotations: {}
54+
apiHost: shed-builder-api.local
55+
uiHost: shed-builder.local
56+
tls: []

src/ShedBuilder.Api/Program.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,26 @@
3333

3434
QuestPDF.Settings.License = QuestPDF.Infrastructure.LicenseType.Community;
3535

36+
var corsOrigins = builder.Configuration["Cors:AllowedOrigins"]
37+
?.Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries)
38+
?? [];
39+
3640
builder.Services.AddCors(options =>
3741
{
3842
options.AddDefaultPolicy(policy =>
3943
{
40-
policy.AllowAnyOrigin()
41-
.AllowAnyHeader()
42-
.AllowAnyMethod();
44+
if (corsOrigins.Length > 0)
45+
{
46+
policy.WithOrigins(corsOrigins)
47+
.AllowAnyHeader()
48+
.AllowAnyMethod();
49+
}
50+
else
51+
{
52+
policy.AllowAnyOrigin()
53+
.AllowAnyHeader()
54+
.AllowAnyMethod();
55+
}
4356
});
4457
});
4558

0 commit comments

Comments
 (0)