From 695577d53ac176a6a732f4c9a205310cb24c6a06 Mon Sep 17 00:00:00 2001 From: tone Date: Sat, 20 Dec 2025 13:26:22 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E6=8F=90=E4=BA=A4deploy=E6=96=87?= =?UTF-8?q?=E4=BB=B6=EF=BC=8Cstep.run=E4=BF=AE=E6=94=B9=E4=B8=BA=E7=9B=B8?= =?UTF-8?q?=E5=AF=B9=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/deploy.yml | 6 +-- apps/deploy/backend-deployment.yaml | 77 ++++++++++++++++++++++++++++ apps/deploy/backend-secret.yaml | 13 +++++ apps/deploy/frontend-deployment.yaml | 32 ++++++++++++ apps/deploy/postgres-deployment.yaml | 42 +++++++++++++++ apps/deploy/postgres-nodeport.yaml | 12 +++++ apps/deploy/postgres-secret.yaml | 9 ++++ 7 files changed, 188 insertions(+), 3 deletions(-) create mode 100644 apps/deploy/backend-deployment.yaml create mode 100644 apps/deploy/backend-secret.yaml create mode 100644 apps/deploy/frontend-deployment.yaml create mode 100644 apps/deploy/postgres-deployment.yaml create mode 100644 apps/deploy/postgres-nodeport.yaml create mode 100644 apps/deploy/postgres-secret.yaml diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index fb0c1e1..f9daef1 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -21,13 +21,13 @@ jobs: - name: Build and push backend image run: | - cd /workspace/tone/tonePage/apps/backend + cd apps/backend docker build -t localhost:5000/backend:latest . docker push localhost:5000/backend:latest - name: Build and push frontend image run: | - cd /workspace/tone/tonePage/apps/frontend + cd apps/frontend docker build \ --build-arg API_BASE="http://backend-service:3001" \ -t localhost:5000/frontend:latest . @@ -35,7 +35,7 @@ jobs: - name: Deploy to K3s run: | - cd /workspace/tone/tonePage/apps/deploy + cd apps/deploy kubectl apply -f postgres-deployment.yaml kubectl apply -f backend-deployment.yaml kubectl apply -f frontend-deployment.yaml diff --git a/apps/deploy/backend-deployment.yaml b/apps/deploy/backend-deployment.yaml new file mode 100644 index 0000000..c6d1933 --- /dev/null +++ b/apps/deploy/backend-deployment.yaml @@ -0,0 +1,77 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: backend +spec: + replicas: 1 + selector: + matchLabels: + app: backend + template: + metadata: + labels: + app: backend + spec: + containers: + - name: backend + image: localhost:5000/backend:latest + ports: + - containerPort: 3001 + env: + - name: DATABASE_HOST + value: "postgres-service" + - name: DATABASE_PORT + value: "5432" + - name: DATABASE_NAME + value: "tone_page" + - name: DATABASE_USERNAME + value: "tone_page" + - name: DATABASE_PASSWORD + valueFrom: + secretKeyRef: + name: backend-secret + key: DATABASE_PASSWORD + - name: ALIYUN_ACCESS_KEY_ID + valueFrom: + secretKeyRef: + name: backend-secret + key: ALIYUN_ACCESS_KEY_ID + - name: ALIYUN_ACCESS_KEY_SECRET + valueFrom: + secretKeyRef: + name: backend-secret + key: ALIYUN_ACCESS_KEY_SECRET + - name: ALIYUN_OSS_STS_ROLE_ARN + valueFrom: + secretKeyRef: + name: backend-secret + key: ALIYUN_OSS_STS_ROLE_ARN + - name: WEBAUTHN_RP_ID + valueFrom: + secretKeyRef: + name: backend-secret + key: WEBAUTHN_RP_ID + - name: WEBAUTHN_ORIGIN + valueFrom: + secretKeyRef: + name: backend-secret + key: WEBAUTHN_ORIGIN + - name: WEBAUTHN_RP_NAME + valueFrom: + secretKeyRef: + name: backend-secret + key: WEBAUTHN_RP_NAME + - name: NODE_ENV + value: "production" +--- +apiVersion: v1 +kind: Service +metadata: + name: backend-service +spec: + selector: + app: backend + ports: + - protocol: TCP + port: 3001 + targetPort: 3001 diff --git a/apps/deploy/backend-secret.yaml b/apps/deploy/backend-secret.yaml new file mode 100644 index 0000000..d434c8a --- /dev/null +++ b/apps/deploy/backend-secret.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Secret +metadata: + name: backend-secret +type: Opaque +# stringData: +# DATABASE_PASSWORD: +# ALIYUN_ACCESS_KEY_ID: +# ALIYUN_ACCESS_KEY_SECRET: +# ALIYUN_OSS_STS_ROLE_ARN: +# WEBAUTHN_RP_ID: +# WEBAUTHN_ORIGIN: +# WEBAUTHN_RP_NAME: diff --git a/apps/deploy/frontend-deployment.yaml b/apps/deploy/frontend-deployment.yaml new file mode 100644 index 0000000..a38e68c --- /dev/null +++ b/apps/deploy/frontend-deployment.yaml @@ -0,0 +1,32 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: frontend +spec: + replicas: 1 + selector: + matchLabels: + app: frontend + template: + metadata: + labels: + app: frontend + spec: + containers: + - name: frontend + image: localhost:5000/frontend:latest + ports: + - containerPort: 3000 +--- +apiVersion: v1 +kind: Service +metadata: + name: frontend-service +spec: + type: NodePort + ports: + - port: 3000 + targetPort: 3000 + nodePort: 30000 + selector: + app: frontend diff --git a/apps/deploy/postgres-deployment.yaml b/apps/deploy/postgres-deployment.yaml new file mode 100644 index 0000000..592d8c5 --- /dev/null +++ b/apps/deploy/postgres-deployment.yaml @@ -0,0 +1,42 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: postgres +spec: + replicas: 1 + selector: + matchLabels: + app: postgres + template: + metadata: + labels: + app: postgres + spec: + containers: + - name: postgres + image: postgres:17-alpine + ports: + - containerPort: 5432 + envFrom: + - secretRef: + name: postgres-secret + volumeMounts: + - name: postgres-storage + mountPath: /var/lib/postgresql/data + volumes: + - name: postgres-storage + hostPath: + path: /var/lib/postgres-data + type: DirectoryOrCreate +--- +apiVersion: v1 +kind: Service +metadata: + name: postgres-service +spec: + selector: + app: postgres + ports: + - protocol: TCP + port: 5432 + targetPort: 5432 diff --git a/apps/deploy/postgres-nodeport.yaml b/apps/deploy/postgres-nodeport.yaml new file mode 100644 index 0000000..4cd1a94 --- /dev/null +++ b/apps/deploy/postgres-nodeport.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: postgres-nodeport +spec: + type: NodePort + ports: + - port: 5432 + targetPort: 5432 + nodePort: 30001 + selector: + app: postgres diff --git a/apps/deploy/postgres-secret.yaml b/apps/deploy/postgres-secret.yaml new file mode 100644 index 0000000..c4d49b5 --- /dev/null +++ b/apps/deploy/postgres-secret.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: Secret +metadata: + name: postgres-secret +type: Opaque +# stringData: +# POSTGRES_USER: +# POSTGRES_PASSWORD: +# POSTGRES_DB: