From 2091723b402f2935d454f7aaf0f5f63ba468569e Mon Sep 17 00:00:00 2001 From: DutchEllie Date: Fri, 1 Jul 2022 15:00:51 +0200 Subject: [PATCH] Add pipeline --- .dockerignore | 2 + .drone.yml | 52 +++++++++++++++++++++ .drone/helm/chart/Chart.yaml | 3 ++ .drone/helm/chart/templates/deployment.yaml | 39 ++++++++++++++++ .drone/helm/chart/templates/ingress.yaml | 36 ++++++++++++++ .drone/helm/chart/templates/service.yaml | 18 +++++++ .drone/helm/chart/values.yaml | 29 ++++++++++++ .drone/helm/prod-val.yaml | 21 +++++++++ .drone/helm/staging-val.yaml | 22 +++++++++ .drone/helm/values.yaml | 0 Dockerfile | 18 +++++++ package-lock.json | 19 ++++++++ package.json | 1 + svelte.config.js | 2 +- 14 files changed, 261 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 .drone.yml create mode 100644 .drone/helm/chart/Chart.yaml create mode 100644 .drone/helm/chart/templates/deployment.yaml create mode 100644 .drone/helm/chart/templates/ingress.yaml create mode 100644 .drone/helm/chart/templates/service.yaml create mode 100644 .drone/helm/chart/values.yaml create mode 100644 .drone/helm/prod-val.yaml create mode 100644 .drone/helm/staging-val.yaml create mode 100644 .drone/helm/values.yaml create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..5171c54 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +node_modules +npm-debug.log \ No newline at end of file diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..ef7706d --- /dev/null +++ b/.drone.yml @@ -0,0 +1,52 @@ +kind: pipeline +type: kubernetes +name: deploy + +trigger: + event: + - push + +steps: +- name: build-publish-image + image: plugins/docker + privileged: true + volumes: + - name: build + path: /drone/src/build + settings: + username: + from_secret: org_docker_username + password: + from_secret: org_docker_password + dockerfile: Dockerfile + repo: dutchellie/${DRONE_REPO_NAME} + tags: + - ${DRONE_BRANCH}-${DRONE_COMMIT_SHA:0:8} +- name: deploy + image: pelotech/drone-helm3 + settings: + mode: upgrade + chart: .drone/helm/chart + namespace: drone-staging + release: ${DRONE_REPO_NAME}-${DRONE_BRANCH} + skip_tls_verify: true + values_files: + - .drone/helm/staging-val.yaml + values: + - "image=dutchellie/${DRONE_REPO_NAME}:${DRONE_BRANCH}-${DRONE_COMMIT_SHA:0:8}" + - "baseURL=${DRONE_BRANCH}.${DRONE_REPO_NAME}.ci.dutchellie.nl" + - "name={DRONE_REPO_NAME}-${DRONE_BRANCH}" + kube_api_server: + from_secret: org_api_server + kube_token: + from_secret: org_kube_token + kube_certificate: + from_secret: org_kube_certificate + kube_service_account: drone-deploy + dry_run: false + depends_on: + - build-publish-image + +volumes: + - name: build + temp: {} \ No newline at end of file diff --git a/.drone/helm/chart/Chart.yaml b/.drone/helm/chart/Chart.yaml new file mode 100644 index 0000000..edd8035 --- /dev/null +++ b/.drone/helm/chart/Chart.yaml @@ -0,0 +1,3 @@ +apiVersion: v2 +name: newsite +version: v0.0.3 \ No newline at end of file diff --git a/.drone/helm/chart/templates/deployment.yaml b/.drone/helm/chart/templates/deployment.yaml new file mode 100644 index 0000000..0b952de --- /dev/null +++ b/.drone/helm/chart/templates/deployment.yaml @@ -0,0 +1,39 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ .Values.name }} + namespace: {{ .Release.Namespace }} + {{- if .Values.annotations }} + annotations: {{ toYaml .Values.annotations | nindent 4}} + {{- end}} +spec: + selector: + matchLabels: + app: {{ .Values.name }} + release: {{ .Values.release }} + replicas: {{ .Values.replicas }} + template: + metadata: + {{- if .Values.podAnnotations }} + annotations: + {{- range $key, $value := .Values.controller.podAnnotations }} + {{ $key }}: {{ $value | quote }} + {{- end }} + {{- end }} + labels: + app: {{ .Values.name }} + release: {{ .Values.release }} + spec: + containers: + - name: {{ .Values.containerName }} + image: {{ .Values.image }} + imagePullPolicy: {{ .Values.imagePullPolicy }} + ports: + - name: http + containerPort: {{ .Values.service.port }} + {{- if .Values.containerEnv }} + env: {{ toYaml .Values.containerEnv | nindent 12 }} + {{- end }} + + + \ No newline at end of file diff --git a/.drone/helm/chart/templates/ingress.yaml b/.drone/helm/chart/templates/ingress.yaml new file mode 100644 index 0000000..286943d --- /dev/null +++ b/.drone/helm/chart/templates/ingress.yaml @@ -0,0 +1,36 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ tpl .Values.ingress.name . }} + namespace: {{ .Release.Namespace }} + {{- with .Values.ingress.annotations }} + annotations: + {{- tpl (. | toYaml) $ | nindent 4 }} + {{- end }} +spec: + ingressClassName: {{ .Values.ingress.className }} +{{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ tpl . $ | quote }} + {{- end }} + secretName: {{ tpl (.secretName | toYaml) $ }} + {{- end }} +{{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ tpl .host $ | quote }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + pathType: {{ .pathType }} + backend: + service: + name: {{ tpl $.Values.service.name $ }} + port: + number: {{ .Values.service.port }} + {{- end }} + {{- end }} \ No newline at end of file diff --git a/.drone/helm/chart/templates/service.yaml b/.drone/helm/chart/templates/service.yaml new file mode 100644 index 0000000..e47f677 --- /dev/null +++ b/.drone/helm/chart/templates/service.yaml @@ -0,0 +1,18 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ tpl .Values.service.name . }} + namespace: {{ .Release.Namespace }} + {{- with .Values.service.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + selector: + app: {{ .Values.name }} + release: {{ .Values.release }} + ports: + - protocol: TCP + name: http + port: {{ .Values.service.port }} + targetPort: {{ .Values.service.port }} \ No newline at end of file diff --git a/.drone/helm/chart/values.yaml b/.drone/helm/chart/values.yaml new file mode 100644 index 0000000..095e1ff --- /dev/null +++ b/.drone/helm/chart/values.yaml @@ -0,0 +1,29 @@ +name: nginx-changeme-deployment +annotations: {} +release: latest +replicas: 1 +podAnnotations: {} +containerName: nginx +image: nginx:latest +imagePullPolicy: Always +containerEnv: [] + +service: + name: changeme-service + annotations: {} + port: 3000 + +ingress: + name: changeme-ingress + annotations: {} + className: nginx + tls: [] + # tls: + # - hosts: + # - example.com + # secretName: example-tls + hosts: + - host: example.com + paths: + - path: / + pathType: Prefix \ No newline at end of file diff --git a/.drone/helm/prod-val.yaml b/.drone/helm/prod-val.yaml new file mode 100644 index 0000000..e908097 --- /dev/null +++ b/.drone/helm/prod-val.yaml @@ -0,0 +1,21 @@ +baseURL: changeme.dutchellie.nl +name: changeme-prod +containerEnv: +# - name: APIURL +# value: https://api.quenten.nl/api +service: + name: "{{ .Values.name }}" +ingress: + name: "{{ .Values.name }}" + annotations: + cert-manager.io/cluster-issuer: "letsencrypt-prod" + external-dns.alpha.kubernetes.io/hostname: "{{ .Values.baseURL }}" + tls: + - hosts: + - "{{ .Values.baseURL }}" + secretName: "{{ .Values.name }}-tls" + hosts: + - host: "{{ .Values.baseURL }}" + paths: + - path: / + pathType: Prefix \ No newline at end of file diff --git a/.drone/helm/staging-val.yaml b/.drone/helm/staging-val.yaml new file mode 100644 index 0000000..a504e63 --- /dev/null +++ b/.drone/helm/staging-val.yaml @@ -0,0 +1,22 @@ +baseURL: changemestaging.dutchellie.nl +name: changeme-staging +containerEnv: +# - name: APIURL +# value: https://api.quenten.nl/api/testing +service: + name: "{{ .Values.name }}" + port: 3000 +ingress: + name: "{{ .Values.name }}" + annotations: + cert-manager.io/cluster-issuer: "letsencrypt-staging" + external-dns.alpha.kubernetes.io/hostname: "{{ .Values.baseURL }}" + tls: + - hosts: + - "{{ .Values.baseURL }}" + secretName: "{{ .Values.name }}-tls" + hosts: + - host: "{{ .Values.baseURL }}" + paths: + - path: / + pathType: Prefix \ No newline at end of file diff --git a/.drone/helm/values.yaml b/.drone/helm/values.yaml new file mode 100644 index 0000000..e69de29 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8bdea7b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM node:18.2.0-alpine + +WORKDIR /app +COPY . . +RUN npm ci +RUN npm audit fix +RUN npm run build + +FROM node:18.2.0-alpine + +WORKDIR /app +COPY --from=0 /app/package*.json ./ +RUN npm ci --production --ignore-scripts +RUN npm audit fix +COPY --from=0 /app/build ./ + +EXPOSE 3000 +CMD ["node", "./index.js"] \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 3f49572..ce370e2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "0.0.1", "devDependencies": { "@sveltejs/adapter-auto": "next", + "@sveltejs/adapter-node": "^1.0.0-next.78", "@sveltejs/kit": "next", "@typescript-eslint/eslint-plugin": "^5.27.0", "@typescript-eslint/parser": "^5.27.0", @@ -196,6 +197,15 @@ "tiny-glob": "^0.2.9" } }, + "node_modules/@sveltejs/adapter-node": { + "version": "1.0.0-next.78", + "resolved": "https://registry.npmjs.org/@sveltejs/adapter-node/-/adapter-node-1.0.0-next.78.tgz", + "integrity": "sha512-TXB5Ii0z/7o1B05p/YLsS4t+JUHFHWBzFv1U16TKvM3HMbMUJIx+AhpM2WJfDX8HtAyfd1m9OawGoUB+1ed24A==", + "dev": true, + "dependencies": { + "tiny-glob": "^0.2.9" + } + }, "node_modules/@sveltejs/adapter-vercel": { "version": "1.0.0-next.59", "resolved": "https://registry.npmjs.org/@sveltejs/adapter-vercel/-/adapter-vercel-1.0.0-next.59.tgz", @@ -3276,6 +3286,15 @@ "tiny-glob": "^0.2.9" } }, + "@sveltejs/adapter-node": { + "version": "1.0.0-next.78", + "resolved": "https://registry.npmjs.org/@sveltejs/adapter-node/-/adapter-node-1.0.0-next.78.tgz", + "integrity": "sha512-TXB5Ii0z/7o1B05p/YLsS4t+JUHFHWBzFv1U16TKvM3HMbMUJIx+AhpM2WJfDX8HtAyfd1m9OawGoUB+1ed24A==", + "dev": true, + "requires": { + "tiny-glob": "^0.2.9" + } + }, "@sveltejs/adapter-vercel": { "version": "1.0.0-next.59", "resolved": "https://registry.npmjs.org/@sveltejs/adapter-vercel/-/adapter-vercel-1.0.0-next.59.tgz", diff --git a/package.json b/package.json index 172850b..1a0c7cb 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ }, "devDependencies": { "@sveltejs/adapter-auto": "next", + "@sveltejs/adapter-node": "^1.0.0-next.78", "@sveltejs/kit": "next", "@typescript-eslint/eslint-plugin": "^5.27.0", "@typescript-eslint/parser": "^5.27.0", diff --git a/svelte.config.js b/svelte.config.js index 892f0c4..ce4ff82 100644 --- a/svelte.config.js +++ b/svelte.config.js @@ -1,4 +1,4 @@ -import adapter from '@sveltejs/adapter-auto'; +import adapter from '@sveltejs/adapter-node'; import preprocess from 'svelte-preprocess'; /** @type {import('@sveltejs/kit').Config} */