-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add kubernetes deployment to Express generator
- Loading branch information
Showing
22 changed files
with
363 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
version: '2.1' | ||
|
||
orbs: | ||
<% if (deployment === 'kubernetes') { %> | ||
docker: circleci/docker@2.0.1 | ||
<% } %> | ||
node: circleci/[email protected] | ||
|
||
executors: | ||
|
@@ -44,6 +47,7 @@ jobs: | |
- run: | ||
command: yarn test | ||
|
||
<% if (deployment === 'ansible') { %> | ||
<%= packageName %>-build: | ||
executor: node | ||
working_directory: ~/project/<%= packagePath %> | ||
|
@@ -97,6 +101,38 @@ jobs: | |
- run: sentry-cli releases new <%= projectName %>-<%= packageName %>@${CIRCLE_SHA1} | ||
- run: sentry-cli releases files <%= projectName %>-<%= packageName %>@${CIRCLE_SHA1} upload-sourcemaps <%= packagePath %>/dist | ||
- run: sentry-cli releases finalize <%= projectName %>-<%= packageName %>@${CIRCLE_SHA1} | ||
<% } %> | ||
<% if (deployment === 'kubernetes') { %> | ||
<%= packageName %>-build: | ||
executor: docker/docker | ||
steps: | ||
- setup_remote_docker | ||
- checkout | ||
- docker/build: | ||
image: <%= projectName %>-<%= packageName %> | ||
tag: << pipeline.git.branch >> | ||
path: <%= packagePath %> | ||
docker-context: <%= packagePath %> | ||
extra_build_args: '--build-arg VERSION=$(git log --max-count 1 --pretty=format:%H "<%= packagePath %>")' | ||
<%= packageName %>-build-and-push: | ||
executor: docker/docker | ||
steps: | ||
- setup_remote_docker | ||
- checkout | ||
- docker/build: | ||
registry: $DOCKER_REGISTRY | ||
image: <%= projectName %>-<%= packageName %> | ||
tag: << pipeline.git.branch >> | ||
path: <%= packagePath %> | ||
docker-context: <%= packagePath %> | ||
extra_build_args: '--build-arg VERSION=$(git log --max-count 1 --pretty=format:%H "<%= packagePath %>")' | ||
- docker/check: | ||
registry: $DOCKER_REGISTRY | ||
- docker/push: | ||
registry: $DOCKER_REGISTRY | ||
image: <%= projectName %>-<%= packageName %> | ||
tag: << pipeline.git.branch >> | ||
<% } %> | ||
|
||
workflows: | ||
version: '2' | ||
|
@@ -109,6 +145,7 @@ workflows: | |
- <%= packageName %>-test: | ||
requires: | ||
- <%= packageName %>-lint | ||
<% if (deployment === 'ansible') { %> | ||
- <%= packageName %>-build: | ||
requires: | ||
- <%= packageName %>-test | ||
|
@@ -124,3 +161,24 @@ workflows: | |
only: | ||
- develop | ||
- main | ||
<% } %> | ||
<% if (deployment === 'kubernetes') { %> | ||
- <%= packageName %>-build-and-push: | ||
context: | ||
- docker-registry | ||
requires: | ||
- <%= packageName %>-test | ||
filters: | ||
branches: | ||
only: | ||
- develop | ||
- main | ||
- <%= packageName %>-build: | ||
requires: | ||
- <%= packageName %>-test | ||
filters: | ||
branches: | ||
ignore: | ||
- develop | ||
- main | ||
<% } %> |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions
8
generators/express/templates/deployment/kubernetes/chart/_helpers.tpl.ejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{{- define "<%= projectName %>.<%= packageName %>.image" }} | ||
{{- .Values.registry }}/<%= projectName %>-<%= packageName %> | ||
{{- if .Values.<%= varify(packageName) %>.image.digest -}} | ||
@{{ .Values.<%= varify(packageName) %>.image.digest }} | ||
{{- else -}} | ||
:{{ .Values.<%= varify(packageName) %>.image.tag }} | ||
{{- end -}} | ||
{{- end }} |
10 changes: 10 additions & 0 deletions
10
generators/express/templates/deployment/kubernetes/chart/database-secret.yaml.ejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: {{ include "<%= projectName %>.fullname" . }}-<%= packageName %>-database | ||
labels: | ||
app.kubernetes.io/component: <%= packageName %> | ||
{{- include "<%= projectName %>.labels" . | nindent 4 }} | ||
type: Opaque | ||
data: | ||
url: {{ (print "postgresql://" .Values.<%= varify(packageName) %>.database.user ":" (.Values.<%= varify(packageName) %>.database.password | urlquery) "@" .Values.<%= varify(packageName) %>.database.host ":" .Values.<%= varify(packageName) %>.database.port "/" .Values.<%= varify(packageName) %>.database.name) | b64enc }} |
48 changes: 48 additions & 0 deletions
48
generators/express/templates/deployment/kubernetes/chart/deployment.yaml.ejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: {{ include "<%= projectName %>.fullname" . }}-<%= packageName %> | ||
labels: | ||
app.kubernetes.io/component: <%= packageName %> | ||
{{- include "<%= projectName %>.labels" . | nindent 4 }} | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app.kubernetes.io/component: <%= packageName %> | ||
{{- include "<%= projectName %>.selectorLabels" . | nindent 6 }} | ||
template: | ||
metadata: | ||
annotations: | ||
checksum/database-secret: {{ include (print $.Template.BasePath "/<%= packageName %>-database-secret.yaml") . | sha256sum }} | ||
labels: | ||
app.kubernetes.io/component: <%= packageName %> | ||
{{- include "<%= projectName %>.selectorLabels" . | nindent 8 }} | ||
spec: | ||
containers: | ||
- name: node | ||
image: {{ include "<%= projectName %>.<%= packageName %>.image" . }} | ||
env: | ||
- name: DATABASE_URL | ||
valueFrom: | ||
secretKeyRef: | ||
name: {{ include "<%= projectName %>.fullname" . }}-<%= packageName %>-database | ||
key: url | ||
- name: ENVIRONMENT_NAME | ||
value: {{ .Values.environment_name }} | ||
- name: SENTRY_DSN | ||
value: {{ .Values.<%= varify(packageName) %>.sentry.dsn }} | ||
ports: | ||
- name: http | ||
containerPort: 3000 | ||
protocol: TCP | ||
livenessProbe: | ||
httpGet: | ||
path: / | ||
port: http | ||
readinessProbe: | ||
httpGet: | ||
path: / | ||
port: http | ||
imagePullSecrets: | ||
- name: registry-secret |
28 changes: 28 additions & 0 deletions
28
generators/express/templates/deployment/kubernetes/chart/ingress.yaml.ejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
apiVersion: networking.k8s.io/v1 | ||
kind: Ingress | ||
metadata: | ||
name: {{ include "<%= projectName %>.fullname" . }}-<%= packageName %> | ||
labels: | ||
app.kubernetes.io/component: <%= packageName %> | ||
{{- include "<%= projectName %>.labels" . | nindent 4 }} | ||
{{- if .Values.basic_auth_password }} | ||
nginx.ingress.kubernetes.io/auth-type: basic | ||
nginx.ingress.kubernetes.io/auth-secret: {{ include "<%= projectName %>.fullname" . }}-basic-auth | ||
nginx.ingress.kubernetes.io/auth-realm: 'Authentication Required' | ||
{{- end }} | ||
spec: | ||
rules: | ||
- host: {{ .Values.host }} | ||
http: | ||
paths: | ||
- path: <%= httpPath %> | ||
pathType: Prefix | ||
backend: | ||
service: | ||
name: {{ include "<%= projectName %>.fullname" . }}-<%= packageName %> | ||
port: | ||
number: 80 | ||
tls: | ||
- hosts: | ||
- {{ .Values.host }} | ||
secretName: {{ .Values.certificate | default (print (include "<%= projectName %>.fullname" .) "-cert") }} |
35 changes: 35 additions & 0 deletions
35
generators/express/templates/deployment/kubernetes/chart/migrate-job.yaml.ejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
apiVersion: batch/v1 | ||
kind: Job | ||
metadata: | ||
name: {{ include "<%= projectName %>.fullname" . }}-<%= packageName %>-migrate | ||
labels: | ||
app.kubernetes.io/component: <%= packageName %> | ||
{{- include "<%= projectName %>.labels" . | nindent 4 }} | ||
annotations: | ||
helm.sh/hook: pre-install,pre-upgrade | ||
helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded | ||
spec: | ||
template: | ||
metadata: | ||
annotations: | ||
checksum/database-secret: {{ include (print $.Template.BasePath "/<%= packageName %>-database-secret.yaml") . | sha256sum }} | ||
spec: | ||
containers: | ||
- name: node | ||
image: {{ include "<%= projectName %>.<%= packageName %>.image" . }} | ||
command: | ||
- typeorm | ||
- migration:run | ||
env: | ||
- name: DATABASE_URL | ||
valueFrom: | ||
secretKeyRef: | ||
name: {{ include "<%= projectName %>.fullname" . }}-<%= packageName %>-database | ||
key: url | ||
- name: ENVIRONMENT_NAME | ||
value: {{ .Values.environment_name }} | ||
- name: SENTRY_DSN | ||
value: {{ .Values.<%= varify(packageName) %>.sentry.dsn }} | ||
restartPolicy: Never | ||
imagePullSecrets: | ||
- name: registry-secret |
16 changes: 16 additions & 0 deletions
16
generators/express/templates/deployment/kubernetes/chart/service.yaml.ejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: {{ include "<%= projectName %>.fullname" . }}-<%= packageName %> | ||
labels: | ||
app.kubernetes.io/component: <%= packageName %> | ||
{{- include "<%= projectName %>.labels" . | nindent 4 }} | ||
spec: | ||
selector: | ||
app.kubernetes.io/component: <%= packageName %> | ||
{{- include "<%= projectName %>.selectorLabels" . | nindent 4 }} | ||
ports: | ||
- protocol: TCP | ||
port: 80 | ||
targetPort: 3000 | ||
name: http |
2 changes: 2 additions & 0 deletions
2
generators/express/templates/deployment/kubernetes/docker/.dockerignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/dist/ | ||
/node_modules/ |
44 changes: 44 additions & 0 deletions
44
generators/express/templates/deployment/kubernetes/docker/Dockerfile.ejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Base image for all steps | ||
FROM node:16.13.1-slim as base | ||
|
||
WORKDIR /srv/<%= packageName %>/ | ||
|
||
# Dev dependencies | ||
FROM base as devDependencies | ||
|
||
COPY package.json . | ||
COPY yarn.lock . | ||
|
||
RUN yarn install --frozen-lockfile | ||
|
||
# Prod dependencies | ||
FROM devDependencies as dependencies | ||
|
||
RUN yarn install --frozen-lockfile --production | ||
|
||
# Build | ||
FROM devDependencies as build | ||
|
||
COPY tsconfig.json . | ||
COPY src ./src | ||
|
||
ARG VERSION | ||
RUN echo "export default '$VERSION';" > src/version.ts | ||
|
||
RUN yarn build | ||
|
||
# Final image | ||
FROM base | ||
|
||
COPY ormconfig-dist.js ./ormconfig.js | ||
COPY --from=dependencies /srv/<%= packageName %>/node_modules /srv/<%= packageName %>/node_modules | ||
COPY --from=build /srv/<%= packageName %>/dist /srv/<%= packageName %>/dist | ||
|
||
USER node | ||
|
||
ENV NODE_ENV="production" | ||
ENV PATH="/srv/<%= packageName %>/node_modules/.bin:${PATH}" | ||
|
||
EXPOSE 3000 | ||
|
||
CMD ["node", "dist"] |
Oops, something went wrong.