From edab7e697d109a42450b0a801930451c9c2c4345 Mon Sep 17 00:00:00 2001 From: David Okulski <32730627+DavidOkulski@users.noreply.github.com> Date: Mon, 13 Jan 2025 13:01:56 -0800 Subject: [PATCH] Created helm charts and dockerfile --- .github/pull_request_template.md | 17 ++++++ .github/workflows/build-and-deploy.yml | 75 ++++++++++++++++++++++++++ dockerfile | 13 +++++ helm/Chart.yaml | 4 ++ helm/templates/deployment.yaml | 28 ++++++++++ helm/templates/network-policy.yaml | 13 +++++ helm/templates/route.yaml | 14 +++++ helm/templates/service.yaml | 13 +++++ helm/values.yaml | 20 +++++++ 9 files changed, 197 insertions(+) create mode 100644 .github/pull_request_template.md create mode 100644 .github/workflows/build-and-deploy.yml create mode 100644 dockerfile create mode 100644 helm/Chart.yaml create mode 100644 helm/templates/deployment.yaml create mode 100644 helm/templates/network-policy.yaml create mode 100644 helm/templates/route.yaml create mode 100644 helm/templates/service.yaml create mode 100644 helm/values.yaml diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..98fdf6d --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,17 @@ +## What changes did you make? + +_Describe the changes you made in this pull request._ + +## Why did you make these changes? + +_Explain why these changes are necessary and what problems they solve._ + +## What alternatives did you consider? + +_Describe any alternative solutions you considered and why._ + +### Checklist + +- [ ] **I have assigned at least one reviewer** +- [ ] **My code meets the style guide** +- [ ] **My code has adequate test coverage (if applicable)** diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml new file mode 100644 index 0000000..1e80d7f --- /dev/null +++ b/.github/workflows/build-and-deploy.yml @@ -0,0 +1,75 @@ +name: Build and Deploy + +on: + push: + branches: + - main + - dev + - test + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + + build_and_push: + runs-on: ubuntu-latest + + steps: + - name: Checkout the repository + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + outputs: + image_tag: ${{ steps.meta.outputs.tags }} + + deploy: + needs: build_and_push + runs-on: ubuntu-latest + + steps: + - name: Checkout the repository + uses: actions/checkout@v4 + + - name: Install oc CLI + uses: redhat-actions/oc-installer@v1 + + - name: Authenticate with OpenShift + uses: redhat-actions/oc-login@v1 + with: + openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }} + namespace: ${{ github.ref == 'refs/heads/main' && secrets.OPENSHIFT_PROD_NAMESPACE || (github.ref == 'refs/heads/dev' && secrets.OPENSHIFT_DEV_NAMESPACE) || secrets.OPENSHIFT_TEST_NAMESPACE }} + openshift_token: ${{ github.ref == 'refs/heads/main' && secrets.OPENSHIFT_PROD_TOKEN || (github.ref == 'refs/heads/dev' && secrets.OPENSHIFT_DEV_TOKEN) || secrets.OPENSHIFT_TEST_TOKEN }} + insecure_skip_tls_verify: true + + - name: Deploy with Helm + run: | + helm upgrade --install communication-layer ./helm --set image.tag=${{ needs.build_and_push.outputs.image_tag }} + + - name: Trigger OpenShift Rollout + run: | + oc rollout restart deployment/communication-layer diff --git a/dockerfile b/dockerfile new file mode 100644 index 0000000..b868972 --- /dev/null +++ b/dockerfile @@ -0,0 +1,13 @@ +FROM node:20 + +WORKDIR /app + +COPY package*.json ./ + +RUN npm install + +COPY . . + +EXPOSE 3030 + +CMD ["npm", "run", "start"] diff --git a/helm/Chart.yaml b/helm/Chart.yaml new file mode 100644 index 0000000..5e87f48 --- /dev/null +++ b/helm/Chart.yaml @@ -0,0 +1,4 @@ +apiVersion: v2 +name: communication-layer +description: A Helm chart for deploying communication layer +version: 0.1.0 diff --git a/helm/templates/deployment.yaml b/helm/templates/deployment.yaml new file mode 100644 index 0000000..baabb23 --- /dev/null +++ b/helm/templates/deployment.yaml @@ -0,0 +1,28 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: communication-layer + labels: + app.kubernetes.io/name: communication-layer +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app.kubernetes.io/name: communication-layer + template: + metadata: + labels: + app.kubernetes.io/name: communication-layer + spec: + containers: + - name: communication-layer + image: "{{ .Values.image.tag }}" + envFrom: + - configMapRef: + name: {{ .Values.secretName }} + ports: + - containerPort: 3030 + resources: {{- toYaml .Values.resources | nindent 12 }} + restartPolicy: Always + strategy: + type: Recreate \ No newline at end of file diff --git a/helm/templates/network-policy.yaml b/helm/templates/network-policy.yaml new file mode 100644 index 0000000..ddfe355 --- /dev/null +++ b/helm/templates/network-policy.yaml @@ -0,0 +1,13 @@ +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + name: allow-from-openshift-ingress +spec: + ingress: + - from: + - namespaceSelector: + matchLabels: + network.openshift.io/policy-group: ingress + podSelector: {} + policyTypes: + - Ingress diff --git a/helm/templates/route.yaml b/helm/templates/route.yaml new file mode 100644 index 0000000..fda374b --- /dev/null +++ b/helm/templates/route.yaml @@ -0,0 +1,14 @@ +apiVersion: route.openshift.io/v1 +kind: Route +metadata: + name: kiln + labels: + app.kubernetes.io/name: kiln +spec: + to: + kind: Service + name: communication-layer + port: + targetPort: 3030 + tls: + termination: edge \ No newline at end of file diff --git a/helm/templates/service.yaml b/helm/templates/service.yaml new file mode 100644 index 0000000..911bb0e --- /dev/null +++ b/helm/templates/service.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Service +metadata: + name: kiln + labels: + app.kubernetes.io/name: communication-layer +spec: + selector: + app.kubernetes.io/name: communication-layer + ports: + - protocol: TCP + port: {{ .Values.service.port }} + targetPort: 3030 \ No newline at end of file diff --git a/helm/values.yaml b/helm/values.yaml new file mode 100644 index 0000000..0311d31 --- /dev/null +++ b/helm/values.yaml @@ -0,0 +1,20 @@ +replicaCount: 1 + +image: + repository: ghcr.io/bcgov/communication-layer + tag: latest + pullPolicy: Always + +service: + type: ClusterIP + port: 3030 + +configMapName: commlayer + +resources: {} + +nodeSelector: {} + +tolerations: [] + +affinity: {}