Skip to content

Commit fe1eefd

Browse files
committed
feat: init renderer server (#8088)
1 parent 0add891 commit fe1eefd

File tree

52 files changed

+826
-329
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+826
-329
lines changed

.github/actions/deploy/deploy.mjs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,14 @@ const createHelmCommand = ({ isDryRun }) => {
9090
const deployCommand = [
9191
`helm upgrade --install affine .github/helm/affine`,
9292
`--namespace ${namespace}`,
93+
`--set-string global.app.buildType="${buildType}"`,
9394
`--set global.ingress.enabled=true`,
9495
`--set-json global.ingress.annotations=\"{ \\"kubernetes.io/ingress.class\\": \\"gce\\", \\"kubernetes.io/ingress.allow-http\\": \\"true\\", \\"kubernetes.io/ingress.global-static-ip-name\\": \\"${STATIC_IP_NAME}\\" }\"`,
9596
`--set-string global.ingress.host="${host}"`,
97+
`--set global.objectStorage.r2.enabled=true`,
98+
`--set-string global.objectStorage.r2.accountId="${R2_ACCOUNT_ID}"`,
99+
`--set-string global.objectStorage.r2.accessKeyId="${R2_ACCESS_KEY_ID}"`,
100+
`--set-string global.objectStorage.r2.secretAccessKey="${R2_SECRET_ACCESS_KEY}"`,
96101
`--set-string global.version="${APP_VERSION}"`,
97102
...redisAndPostgres,
98103
`--set web.replicaCount=${webReplicaCount}`,
@@ -106,10 +111,6 @@ const createHelmCommand = ({ isDryRun }) => {
106111
`--set-string graphql.app.copilot.openai.key="${COPILOT_OPENAI_API_KEY}"`,
107112
`--set-string graphql.app.copilot.fal.key="${COPILOT_FAL_API_KEY}"`,
108113
`--set-string graphql.app.copilot.unsplash.key="${COPILOT_UNSPLASH_API_KEY}"`,
109-
`--set graphql.app.objectStorage.r2.enabled=true`,
110-
`--set-string graphql.app.objectStorage.r2.accountId="${R2_ACCOUNT_ID}"`,
111-
`--set-string graphql.app.objectStorage.r2.accessKeyId="${R2_ACCESS_KEY_ID}"`,
112-
`--set-string graphql.app.objectStorage.r2.secretAccessKey="${R2_SECRET_ACCESS_KEY}"`,
113114
`--set-string graphql.app.mailer.sender="${MAILER_SENDER}"`,
114115
`--set-string graphql.app.mailer.user="${MAILER_USER}"`,
115116
`--set-string graphql.app.mailer.password="${MAILER_PASSWORD}"`,
@@ -125,6 +126,8 @@ const createHelmCommand = ({ isDryRun }) => {
125126
`--set graphql.app.features.syncClientVersionCheck=true`,
126127
`--set sync.replicaCount=${syncReplicaCount}`,
127128
`--set-string sync.image.tag="${imageTag}"`,
129+
`--set-string renderer.image.tag="${imageTag}"`,
130+
`--set renderer.app.host=${host}`,
128131
...serviceAnnotations,
129132
`--timeout 10m`,
130133
flag,

.github/deployment/front/affine.nginx.conf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ server {
66
try_files $uri/index.html $uri/ $uri /admin/index.html;
77
}
88

9-
location ~ ^/(_plugin|assets|imgs|js|plugins|static)/ {
10-
root /app/dist/;
11-
try_files $uri $uri/ =404;
12-
}
13-
149
set $app_root_path /app/dist/;
1510
set $mobile_root /app/dist/;
1611
set_by_lua $affine_env 'return os.getenv("AFFINE_ENV")';
@@ -28,6 +23,11 @@ server {
2823
set $app_root_path $mobile_root;
2924
}
3025

26+
location ~ ^/(_plugin|assets|imgs|js|plugins|static)/ {
27+
root $app_root_path;
28+
try_files $uri $uri/ =404;
29+
}
30+
3131
location / {
3232
root $app_root_path;
3333
index index.html;

.github/deployment/node/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ FROM node:20-bookworm-slim
33
COPY ./packages/backend/server /app
44
COPY ./packages/frontend/web/dist /app/static
55
COPY ./packages/frontend/admin/dist /app/static/admin
6+
COPY ./packages/frontend/mobile/dist /app/static/mobile
67
WORKDIR /app
78

89
RUN apt-get update && \

.github/helm/affine/charts/graphql/templates/deployment.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ spec:
7676
- name: AFFINE_SERVER_HTTPS
7777
value: "{{ .Values.app.https }}"
7878
- name: ENABLE_R2_OBJECT_STORAGE
79-
value: "{{ .Values.app.objectStorage.r2.enabled }}"
79+
value: "{{ .Values.global.objectStorage.r2.enabled }}"
8080
- name: FEATURES_EARLY_ACCESS_PREVIEW
8181
value: "{{ .Values.app.features.earlyAccessPreview }}"
8282
- name: FEATURES_SYNC_CLIENT_VERSION_CHECK
@@ -122,21 +122,21 @@ spec:
122122
- name: DOC_MERGE_USE_JWST_CODEC
123123
value: "true"
124124
{{ end }}
125-
{{ if .Values.app.objectStorage.r2.enabled }}
125+
{{ if .Values.global.objectStorage.r2.enabled }}
126126
- name: R2_OBJECT_STORAGE_ACCOUNT_ID
127127
valueFrom:
128128
secretKeyRef:
129-
name: "{{ .Values.app.objectStorage.r2.secretName }}"
129+
name: "{{ .Values.global.objectStorage.r2.secretName }}"
130130
key: accountId
131131
- name: R2_OBJECT_STORAGE_ACCESS_KEY_ID
132132
valueFrom:
133133
secretKeyRef:
134-
name: "{{ .Values.app.objectStorage.r2.secretName }}"
134+
name: "{{ .Values.global.objectStorage.r2.secretName }}"
135135
key: accessKeyId
136136
- name: R2_OBJECT_STORAGE_SECRET_ACCESS_KEY
137137
valueFrom:
138138
secretKeyRef:
139-
name: "{{ .Values.app.objectStorage.r2.secretName }}"
139+
name: "{{ .Values.global.objectStorage.r2.secretName }}"
140140
key: secretAccessKey
141141
{{ end }}
142142
{{ if .Values.app.captcha.enabled }}

.github/helm/affine/charts/graphql/templates/migration.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,21 @@ spec:
3737
- name: DATABASE_URL
3838
value: postgres://{{ .Values.global.database.user }}:$(DATABASE_PASSWORD)@{{ .Values.global.database.gcloud.cloudSqlInternal }}:{{ .Values.global.database.port }}/{{ .Values.global.database.name }}
3939
{{ end }}
40-
{{ if .Values.app.objectStorage.r2.enabled }}
40+
{{ if .Values.global.objectStorage.r2.enabled }}
4141
- name: R2_OBJECT_STORAGE_ACCOUNT_ID
4242
valueFrom:
4343
secretKeyRef:
44-
name: "{{ .Values.app.objectStorage.r2.secretName }}"
44+
name: "{{ .Values.global.objectStorage.r2.secretName }}"
4545
key: accountId
4646
- name: R2_OBJECT_STORAGE_ACCESS_KEY_ID
4747
valueFrom:
4848
secretKeyRef:
49-
name: "{{ .Values.app.objectStorage.r2.secretName }}"
49+
name: "{{ .Values.global.objectStorage.r2.secretName }}"
5050
key: accessKeyId
5151
- name: R2_OBJECT_STORAGE_SECRET_ACCESS_KEY
5252
valueFrom:
5353
secretKeyRef:
54-
name: "{{ .Values.app.objectStorage.r2.secretName }}"
54+
name: "{{ .Values.global.objectStorage.r2.secretName }}"
5555
key: secretAccessKey
5656
{{ end }}
5757
resources:

.github/helm/affine/charts/graphql/templates/r2-secret.yaml

Lines changed: 0 additions & 11 deletions
This file was deleted.

.github/helm/affine/charts/graphql/values.yaml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,7 @@ app:
2929
secretName: copilot
3030
openai:
3131
key: ''
32-
objectStorage:
33-
r2:
34-
enabled: false
35-
secretName: r2
36-
accountId: ''
37-
accessKeyId: ''
38-
secretAccessKey: ''
39-
oauth:
32+
oauth:
4033
google:
4134
enabled: false
4235
secretName: oauth-google
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v2
2+
name: renderer
3+
description: AFFiNE renderer server
4+
type: application
5+
version: 0.0.0
6+
appVersion: "0.16.0"
7+
dependencies:
8+
- name: gcloud-sql-proxy
9+
version: 0.0.0
10+
repository: "file://../gcloud-sql-proxy"
11+
condition: .global.database.gcloud.enabled
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
1. Get the application URL by running these commands:
2+
{{- if contains "NodePort" .Values.service.type }}
3+
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "renderer.fullname" . }})
4+
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
5+
echo http://$NODE_IP:$NODE_PORT
6+
{{- else if contains "LoadBalancer" .Values.service.type }}
7+
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
8+
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "renderer.fullname" . }}'
9+
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "renderer.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
10+
echo http://$SERVICE_IP:{{ .Values.service.port }}
11+
{{- else if contains "ClusterIP" .Values.service.type }}
12+
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "renderer.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
13+
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
14+
echo "Visit http://127.0.0.1:8080 to use your application"
15+
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
16+
{{- end }}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "renderer.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11+
If release name contains chart name it will be used as a full name.
12+
*/}}
13+
{{- define "renderer.fullname" -}}
14+
{{- if .Values.fullnameOverride }}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16+
{{- else }}
17+
{{- $name := default .Chart.Name .Values.nameOverride }}
18+
{{- if contains $name .Release.Name }}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20+
{{- else }}
21+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22+
{{- end }}
23+
{{- end }}
24+
{{- end }}
25+
26+
{{/*
27+
Create chart name and version as used by the chart label.
28+
*/}}
29+
{{- define "renderer.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "renderer.labels" -}}
37+
helm.sh/chart: {{ include "renderer.chart" . }}
38+
{{ include "renderer.selectorLabels" . }}
39+
{{- if .Chart.AppVersion }}
40+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
41+
{{- end }}
42+
app.kubernetes.io/managed-by: {{ .Release.Service }}
43+
monitoring: enabled
44+
{{- end }}
45+
46+
{{/*
47+
Selector labels
48+
*/}}
49+
{{- define "renderer.selectorLabels" -}}
50+
app.kubernetes.io/name: {{ include "renderer.name" . }}
51+
app.kubernetes.io/instance: {{ .Release.Name }}
52+
{{- end }}
53+
54+
{{/*
55+
Create the name of the service account to use
56+
*/}}
57+
{{- define "renderer.serviceAccountName" -}}
58+
{{- if .Values.serviceAccount.create }}
59+
{{- default (include "renderer.fullname" .) .Values.serviceAccount.name }}
60+
{{- else }}
61+
{{- default "default" .Values.serviceAccount.name }}
62+
{{- end }}
63+
{{- end }}

0 commit comments

Comments
 (0)