From b3fb88303f9bcfe85626ea11be3ec642bd245d12 Mon Sep 17 00:00:00 2001 From: Max T Date: Thu, 13 Apr 2023 12:53:05 +0200 Subject: [PATCH 01/14] Add todo planning --- todos.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 todos.md diff --git a/todos.md b/todos.md new file mode 100644 index 0000000..3236c5d --- /dev/null +++ b/todos.md @@ -0,0 +1,22 @@ +todos + +frontend: +- build: + - openapi anders? + buildpacks? + direkt docker? + über maven? +deploy + nginx prod vs dev container? + - postgres: wir stellen code für dev bereit, den leute optional für prod hernehmen könnten, wir rechnen aber nicht damit + +setup + - minikube durch kind/k3s ersetzen? (Install-Größe und Performanz) + +skaffold-zeug: + - FileSync, damit nicht immer neu gebaut werden muss + + backend: +- liquibase in initcontainer +- https://redhat-scholars.github.io/spring-boot-k8s-tutorial/spring-boot-tutorial/03-kubernetes.html + From ef7c7343a5dc1aee7bc0e72677e41de56fd331c9 Mon Sep 17 00:00:00 2001 From: Max T Date: Thu, 13 Apr 2023 12:58:28 +0200 Subject: [PATCH 02/14] Add k9s to dependencies Makes it easier to debug local, small package --- flake.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 46af63f..de14860 100644 --- a/flake.nix +++ b/flake.nix @@ -25,10 +25,11 @@ pkgs.nodejs-18_x pkgs.buildpack pkgs.kubernetes-helm + pkgs.k9s ]; }; overlays.default = (final: prev: { skaffold = pkgs-unstable.skaffold; }); }); -} \ No newline at end of file +} From 57db1f7bd8462e08ad6198e79682a3a6b80dae4a Mon Sep 17 00:00:00 2001 From: Max T Date: Thu, 13 Apr 2023 12:59:44 +0200 Subject: [PATCH 03/14] WIP frontend deployment --- packages/frontend/Dockerfile | 19 +++ packages/frontend/package-lock.json | 96 +++++++++++--- packages/frontend/pom.xml | 196 +++++++++++++++------------- pom.xml | 4 +- skaffold.yaml | 6 + 5 files changed, 207 insertions(+), 114 deletions(-) create mode 100644 packages/frontend/Dockerfile diff --git a/packages/frontend/Dockerfile b/packages/frontend/Dockerfile new file mode 100644 index 0000000..c45da17 --- /dev/null +++ b/packages/frontend/Dockerfile @@ -0,0 +1,19 @@ +FROM openapitools/openapi-generator-cli:6.4.0 AS openapitools + +RUN mkdir -p /app/generated-sources/client +WORKDIR /app/generated-sources/client +# https://openapi-generator.tech/docs/installation#docker + +FROM node:alpine3.17 AS builder + +RUN mkdir -p /app +WORKDIR /app + +COPY frontend/package*.json ./ + +RUN npm install +RUN npm run build + +FROM nginx:latest as webserver + +COPY /build /var/html/ \ No newline at end of file diff --git a/packages/frontend/package-lock.json b/packages/frontend/package-lock.json index 0e8e7f3..783af2f 100644 --- a/packages/frontend/package-lock.json +++ b/packages/frontend/package-lock.json @@ -61,7 +61,24 @@ "typescript": "^4.0" } }, - "generated-sources/client": {}, + "generated-sources/client": { + "name": "rest-client", + "version": "8.19.3", + "license": "Unlicense", + "dependencies": { + "axios": "^0.27.2" + }, + "devDependencies": { + "@types/node": "^12.11.5", + "typescript": "^4.0" + } + }, + "generated-sources/client/node_modules/@types/node": { + "version": "12.20.55", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.20.55.tgz", + "integrity": "sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ==", + "dev": true + }, "node_modules/@babel/parser": { "version": "7.21.3", "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.21.3.tgz", @@ -1407,8 +1424,7 @@ "node_modules/asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", - "dev": true + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" }, "node_modules/autoprefixer": { "version": "10.4.14", @@ -1455,6 +1471,15 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/axios": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.27.2.tgz", + "integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==", + "dependencies": { + "follow-redirects": "^1.14.9", + "form-data": "^4.0.0" + } + }, "node_modules/babel-runtime": { "version": "6.26.0", "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz", @@ -1705,7 +1730,6 @@ "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "dev": true, "dependencies": { "delayed-stream": "~1.0.0" }, @@ -1885,7 +1909,6 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", - "dev": true, "engines": { "node": ">=0.4.0" } @@ -2636,6 +2659,25 @@ "integrity": "sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ==", "dev": true }, + "node_modules/follow-redirects": { + "version": "1.15.2", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", + "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, "node_modules/for-each": { "version": "0.3.3", "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz", @@ -2649,7 +2691,6 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", - "dev": true, "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", @@ -3633,7 +3674,6 @@ "version": "1.52.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", - "dev": true, "engines": { "node": ">= 0.6" } @@ -3642,7 +3682,6 @@ "version": "2.1.35", "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", - "dev": true, "dependencies": { "mime-db": "1.52.0" }, @@ -6786,8 +6825,7 @@ "asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", - "dev": true + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" }, "autoprefixer": { "version": "10.4.14", @@ -6809,6 +6847,15 @@ "integrity": "sha512-DMD0KiN46eipeziST1LPP/STfDU0sufISXmjSgvVsoU2tqxctQeASejWcfNtxYKqETM1UxQ8sp2OrSBWpHY6sw==", "dev": true }, + "axios": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.27.2.tgz", + "integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==", + "requires": { + "follow-redirects": "^1.14.9", + "form-data": "^4.0.0" + } + }, "babel-runtime": { "version": "6.26.0", "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz", @@ -6982,7 +7029,6 @@ "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "dev": true, "requires": { "delayed-stream": "~1.0.0" } @@ -7114,8 +7160,7 @@ "delayed-stream": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", - "dev": true + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==" }, "detective": { "version": "5.2.1", @@ -7684,6 +7729,11 @@ "integrity": "sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ==", "dev": true }, + "follow-redirects": { + "version": "1.15.2", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", + "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==" + }, "for-each": { "version": "0.3.3", "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz", @@ -7697,7 +7747,6 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", - "dev": true, "requires": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", @@ -8405,14 +8454,12 @@ "mime-db": { "version": "1.52.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", - "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", - "dev": true + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==" }, "mime-types": { "version": "2.1.35", "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", - "dev": true, "requires": { "mime-db": "1.52.0" } @@ -9087,7 +9134,20 @@ "dev": true }, "rest-client": { - "version": "file:generated-sources/client" + "version": "file:generated-sources/client", + "requires": { + "@types/node": "^12.11.5", + "axios": "^0.27.2", + "typescript": "^4.0" + }, + "dependencies": { + "@types/node": { + "version": "12.20.55", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.20.55.tgz", + "integrity": "sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ==", + "dev": true + } + } }, "reusify": { "version": "1.0.4", diff --git a/packages/frontend/pom.xml b/packages/frontend/pom.xml index ec90334..268a915 100644 --- a/packages/frontend/pom.xml +++ b/packages/frontend/pom.xml @@ -1,101 +1,109 @@ - 4.0.0 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - de.mayflower - frontend - 0.0.1 + de.mayflower + frontend + 0.0.1 - frontend - Frontend for oTTo + frontend + Frontend for oTTo - - - 6.4.0 - + + + 6.4.0 + + + otto/frontend + - - - - - - org.openapitools - openapi-generator-maven-plugin - ${plugins.openapi-generator.version} - - - - generate - - validate - - ${project.basedir}/../api-spec/openapi.yml - typescript-axios - - rest-client - true - 8.19.3 - true - - ${project.basedir}/generated-sources/client - - - - - - com.github.eirslett - frontend-maven-plugin - - 1.12.1 - - - - install node and npm - - install-node-and-npm - - - generate-resources - - - Build OpenAPI code - - npm - + + + + + + org.openapitools + openapi-generator-maven-plugin + ${plugins.openapi-generator.version} + + + + generate + + validate + + ${project.basedir}/../api-spec/openapi.yml + typescript-axios + + rest-client + true + 8.19.3 + true + + ${project.basedir}/generated-sources/client + + + + + + com.github.eirslett + frontend-maven-plugin + 1.12.1 + + + install node and npm + + install-node-and-npm + + + + Build OpenAPI code + + npm + + + ${project.basedir}/generated-sources/client + ${project.basedir} + + + + install dependencies + + npm + + + + build prod server + + npm + + + run build + + + + + v18.14.2 + + + + - - generate-resources - - - - install - ${project.basedir}/generated-sources/client - ${project.basedir} - - - - - - v18.14.2 - - - - - - - - org.openapitools - openapi-generator-maven-plugin - - - com.github.eirslett - frontend-maven-plugin - - - - + + + org.openapitools + openapi-generator-maven-plugin + + + com.github.eirslett + frontend-maven-plugin + + + com.google.cloud.tools + jib-maven-plugin + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 21f6895..dd4e58e 100644 --- a/pom.xml +++ b/pom.xml @@ -1,6 +1,6 @@ - + 4.0.0 de.mayflower diff --git a/skaffold.yaml b/skaffold.yaml index bd9b313..a07e541 100644 --- a/skaffold.yaml +++ b/skaffold.yaml @@ -9,6 +9,11 @@ build: jib: project: packages/backend type: maven + - image: frontend + context: . + docker: + dockerfile: packages/frontend + deploy: helm: releases: @@ -26,6 +31,7 @@ deploy: repo: 'https://charts.bitnami.com/bitnami' valuesFiles: - "helm/dev-db-config.yaml" + version: 15.2.0 portForward: - resourceType: Service resourceName: backend-otto From 91cb9a9ff189f18aac08f99d6fd38c09b7bfda6f Mon Sep 17 00:00:00 2001 From: Max T Date: Thu, 13 Apr 2023 13:00:28 +0200 Subject: [PATCH 04/14] Add frontend/target to gitignore --- packages/frontend/.gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/frontend/.gitignore b/packages/frontend/.gitignore index 613fecb..b3c58be 100644 --- a/packages/frontend/.gitignore +++ b/packages/frontend/.gitignore @@ -31,3 +31,5 @@ coverage test-results/ playwright-report/ + +target \ No newline at end of file From 23419ca718f5b8f5b922930a7a4811cc5f879709 Mon Sep 17 00:00:00 2001 From: Konstantin Sabass Date: Thu, 13 Apr 2023 17:00:04 +0200 Subject: [PATCH 05/14] add dockerfile for frontend --- packages/frontend/.dockerignore | 3 +++ packages/frontend/Dockerfile | 25 ++++++++++++++---- packages/frontend/package-lock.json | 40 ++++++----------------------- skaffold.yaml | 2 +- 4 files changed, 32 insertions(+), 38 deletions(-) create mode 100644 packages/frontend/.dockerignore diff --git a/packages/frontend/.dockerignore b/packages/frontend/.dockerignore new file mode 100644 index 0000000..954c1db --- /dev/null +++ b/packages/frontend/.dockerignore @@ -0,0 +1,3 @@ +node_modules +generated-sources +dist diff --git a/packages/frontend/Dockerfile b/packages/frontend/Dockerfile index c45da17..fae972e 100644 --- a/packages/frontend/Dockerfile +++ b/packages/frontend/Dockerfile @@ -1,19 +1,34 @@ -FROM openapitools/openapi-generator-cli:6.4.0 AS openapitools +FROM openapitools/openapi-generator-cli:v6.4.0 AS openapigenerator_builder RUN mkdir -p /app/generated-sources/client +COPY packages/api-spec/openapi.yml /app/openapi.yml WORKDIR /app/generated-sources/client +RUN /usr/local/bin/docker-entrypoint.sh \ + generate -i /app/openapi.yml -g typescript-axios -o . \ + --additional-properties=npmName=rest-client,withInterface=true,supportsES6=true + +# https://openapi-generator.tech/docs/generators/typescript-axios/ # https://openapi-generator.tech/docs/installation#docker -FROM node:alpine3.17 AS builder +FROM node:alpine3.17 AS frontend_builder_prod RUN mkdir -p /app WORKDIR /app -COPY frontend/package*.json ./ +# copy the generated openapi-client +COPY --from=openapigenerator_builder /app/generated-sources/client /app/generated-sources/client +# install npm dependencies +COPY packages/frontend/package*.json ./ RUN npm install + +# build frontend +WORKDIR /app +COPY packages/frontend ./ RUN npm run build -FROM nginx:latest as webserver -COPY /build /var/html/ \ No newline at end of file +FROM nginx:latest as webserver_prod + +COPY --from=frontend_builder_prod /app/dist /usr/share/nginx/html +EXPOSE 80 diff --git a/packages/frontend/package-lock.json b/packages/frontend/package-lock.json index 783af2f..68f8a46 100644 --- a/packages/frontend/package-lock.json +++ b/packages/frontend/package-lock.json @@ -61,24 +61,6 @@ "typescript": "^4.0" } }, - "generated-sources/client": { - "name": "rest-client", - "version": "8.19.3", - "license": "Unlicense", - "dependencies": { - "axios": "^0.27.2" - }, - "devDependencies": { - "@types/node": "^12.11.5", - "typescript": "^4.0" - } - }, - "generated-sources/client/node_modules/@types/node": { - "version": "12.20.55", - "resolved": "https://registry.npmjs.org/@types/node/-/node-12.20.55.tgz", - "integrity": "sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ==", - "dev": true - }, "node_modules/@babel/parser": { "version": "7.21.3", "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.21.3.tgz", @@ -4663,8 +4645,12 @@ } }, "node_modules/rest-client": { - "resolved": "generated-sources/client", - "link": true + "version": "8.19.3", + "resolved": "file:generated-sources/client", + "license": "Unlicense", + "dependencies": { + "axios": "^0.27.2" + } }, "node_modules/reusify": { "version": "1.0.4", @@ -9134,19 +9120,9 @@ "dev": true }, "rest-client": { - "version": "file:generated-sources/client", + "version": "8.19.3", "requires": { - "@types/node": "^12.11.5", - "axios": "^0.27.2", - "typescript": "^4.0" - }, - "dependencies": { - "@types/node": { - "version": "12.20.55", - "resolved": "https://registry.npmjs.org/@types/node/-/node-12.20.55.tgz", - "integrity": "sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ==", - "dev": true - } + "axios": "^0.27.2" } }, "reusify": { diff --git a/skaffold.yaml b/skaffold.yaml index a07e541..8cd485c 100644 --- a/skaffold.yaml +++ b/skaffold.yaml @@ -12,7 +12,7 @@ build: - image: frontend context: . docker: - dockerfile: packages/frontend + dockerfile: packages/frontend/Dockerfile deploy: helm: From b4f79ec0682c0c11100a1e322f46822679da475a Mon Sep 17 00:00:00 2001 From: Max T Date: Fri, 14 Apr 2023 10:46:09 +0200 Subject: [PATCH 06/14] Log todo --- todos.md | 1 + 1 file changed, 1 insertion(+) diff --git a/todos.md b/todos.md index 3236c5d..6481cd9 100644 --- a/todos.md +++ b/todos.md @@ -17,6 +17,7 @@ skaffold-zeug: - FileSync, damit nicht immer neu gebaut werden muss backend: +- Warum funktionieren probes nicht? - liquibase in initcontainer - https://redhat-scholars.github.io/spring-boot-k8s-tutorial/spring-boot-tutorial/03-kubernetes.html From 27e74175aa79295a3a19853ef076e0ba732ee5f6 Mon Sep 17 00:00:00 2001 From: Max T Date: Fri, 14 Apr 2023 10:46:30 +0200 Subject: [PATCH 07/14] Add helm deployment for frontend quick n dirty --- helm/otto/templates/_helpers.tpl | 4 ++ ...eployment.yaml => backend-deployment.yaml} | 2 +- .../{service.yaml => backend-service.yaml} | 0 helm/otto/templates/frontend-deployment.yaml | 42 +++++++++++++++++++ helm/otto/templates/frontend-service.yaml | 15 +++++++ helm/otto/values.yaml | 8 ++++ skaffold.yaml | 13 ++++-- 7 files changed, 79 insertions(+), 5 deletions(-) rename helm/otto/templates/{deployment.yaml => backend-deployment.yaml} (97%) rename helm/otto/templates/{service.yaml => backend-service.yaml} (100%) create mode 100644 helm/otto/templates/frontend-deployment.yaml create mode 100644 helm/otto/templates/frontend-service.yaml diff --git a/helm/otto/templates/_helpers.tpl b/helm/otto/templates/_helpers.tpl index 2823e1a..d631607 100644 --- a/helm/otto/templates/_helpers.tpl +++ b/helm/otto/templates/_helpers.tpl @@ -49,6 +49,10 @@ Selector labels app.kubernetes.io/name: {{ include "otto.name" . }} app.kubernetes.io/instance: {{ .Release.Name }} {{- end }} +{{- define "otto.selectorLabelsFrontend" -}} +app.kubernetes.io/name: {{ include "otto.name" . }}-frontend +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} {{/* Create the name of the service account to use diff --git a/helm/otto/templates/deployment.yaml b/helm/otto/templates/backend-deployment.yaml similarity index 97% rename from helm/otto/templates/deployment.yaml rename to helm/otto/templates/backend-deployment.yaml index 1d70f5b..6ffa64b 100644 --- a/helm/otto/templates/deployment.yaml +++ b/helm/otto/templates/backend-deployment.yaml @@ -1,7 +1,7 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: {{ include "otto.fullname" . }} + name: {{ include "otto.fullname" . }}-backend labels: {{- include "otto.labels" . | nindent 4 }} spec: diff --git a/helm/otto/templates/service.yaml b/helm/otto/templates/backend-service.yaml similarity index 100% rename from helm/otto/templates/service.yaml rename to helm/otto/templates/backend-service.yaml diff --git a/helm/otto/templates/frontend-deployment.yaml b/helm/otto/templates/frontend-deployment.yaml new file mode 100644 index 0000000..912ae9b --- /dev/null +++ b/helm/otto/templates/frontend-deployment.yaml @@ -0,0 +1,42 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "otto.fullname" . }}-frontend + labels: + {{- include "otto.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.frontend.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "otto.selectorLabelsFrontend" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "otto.selectorLabelsFrontend" . | nindent 8 }} + spec: + serviceAccountName: {{ include "otto.serviceAccountName" . }} + containers: + - name: {{ .Chart.Name }}-frontend + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.frontend.image.repository }}:{{ .Values.frontend.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.frontend.image.pullPolicy }} + ports: + - name: http + containerPort: {{ .Values.frontend.service.port }} + protocol: TCP + livenessProbe: + httpGet: + path: / + port: http + readinessProbe: + httpGet: + path: / + port: http + diff --git a/helm/otto/templates/frontend-service.yaml b/helm/otto/templates/frontend-service.yaml new file mode 100644 index 0000000..9b30d30 --- /dev/null +++ b/helm/otto/templates/frontend-service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "otto.fullname" . }}-frontend + labels: + {{- include "otto.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.frontend.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "otto.selectorLabelsFrontend" . | nindent 4 }} diff --git a/helm/otto/values.yaml b/helm/otto/values.yaml index 1162e18..1fd1afa 100644 --- a/helm/otto/values.yaml +++ b/helm/otto/values.yaml @@ -65,6 +65,14 @@ service: type: ClusterIP port: 8080 +frontend: + service: + port: 80 + replicaCount: 1 + image: + repository: frontend + pullPolicy: IfNotPresent + ingress: enabled: false className: "" diff --git a/skaffold.yaml b/skaffold.yaml index 8cd485c..774b219 100644 --- a/skaffold.yaml +++ b/skaffold.yaml @@ -17,7 +17,7 @@ build: deploy: helm: releases: - - name: backend + - name: otto namespace: 'otto' createNamespace: true chartPath: 'helm/otto' @@ -31,9 +31,14 @@ deploy: repo: 'https://charts.bitnami.com/bitnami' valuesFiles: - "helm/dev-db-config.yaml" - version: 15.2.0 + version: 12.2.7 portForward: - resourceType: Service - resourceName: backend-otto + resourceName: otto namespace: otto - port: 8080 \ No newline at end of file + port: 8080 + - resourceType: Service + resourceName: otto-frontend + namespace: otto + port: 80 + localPort: 3000 \ No newline at end of file From 9d9881bc1583c973a37533eb5637ee5613566c98 Mon Sep 17 00:00:00 2001 From: Max T Date: Fri, 14 Apr 2023 13:14:35 +0200 Subject: [PATCH 08/14] Add ghcr (you will need tokens to push) --- helm/otto/values.yaml | 4 ++-- skaffold.yaml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/helm/otto/values.yaml b/helm/otto/values.yaml index 1fd1afa..5eec591 100644 --- a/helm/otto/values.yaml +++ b/helm/otto/values.yaml @@ -22,7 +22,7 @@ global: replicaCount: 1 image: - repository: backend + repository: ghcr.io/mayflower/otto-backend pullPolicy: IfNotPresent # Overrides the image tag whose default is the chart appVersion. # tag: "" @@ -70,7 +70,7 @@ frontend: port: 80 replicaCount: 1 image: - repository: frontend + repository: ghcr.io/mayflower/otto-frontend pullPolicy: IfNotPresent ingress: diff --git a/skaffold.yaml b/skaffold.yaml index 774b219..454f532 100644 --- a/skaffold.yaml +++ b/skaffold.yaml @@ -4,12 +4,12 @@ metadata: name: otto build: artifacts: - - image: backend + - image: ghcr.io/mayflower/otto-backend context: . jib: project: packages/backend type: maven - - image: frontend + - image: ghcr.io/mayflower/otto-frontend context: . docker: dockerfile: packages/frontend/Dockerfile From ca521226c565825c7f769d77cce6410a25861e48 Mon Sep 17 00:00:00 2001 From: Max T Date: Fri, 14 Apr 2023 13:25:21 +0200 Subject: [PATCH 09/14] Try CI stuff --- .github/workflows/docker-image.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .github/workflows/docker-image.yml diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..5c41dc1 --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,18 @@ +name: Docker Image CI + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Build the Frontend Docker image + run: docker build . --file packages/frontend/Dockerfile --tag otto-frontend:$(date +%s) \ No newline at end of file From d1de2a150eacca58a93ac5f7bed6403600ec02c1 Mon Sep 17 00:00:00 2001 From: Max T Date: Fri, 14 Apr 2023 14:39:43 +0200 Subject: [PATCH 10/14] Add ingress for backend --- helm/otto/values.yaml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/helm/otto/values.yaml b/helm/otto/values.yaml index 5eec591..f2fc9db 100644 --- a/helm/otto/values.yaml +++ b/helm/otto/values.yaml @@ -74,13 +74,17 @@ frontend: pullPolicy: IfNotPresent ingress: - enabled: false - className: "" - annotations: {} + enabled: true + className: "alb" + annotations: + alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80}]' + alb.ingress.kubernetes.io/scheme: internet-facing + alb.ingress.kubernetes.io/tags: "Environment=dev,Team=oTTo" + alb.ingress.kubernetes.io/target-type: ip # kubernetes.io/ingress.class: nginx # kubernetes.io/tls-acme: "true" hosts: - - host: chart-example.local + - host: otto-backend.playground.workshop.mayflower.tech paths: - path: / pathType: ImplementationSpecific From e8e2a0506689cc5fa814c57929a0e95fc7698512 Mon Sep 17 00:00:00 2001 From: Max T Date: Fri, 14 Apr 2023 18:35:01 +0200 Subject: [PATCH 11/14] add https support on eks --- helm/otto/values.yaml | 3 ++- todos.md => infra-todos.md | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) rename todos.md => infra-todos.md (99%) diff --git a/helm/otto/values.yaml b/helm/otto/values.yaml index f2fc9db..43547ec 100644 --- a/helm/otto/values.yaml +++ b/helm/otto/values.yaml @@ -77,7 +77,8 @@ ingress: enabled: true className: "alb" annotations: - alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80}]' + alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80},{"HTTPS":443}]' + alb.ingress.kubernetes.io/ssl-redirect: '443' alb.ingress.kubernetes.io/scheme: internet-facing alb.ingress.kubernetes.io/tags: "Environment=dev,Team=oTTo" alb.ingress.kubernetes.io/target-type: ip diff --git a/todos.md b/infra-todos.md similarity index 99% rename from todos.md rename to infra-todos.md index 6481cd9..b0c6939 100644 --- a/todos.md +++ b/infra-todos.md @@ -20,4 +20,3 @@ skaffold-zeug: - Warum funktionieren probes nicht? - liquibase in initcontainer - https://redhat-scholars.github.io/spring-boot-k8s-tutorial/spring-boot-tutorial/03-kubernetes.html - From a15e17318caaefd45183e18b523148bc8c4c8a4a Mon Sep 17 00:00:00 2001 From: Max T Date: Mon, 17 Apr 2023 13:04:51 +0200 Subject: [PATCH 12/14] Update planings --- infra-todos.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/infra-todos.md b/infra-todos.md index b0c6939..e0ea218 100644 --- a/infra-todos.md +++ b/infra-todos.md @@ -11,7 +11,12 @@ deploy - postgres: wir stellen code für dev bereit, den leute optional für prod hernehmen könnten, wir rechnen aber nicht damit setup - - minikube durch kind/k3s ersetzen? (Install-Größe und Performanz) + - minikube (1.02 GB) durch kind/k3s ersetzen? (Install-Größe und Performanz) + - Findings: + - Kind ist unwesentlich kleiner (823 MB), und es ist deutlich umständlicher, ein Kubernetes-Dashboard zum laufen zu bekommen + - k3s läuft nicht auf MacOS + - k3d wesentlich kleiner in images: 161 + 39 + 18 MB, schnell + -> k3d könnte sich lohnen, wenn aufsetzen reibungslos geht skaffold-zeug: - FileSync, damit nicht immer neu gebaut werden muss From 9aa19ded1cbe967ebeb18b16d8a0e94098857ff4 Mon Sep 17 00:00:00 2001 From: Max T Date: Tue, 18 Apr 2023 17:27:36 +0200 Subject: [PATCH 13/14] Specify nginx version --- packages/frontend/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/frontend/Dockerfile b/packages/frontend/Dockerfile index fae972e..3775dfd 100644 --- a/packages/frontend/Dockerfile +++ b/packages/frontend/Dockerfile @@ -28,7 +28,7 @@ COPY packages/frontend ./ RUN npm run build -FROM nginx:latest as webserver_prod +FROM nginx:1.22-alpine as webserver_prod COPY --from=frontend_builder_prod /app/dist /usr/share/nginx/html EXPOSE 80 From bbb1de3efd4840ddca893424efb3b1fc1ea6061b Mon Sep 17 00:00:00 2001 From: Max T Date: Thu, 27 Apr 2023 12:23:28 +0200 Subject: [PATCH 14/14] Try tilt instead of skaffold --- Tiltfile | 20 ++++++++++++++++++++ flake.nix | 2 +- helm/otto/values.yaml | 2 +- pom.xml | 1 - 4 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 Tiltfile diff --git a/Tiltfile b/Tiltfile new file mode 100644 index 0000000..481aa11 --- /dev/null +++ b/Tiltfile @@ -0,0 +1,20 @@ +load('ext://helm_resource', 'helm_resource', 'helm_repo') +helm_repo('bitnami', 'https://charts.bitnami.com/bitnami') +helm_resource('db', + 'bitnami/postgresql', + namespace="otto", + flags=['--values=./helm/dev-db-config.yaml'] + ) +yaml = helm('./helm/otto', + name='otto', + namespace='otto' +) +k8s_yaml(yaml) + +k8s_resource("otto-frontend", port_forwards='3000:80') +k8s_resource("otto-backend",port_forwards="8080") + +docker_build('ghcr.io/mayflower/otto-frontend','.',dockerfile='packages/frontend/Dockerfile', only=['packages/frontend','packages/api-spec']) +custom_build('ghcr.io/mayflower/otto-backend', +'./mvnw compile jib:dockerBuild -pl packages/backend -Dimage=$EXPECTED_REF', +deps=['packages/backend'], ignore=['bin','target']) \ No newline at end of file diff --git a/flake.nix b/flake.nix index de14860..c1e8573 100644 --- a/flake.nix +++ b/flake.nix @@ -23,9 +23,9 @@ pkgs.skaffold pkgs.openjdk_headless pkgs.nodejs-18_x - pkgs.buildpack pkgs.kubernetes-helm pkgs.k9s + pkgs.tilt ]; }; overlays.default = (final: prev: { diff --git a/helm/otto/values.yaml b/helm/otto/values.yaml index 43547ec..18ffdd0 100644 --- a/helm/otto/values.yaml +++ b/helm/otto/values.yaml @@ -31,7 +31,7 @@ spring: config: dbEndpoint: "db-postgresql.otto" defaultDB: "otto" - wait: true + wait: false minReadySeconds: 30 diff --git a/pom.xml b/pom.xml index dd4e58e..96d0fac 100644 --- a/pom.xml +++ b/pom.xml @@ -13,6 +13,5 @@ packages/backend - packages/frontend \ No newline at end of file