chore(deploy): prod

This commit is contained in:
incubator4 2024-01-01 11:29:46 +08:00
parent 7e1ab9d498
commit a3cb618a03
7 changed files with 30 additions and 216 deletions

View File

@ -1,86 +0,0 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: xlog-caddy
namespace: crossbell
data:
Caddyfile: |
{
storage redis {
}
on_demand_tls {
ask http://localhost:5000/
}
}
xlog.app, *.xlog.app {
tls jeff@rss3.io {
dns cloudflare {env.CF_API_TOKEN}
}
reverse_proxy xlog-internal.crossbell.svc:3000 {
header_up x-forwarded-proto http
}
}
:8080 {
metrics
}
:80, :443 {
tls jeff@rss3.io {
on_demand
}
reverse_proxy xlog-internal.crossbell.svc:3000 {
header_up x-forwarded-proto http
}
}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: xlog-caddy-validator
namespace: crossbell
data:
app.py: |
import requests
from flask import Flask, request, Response
app = Flask(__name__)
@app.route("/")
def check_domain():
domain = request.args.get("domain")
if not domain:
return Response(status=404)
if domain.endswith('.xlog.app') or domain == "xlog.app":
return Response(status=200)
# get TXT
res = requests.get("https://cloudflare-dns.com/dns-query", params={
"name": f"_xlog-challenge.{domain}",
"type": "TXT",
}, headers={"Accept": "application/dns-json"})
if res.status_code != 200:
return Response(status=res.status_code)
answer = res.json().get("Answer") or [{}]
tenant = answer[0].get("data", "").replace('"', "")
if not tenant:
return Response(status=404)
# check crossbell
res = requests.get(f"https://indexer.crossbell.io/v1/handles/{tenant}/character")
if res.status_code != 200:
return Response(status=404)
attributes = res.json().get("metadata", {}).get("content", {}).get("attributes", [])
for d in attributes:
if d.get("trait_type") == "xlog_custom_domain":
print(d)
xlog_custom_domain = d.get("value", "").lower()
if xlog_custom_domain == domain:
return Response(status=200)
return Response(status=404)

View File

@ -25,13 +25,8 @@ spec:
prometheus.io/scrape: "true"
spec:
enableServiceLinks: false
tolerations:
- key: "rss3.io/usage"
operator: "Equal"
value: "csb-others"
effect: "NoSchedule"
initContainers:
- image: $IMAGE_TAG_RELEASE
- image: rss3/xlog
envFrom:
- secretRef:
name: xlog
@ -40,7 +35,7 @@ spec:
command: ["/bin/sh", "-c"]
args: ["npm install -g prisma; npm run prisma:migrate:deploy"]
containers:
- image: $IMAGE_TAG_RELEASE
- image: rss3/xlog
imagePullPolicy: Always
name: xlog
envFrom:
@ -74,71 +69,3 @@ spec:
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: xlog-caddy
namespace: crossbell
spec:
replicas: 3
selector:
matchLabels:
app: xlog-caddy
template:
metadata:
labels:
app: xlog-caddy
annotations:
prometheus.io/path: /metrics
prometheus.io/port: "8080"
prometheus.io/scrape: "true"
spec:
containers:
- name: caddy
image: kindjeff/caddy-tlsredis-docker
imagePullPolicy: Always
command: ["caddy", "run", "-config", "/app/Caddyfile"]
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 500m
memory: 512Mi
envFrom:
- secretRef:
name: xlog-caddy
ports:
- containerPort: 80
name: http
- containerPort: 443
name: https
volumeMounts:
- name: caddyfile
mountPath: /app
- name: caddy-validator
image: python
command: ["/bin/sh", "-c"]
args: ["pip install flask requests; flask --app=app run"]
resources:
requests:
cpu: 50m
memory: 64Mi
limits:
cpu: 100m
memory: 128Mi
ports:
- containerPort: 5000
name: http
volumeMounts:
- name: validator
mountPath: /app.py
subPath: app.py
volumes:
- name: caddyfile
configMap:
name: xlog-caddy
- name: validator
configMap:
name: xlog-caddy-validator

View File

@ -4,7 +4,7 @@ metadata:
name: xlog
namespace: crossbell
spec:
maxReplicas: 11
maxReplicas: 14
minReplicas: 7
scaleTargetRef:
apiVersion: apps/v1
@ -17,23 +17,3 @@ spec:
target:
type: Utilization
averageUtilization: 300
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: xlog-caddy
namespace: crossbell
spec:
maxReplicas: 20
minReplicas: 3
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: xlog-caddy
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 300

View File

@ -0,0 +1,8 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- deploy.yaml
- secret.yaml
- svc.yaml
- hpa

16
deploy/prod/secret.yaml Normal file
View File

@ -0,0 +1,16 @@
# Remember to add it in env.production because it is the nextjs project
apiVersion: v1
stringData:
REDIS_URL: <REDIS_URL>
DATABASE_URL: <DATABASE_URL>
SIMPLEHASH_API_KEY: <SIMPLEHASH_API_KEY>
OPENAI_API_KEY: <OPENAI_API_KEY>
ANONYMOUS_ACCOUNT_PRIVATEKEY: <ANONYMOUS_ACCOUNT_PRIVATEKEY>
PORTFOLIO_GITHUB_TOKEN: <PORTFOLIO_GITHUB_TOKEN>
kind: Secret
metadata:
name: xlog
namespace: crossbell
annotations:
avp.kubernetes.io/path: "kv/data/crossbell/xlog"
type: Opaque

View File

@ -1,27 +0,0 @@
# Remember to add it in env.production because it is the nextjs project
apiVersion: v1
stringData:
REDIS_URL: ${REDIS_URL}
DATABASE_URL: ${PG_CONN_STRING}
SIMPLEHASH_API_KEY: ${SIMPLEHASH_API_KEY}
OPENAI_API_KEY: ${OPENAI_API_KEY}
ANONYMOUS_ACCOUNT_PRIVATEKEY: ${ANONYMOUS_ACCOUNT_PRIVATEKEY}
kind: Secret
metadata:
name: xlog
namespace: crossbell
type: Opaque
---
apiVersion: v1
stringData:
CADDY_CLUSTERING_REDIS_HOST: ${CADDY_CLUSTERING_REDIS_HOST}
CADDY_CLUSTERING_REDIS_PORT: "6379"
CADDY_CLUSTERING_REDIS_USERNAME: ""
CADDY_CLUSTERING_REDIS_PASSWORD: ${CADDY_CLUSTERING_REDIS_PASSWORD}
CADDY_CLUSTERING_REDIS_DB: "0"
CF_API_TOKEN: ${CF_API_TOKEN}
kind: Secret
metadata:
name: xlog-caddy
namespace: crossbell
type: Opaque

View File

@ -1,18 +1,14 @@
apiVersion: v1
kind: Service
metadata:
name: xlog-lb
name: xlog-internal
namespace: crossbell
spec:
type: LoadBalancer
type: ClusterIP
selector:
app: xlog
ports:
- name: http
protocol: TCP
port: 80
targetPort: 80
- name: https
protocol: TCP
port: 443
targetPort: 443
targetPort: 3000