Jelajahi Sumber

Adding helm chart for deployment

bodicsek 3 tahun lalu
induk
melakukan
7a38596384

+ 0 - 2
.npmrc

@@ -1,2 +0,0 @@
-registry=https://artifactory.oci.oraclecorp.com/api/npm/global-dev-npm/
-@os:registry=https://artifacthub-phx.oci.oraclecorp.com/api/npm/os-npm-release/

+ 1 - 1
Dockerfile

@@ -1,4 +1,4 @@
-FROM docker-remote.artifactory.oci.oraclecorp.com/oraclelinux:8
+FROM container-registry.oracle.com/os/oraclelinux:8
 
 
 RUN dnf upgrade -y && \
 RUN dnf upgrade -y && \
     dnf module enable nodejs:16 -y && \
     dnf module enable nodejs:16 -y && \

+ 0 - 19
deployment/deployment.yaml

@@ -1,19 +0,0 @@
-apiVersion: apps/v1
-kind: Deployment
-metadata:
-  name: occ-fw-backend-deployment
-spec:
-  selector:
-    matchLabels:
-      app: occ-fw-backend
-  replicas: 1
-  template:
-    metadata:
-      labels:
-        app: occ-fw-backend
-    spec:
-      containers:
-        - name: occ-fw-backend
-          image: occ-fw-backend:0.0.1
-          ports:
-          - containerPort: 3000

+ 23 - 0
deployment/helm-chart/.helmignore

@@ -0,0 +1,23 @@
+# Patterns to ignore when building packages.
+# This supports shell glob matching, relative path matching, and
+# negation (prefixed with !). Only one pattern per line.
+.DS_Store
+# Common VCS dirs
+.git/
+.gitignore
+.bzr/
+.bzrignore
+.hg/
+.hgignore
+.svn/
+# Common backup files
+*.swp
+*.bak
+*.tmp
+*.orig
+*~
+# Various IDEs
+.project
+.idea/
+*.tmproj
+.vscode/

+ 24 - 0
deployment/helm-chart/Chart.yaml

@@ -0,0 +1,24 @@
+apiVersion: v2
+name: occ-fw-backend
+description: A Helm chart for Kubernetes
+
+# A chart can be either an 'application' or a 'library' chart.
+#
+# Application charts are a collection of templates that can be packaged into versioned archives
+# to be deployed.
+#
+# Library charts provide useful utilities or functions for the chart developer. They're included as
+# a dependency of application charts to inject those utilities and functions into the rendering
+# pipeline. Library charts do not define any templates and therefore cannot be deployed.
+type: application
+
+# This is the chart version. This version number should be incremented each time you make changes
+# to the chart and its templates, including the app version.
+# Versions are expected to follow Semantic Versioning (https://semver.org/)
+version: 0.1.0
+
+# This is the version number of the application being deployed. This version number should be
+# incremented each time you make changes to the application. Versions are not expected to
+# follow Semantic Versioning. They should reflect the version the application is using.
+# It is recommended to use it with quotes.
+appVersion: "1.16.0"

+ 21 - 0
deployment/helm-chart/templates/deployment.yaml

@@ -0,0 +1,21 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: {{ .Values.appName }}-deployment
+spec:
+  selector:
+    matchLabels:
+      app: {{ .Values.appName }}
+  replicas: 1
+  template:
+    metadata:
+      labels:
+        app: {{ .Values.appName }}
+    spec:
+      containers:
+        - name: {{ .Values.appName }}
+          image: {{ .Values.imageRegistry }}/{{ .Values.appName }}:{{ .Values.appVersion }}
+          ports:
+          - containerPort: 3000
+      imagePullSecrets:
+        - name: {{ .Values.imagePullSecret }}

+ 7 - 7
deployment/ingress.yaml → deployment/helm-chart/templates/ingress.yaml

@@ -1,30 +1,30 @@
 ---
 ---
 # Middleware
 # Middleware
-# Strip prefix /overview
 apiVersion: traefik.containo.us/v1alpha1
 apiVersion: traefik.containo.us/v1alpha1
 kind: Middleware
 kind: Middleware
 metadata:
 metadata:
-  name: occ-fw-backend-path-strip-mw
+  name: {{ .Values.appName }}-middleware-strip
 spec:
 spec:
   stripPrefix:
   stripPrefix:
     forceSlash: false
     forceSlash: false
     prefixes:
     prefixes:
-      - /occ/api
+      - {{ .Values.pathPrefix }}
 ---
 ---
 # IngressRoute
 # IngressRoute
 apiVersion: traefik.containo.us/v1alpha1
 apiVersion: traefik.containo.us/v1alpha1
 kind: IngressRoute
 kind: IngressRoute
 metadata:
 metadata:
-  name: occ-backend-ingress-route
+  name: {{ .Values.appName }}-ingress-route
 spec:
 spec:
   entryPoints:
   entryPoints:
     - websecure
     - websecure
+  tls: {}
   routes:
   routes:
     - kind: Rule
     - kind: Rule
-      match: PathPrefix(`/occ/api/`)
+      match: Host(`{{ .Values.host }}`) && PathPrefix(`{{ .Values.pathPrefix }}`)
       middlewares:
       middlewares:
-        - name: occ-fw-backend-path-strip-mw
+        - name: {{ .Values.appName }}-middleware-strip
       services:
       services:
         - kind: Service
         - kind: Service
-          name: occ-fw-backend-service
+          name: {{ .Values.appName }}-service
           port: 80
           port: 80

+ 2 - 2
deployment/service.yaml → deployment/helm-chart/templates/service.yaml

@@ -1,10 +1,10 @@
 apiVersion: v1
 apiVersion: v1
 kind: Service
 kind: Service
 metadata:
 metadata:
-  name: occ-fw-backend-service
+  name: {{ .Values.appName }}-service
 spec:
 spec:
   selector:
   selector:
-    app: occ-fw-backend
+    app: {{ .Values.appName }}
   ports:
   ports:
     - protocol: TCP
     - protocol: TCP
       port: 80
       port: 80

+ 10 - 0
deployment/helm-chart/values.yaml

@@ -0,0 +1,10 @@
+# Default values for helm-chart.
+# This is a YAML-formatted file.
+# Declare variables to be passed into your templates.
+
+appName: "occ-fw-backend"
+appVersion: 1.0.0
+imageRegistry: "iad.ocir.io/cesdev"
+imagePullSecret: ocirsecret
+host: "customercentral-poc.oracle.com"
+pathPrefix: "/occ/api/"

+ 7 - 0
deployment/scripts/ocir-login.sh

@@ -0,0 +1,7 @@
+#!/bin/sh
+
+readarray -d / -t registry <<< $1
+
+oci --profile DEFAULT raw-request --http-method GET --target-uri https://$registry/20180419/docker/token \
+| jq -r '.data.token' \
+| docker login -u BEARER_TOKEN --password-stdin iad.ocir.io

File diff ditekan karena terlalu besar
+ 181 - 265
package-lock.json


+ 7 - 2
package.json

@@ -5,10 +5,14 @@
   "author": "",
   "author": "",
   "private": true,
   "private": true,
   "license": "UNLICENSED",
   "license": "UNLICENSED",
+  "config": {
+    "host": "customercentral-poc.oracle.com",
+    "registry": "iad.ocir.io/cesdev"
+  },
   "scripts": {
   "scripts": {
     "prebuild": "rimraf dist",
     "prebuild": "rimraf dist",
     "build": "nest build",
     "build": "nest build",
-    "build:container": "docker build -t $npm_package_name:$npm_package_version .",
+    "build:container": "docker build -t $npm_package_config_registry/$npm_package_name:$npm_package_version .",
     "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
     "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
     "start": "nest start",
     "start": "nest start",
     "start:container": "npm run build:container && docker run --rm -d -p 3000:3000 $npm_package_name:$npm_package_version",
     "start:container": "npm run build:container && docker run --rm -d -p 3000:3000 $npm_package_name:$npm_package_version",
@@ -21,7 +25,8 @@
     "test:cov": "jest --coverage",
     "test:cov": "jest --coverage",
     "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
     "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
     "test:e2e": "jest --config ./test/jest-e2e.json",
     "test:e2e": "jest --config ./test/jest-e2e.json",
-    "deploy": "npm run build:container && kubectl apply -f deployment"
+    "deploy": "npm run build:container && helm upgrade --install $npm_package_name --set appName=$npm_package_name --set appVersion=$npm_package_version --set host=$npm_package_config_host --set imageRegistry=$npm_package_config_registry ./deployment/helm-chart",
+    "deploy:container": "npm run build:container && ./deployment/scripts/ocir-login.sh $npm_package_config_registry && docker push $npm_package_config_registry/$npm_package_name:$npm_package_version"
   },
   },
   "dependencies": {
   "dependencies": {
     "@nestjs/axios": "^0.1.0",
     "@nestjs/axios": "^0.1.0",

Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini