diff --git a/.github/workflows/portal-dev-deploy.yml b/.github/workflows/portal-dev-deploy.yml new file mode 100644 index 0000000..3ffcf2c --- /dev/null +++ b/.github/workflows/portal-dev-deploy.yml @@ -0,0 +1,46 @@ +name: Deploy to Production + +on: + workflow_dispatch: + inputs: + tag: + type: string + description: The tag to deploy + required: true + +env: + KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }} + DOCKER_REGISTRY: your-registry + DOCKER_IMAGE: your-app + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up kubectl + uses: azure/k8s-set-context@v1 + with: + kubeconfig: ${{ secrets.DEV_KUBE_CONFIG }} + + - name: Install Helm + uses: azure/setup-helm@v3 + with: + version: 'v3.12.0' + + - name: Update image tag in values file + run: | + sed -i "s/tag: .*/tag: ${{ github.event.inputs.tag }}/" charts/portal/environments/dev.yaml + + - name: Commit changes + run: | + git config --global user.name 'GitHub Actions' + git config --global user.email 'github-actions@github.com' + git add charts/portal/environments/dev.yaml + git commit -m "Update image tag to ${{ github.event.inputs.tag }}" + git push + + - name: Deploy to dev + run: | + helm upgrade portal portal -n portal -f portal/values.yaml -f portal/environments/dev.yaml diff --git a/.github/workflows/portal-production-deploy.yml b/.github/workflows/portal-production-deploy.yml new file mode 100644 index 0000000..9f80e7e --- /dev/null +++ b/.github/workflows/portal-production-deploy.yml @@ -0,0 +1,46 @@ +name: Deploy to Production + +on: + workflow_dispatch: + inputs: + tag: + type: string + description: The tag to deploy + required: true + +env: + KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }} + DOCKER_REGISTRY: your-registry + DOCKER_IMAGE: your-app + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up kubectl + uses: azure/k8s-set-context@v1 + with: + kubeconfig: ${{ secrets.PRODUCTION_KUBE_CONFIG }} + + - name: Install Helm + uses: azure/setup-helm@v3 + with: + version: 'v3.12.0' + + - name: Update image tag in values file + run: | + sed -i "s/tag: .*/tag: ${{ github.event.inputs.tag }}/" charts/portal/environments/production.yaml + + - name: Commit changes + run: | + git config --global user.name 'GitHub Actions' + git config --global user.email 'github-actions@github.com' + git add charts/portal/environments/production.yaml + git commit -m "Update image tag to ${{ github.event.inputs.tag }}" + git push + + - name: Deploy to production + run: | + helm upgrade portal portal -n portal -f portal/values.yaml -f portal/environments/production.yaml diff --git a/charts/portal/Chart.yaml b/charts/portal/Chart.yaml new file mode 100644 index 0000000..e973a84 --- /dev/null +++ b/charts/portal/Chart.yaml @@ -0,0 +1,4 @@ +apiVersion: v2 +name: portal +description: A Helm chart for deploying the portal +version: 0.1.0 diff --git a/charts/portal/environments/dev.yaml b/charts/portal/environments/dev.yaml new file mode 100644 index 0000000..c53a732 --- /dev/null +++ b/charts/portal/environments/dev.yaml @@ -0,0 +1,20 @@ +image: + tag: c819a2996f8d96cfcadc73cba625d01d70f8df2b + +environment: dev +replicaCount: 1 + +ingress: + hosts: + - host: portal.dev.codetogether.com + paths: + - path: / + pathType: Prefix + +resources: + limits: + cpu: 300m + memory: 384Mi + requests: + cpu: 100m + memory: 128Mi diff --git a/charts/portal/environments/production.yaml b/charts/portal/environments/production.yaml new file mode 100644 index 0000000..313bff2 --- /dev/null +++ b/charts/portal/environments/production.yaml @@ -0,0 +1,20 @@ +environment: production +replicaCount: 2 +image: + tag: prod-1c73b5aa304002a7412eadd86f063350ec78db8d + +ingress: + enabled: false + hosts: + - host: app.codetogether.com + paths: + - path: / + pathType: Prefix + +resources: + limits: + cpu: 500m + memory: 512Mi + requests: + cpu: 200m + memory: 256Mi \ No newline at end of file diff --git a/charts/portal/templates/deployment.yaml b/charts/portal/templates/deployment.yaml new file mode 100644 index 0000000..48d6902 --- /dev/null +++ b/charts/portal/templates/deployment.yaml @@ -0,0 +1,65 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ .Release.Name }} + labels: + app: {{ .Release.Name }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app: {{ .Release.Name }} + template: + metadata: + labels: + app: {{ .Release.Name }} + spec: + imagePullSecrets: + {{- toYaml .Values.imagePullSecrets | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + command: [ "yarn", "run", "start:backend" ] + args: [ "--hostname=0.0.0.0", "--port=3000" ] + ports: + - containerPort: 3000 + resources: + {{- toYaml .Values.resources | nindent 12 }} + envFrom: + - secretRef: + name: portal-secrets + readinessProbe: + httpGet: + path: /saas-admin + port: 3000 + initialDelaySeconds: 5 + periodSeconds: 5 + failureThreshold: 5 + successThreshold: 1 + livenessProbe: + httpGet: + path: /saas-admin + port: 3000 + initialDelaySeconds: 5 + periodSeconds: 5 + failureThreshold: 5 + successThreshold: 1 + startupProbe: + httpGet: + path: /saas-admin + port: 3000 + initialDelaySeconds: 5 + periodSeconds: 5 + failureThreshold: 20 + successThreshold: 1 + volumeMounts: + - name: kubeconfig + mountPath: /root/.kube/config + subPath: kube-config + volumes: + - name: kubeconfig + configMap: + name: portal-kubeconfig + defaultMode: 0600 + \ No newline at end of file diff --git a/charts/portal/templates/ingress.yaml b/charts/portal/templates/ingress.yaml new file mode 100644 index 0000000..641d716 --- /dev/null +++ b/charts/portal/templates/ingress.yaml @@ -0,0 +1,23 @@ +{{- if .Values.ingress.enabled -}} +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ .Release.Name }} +spec: + ingressClassName: {{ .Values.ingress.className }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + pathType: {{ .pathType }} + backend: + service: + name: {{ $.Release.Name }} + port: + number: {{ $.Values.service.port }} + {{- end }} + {{- end }} +{{- end }} \ No newline at end of file diff --git a/charts/portal/templates/service.yaml b/charts/portal/templates/service.yaml new file mode 100644 index 0000000..f95d4ed --- /dev/null +++ b/charts/portal/templates/service.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ .Release.Name }} + labels: + app: {{ .Release.Name }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: 3000 + protocol: TCP + selector: + app: {{ .Release.Name }} \ No newline at end of file diff --git a/charts/portal/values.yaml b/charts/portal/values.yaml new file mode 100644 index 0000000..b6f6939 --- /dev/null +++ b/charts/portal/values.yaml @@ -0,0 +1,24 @@ +# Default values for the application +replicaCount: 2 + +image: + repository: registry.digitalocean.com/codetogether-registry/portal + tag: latest + pullPolicy: Always + +imagePullSecrets: + - name: digitalocean-registry + +service: + type: ClusterIP + port: 3000 + +resources: + limits: + cpu: 500m + memory: 512Mi + requests: + cpu: 200m + memory: 256Mi + +