diff --git a/.gitea/workflows/deploy.yaml b/.gitea/workflows/deploy.yaml new file mode 100644 index 0000000..d71d0be --- /dev/null +++ b/.gitea/workflows/deploy.yaml @@ -0,0 +1,46 @@ +name: Build and Deploy Web + +on: + push: + branches: + - main + - master + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to Huawei Cloud SWR + uses: docker/login-action@v2 + with: + registry: ${{ secrets.SWR_SERVER }} + username: ${{ secrets.SWR_USERNAME }} + password: ${{ secrets.SWR_PASSWORD }} + + - name: Build and Push Web + uses: docker/build-push-action@v4 + with: + context: . + push: true + tags: ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/rtc-web:latest + + - name: Deploy to K3s + uses: Azure/k8s-set-context@v3 + with: + method: kubeconfig + kubeconfig: ${{ secrets.KUBE_CONFIG }} + + - name: Update K8s Manifests + run: | + sed -i "s|\${CI_REGISTRY_IMAGE}/web:latest|${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/rtc-web:latest|g" k8s/web-deployment.yaml + + kubectl apply -f k8s/web-deployment.yaml + kubectl apply -f k8s/ingress.yaml + + kubectl rollout restart deployment/rtc-web diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..aa69866 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +# Build stage +FROM node:20-alpine as build-stage + +WORKDIR /app + +COPY package*.json ./ + +RUN npm install + +COPY . . + +RUN npm run build + +# Production stage +FROM nginx:stable-alpine as production-stage + +COPY --from=build-stage /app/dist /usr/share/nginx/html + +# Copy custom nginx config if needed, otherwise default is used +# COPY nginx.conf /etc/nginx/conf.d/default.conf + +EXPOSE 80 + +CMD ["nginx", "-g", "daemon off;"] diff --git a/k8s/ingress.yaml b/k8s/ingress.yaml new file mode 100644 index 0000000..e329c3c --- /dev/null +++ b/k8s/ingress.yaml @@ -0,0 +1,31 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: rtc-ingress + annotations: + kubernetes.io/ingress.class: "traefik" +spec: + rules: + - http: + paths: + - path: /api + pathType: Prefix + backend: + service: + name: rtc-backend + port: + number: 8000 + - path: /admin + pathType: Prefix + backend: + service: + name: rtc-backend + port: + number: 8000 + - path: / + pathType: Prefix + backend: + service: + name: rtc-web + port: + number: 80 diff --git a/k8s/web-deployment.yaml b/k8s/web-deployment.yaml new file mode 100644 index 0000000..c9f1b5b --- /dev/null +++ b/k8s/web-deployment.yaml @@ -0,0 +1,41 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: rtc-web + labels: + app: rtc-web +spec: + replicas: 1 + selector: + matchLabels: + app: rtc-web + template: + metadata: + labels: + app: rtc-web + spec: + containers: + - name: rtc-web + image: ${CI_REGISTRY_IMAGE}/web:latest + imagePullPolicy: Always + ports: + - containerPort: 80 + resources: + requests: + memory: "64Mi" + cpu: "100m" + limits: + memory: "512Mi" + cpu: "500m" +--- +apiVersion: v1 +kind: Service +metadata: + name: rtc-web +spec: + selector: + app: rtc-web + ports: + - protocol: TCP + port: 80 + targetPort: 80