From c713a07531ac3441489a2bd56dde69243abfa203 Mon Sep 17 00:00:00 2001 From: Andrey Platov Date: Sat, 28 Aug 2021 23:28:46 +0200 Subject: [PATCH] tooling update Signed-off-by: Andrey Platov --- .gitignore | 2 +- common/config/rush/pnpm-lock.yaml | 12 +++++++++--- server/front/kube/front.yml | 2 +- server/front/package.json | 4 +++- server/front/src/index.ts | 26 +++++++++++++------------ server/server/Dockerfile | 8 ++++++++ server/server/kube/transactor.yml | 32 +++++++++++++++++++++++++++++++ server/server/package.json | 8 ++++++-- server/workspace/Dockerfile | 8 ++++++++ server/workspace/package.json | 8 ++++++-- server/workspace/run.sh | 18 +++++++++++++++++ server/workspace/src/index.ts | 6 +++++- 12 files changed, 111 insertions(+), 23 deletions(-) create mode 100644 server/server/Dockerfile create mode 100644 server/server/kube/transactor.yml create mode 100644 server/workspace/Dockerfile create mode 100755 server/workspace/run.sh diff --git a/.gitignore b/.gitignore index cf14211bf7..a7244511b4 100644 --- a/.gitignore +++ b/.gitignore @@ -67,5 +67,5 @@ common/deploy/ common/temp/ common/autoinstallers/*/.npmrc **/.rush/temp/ -server/front/bundle.js +bundle.js dist diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index 5544797d63..ff704f6854 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -71,6 +71,7 @@ specifiers: '@tiptap/extension-typography': ~2.0.0-beta.13 '@tiptap/starter-kit': ~2.0.0-beta.89 '@types/cors': ^2.8.12 + '@types/express': ^4.17.13 '@types/express-fileupload': ^1.1.7 '@types/heft-jest': ^1.0.2 '@types/toposort': ^2.0.3 @@ -84,6 +85,7 @@ specifiers: cross-env: ^7.0.3 css-loader: ^5.2.1 dotenv-webpack: ^7.0.2 + esbuild: ^0.12.24 eslint: ^7.32.0 eslint-config-standard-with-typescript: ^20.0.0 eslint-plugin-import: '2' @@ -185,6 +187,7 @@ dependencies: '@tiptap/extension-typography': 2.0.0-beta.13_@tiptap+core@2.0.0-beta.93 '@tiptap/starter-kit': 2.0.0-beta.89 '@types/cors': 2.8.12 + '@types/express': 4.17.13 '@types/express-fileupload': 1.1.7 '@types/heft-jest': 1.0.2 '@types/toposort': 2.0.3 @@ -198,6 +201,7 @@ dependencies: cross-env: 7.0.3 css-loader: 5.2.7_webpack@5.48.0 dotenv-webpack: 7.0.3_webpack@5.48.0 + esbuild: 0.12.24 eslint: 7.32.0 eslint-config-standard-with-typescript: 20.0.0_2e482f375e273d762fe67cbd5e194b49 eslint-plugin-import: 2.23.4_eslint@7.32.0 @@ -9153,7 +9157,7 @@ packages: dev: false file:projects/front.tgz_6c259fadfeb3a4b20890aefe87070b8b: - resolution: {integrity: sha512-LkPDbq5ryvnmz54MLr4Bj2L3G3vpBIoChyagXRYuwq3RVddY0BN0qVlNTafiapGztblj+mhH93NpKddrhMCEIA==, tarball: file:projects/front.tgz} + resolution: {integrity: sha512-XmgU22kXGEisU6bW4q3GuuqhzjWazpokQ+ASxb2Nu7M/cTM+xy9EY/fvessk79EXRTGFvoH4hM2jrbleWKP9ug==, tarball: file:projects/front.tgz} id: file:projects/front.tgz name: '@rush-temp/front' version: 0.0.0 @@ -9727,7 +9731,7 @@ packages: dev: false file:projects/server.tgz_6c259fadfeb3a4b20890aefe87070b8b: - resolution: {integrity: sha512-6XfixxRO1uisszjaBtMFoQCCvv2zWAknPVz3ZmES4q/keIWZuDDP667FpDMJ9maBB1AN7ImI9VBMXNbXDlVUuA==, tarball: file:projects/server.tgz} + resolution: {integrity: sha512-MEVHXm1K1YXXILA5Aq14mHsfYoFCd9Y43+vOFu6SHjXEphIn7J7neQm08DOqMWiSKbWK9uvkNjHEr5Fw12Mbog==, tarball: file:projects/server.tgz} id: file:projects/server.tgz name: '@rush-temp/server' version: 0.0.0 @@ -9736,6 +9740,7 @@ packages: '@types/node': 16.7.1 '@types/ws': 7.4.7 '@typescript-eslint/eslint-plugin': 4.28.5_a8e83fcad666e1ba86be4b2e27a20aea + esbuild: 0.12.24 eslint: 7.32.0 eslint-plugin-import: 2.23.4_eslint@7.32.0 eslint-plugin-node: 11.1.0_eslint@7.32.0 @@ -9995,7 +10000,7 @@ packages: dev: false file:projects/workspace.tgz_6c259fadfeb3a4b20890aefe87070b8b: - resolution: {integrity: sha512-q2/1LqGkYRwsMNbjDjy4ngJlBDAefFWXuEdVyIN0DyBjmBibnEVZuQayjBh5O7xUQYKlT0A7TdVn99hpIwixOA==, tarball: file:projects/workspace.tgz} + resolution: {integrity: sha512-Ircelx/9snTrdceAfj7OBTqmR1tZ/cTtPtdf3zcmTJ+EwFh0rhWQJgd80CSeny6I8wMC+UXcKUk5mGHDqcmKcw==, tarball: file:projects/workspace.tgz} id: file:projects/workspace.tgz name: '@rush-temp/workspace' version: 0.0.0 @@ -10003,6 +10008,7 @@ packages: '@types/heft-jest': 1.0.2 '@types/node': 16.7.1 '@typescript-eslint/eslint-plugin': 4.28.5_a8e83fcad666e1ba86be4b2e27a20aea + esbuild: 0.12.24 eslint: 7.32.0 eslint-plugin-import: 2.23.4_eslint@7.32.0 eslint-plugin-node: 11.1.0_eslint@7.32.0 diff --git a/server/front/kube/front.yml b/server/front/kube/front.yml index a05cb369a8..1e22c08c51 100644 --- a/server/front/kube/front.yml +++ b/server/front/kube/front.yml @@ -4,7 +4,7 @@ kind: Deployment metadata: name: front spec: - replicas: 5 + replicas: 1 selector: matchLabels: app: front diff --git a/server/front/package.json b/server/front/package.json index 125499b8c2..2a937add80 100644 --- a/server/front/package.json +++ b/server/front/package.json @@ -7,7 +7,9 @@ "scripts": { "build": "heft build", "lint:fix": "eslint --fix src", - "bundle": "esbuild src/index.ts --bundle --platform=node > bundle.js & cp -r ../../dev/prod/dist . & cp -r ../../dev/prod/public/* ./dist/" + "bundle": "esbuild src/index.ts --bundle --minify --platform=node > bundle.js & cp -r ../../dev/prod/dist . & cp -r ../../dev/prod/public/* ./dist/", + "docker:build": "docker build -t anticrm/front .", + "docker:push": "docker push anticrm/front" }, "devDependencies": { "@anticrm/platform-rig":"~0.6.0", diff --git a/server/front/src/index.ts b/server/front/src/index.ts index e0f03e4199..8d7a5f6b3a 100644 --- a/server/front/src/index.ts +++ b/server/front/src/index.ts @@ -1,32 +1,34 @@ // // Copyright © 2020, 2021 Anticrm Platform Contributors. // Copyright © 2021 Hardcore Engineering Inc. -// +// // Licensed under the Eclipse Public License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. You may // obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0 -// +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// +// // See the License for the specific language governing permissions and // limitations under the License. // import express from 'express' -import path from 'path' -const port = process.env.PORT || 8080; -const app = express(); +import { resolve, join } from 'path' -// serve static assets normally -app.use(express.static(__dirname + '/dist', { maxAge: '10m'})) +const port = process.env.PORT ?? 8080 +const app = express() + +const dist = resolve(__dirname, 'dist') + +console.log('serving static files from', dist) + +app.use(express.static(dist, { maxAge: '10m' })) -// handle every other route with index.html, which will contain -// a script tag to your application's JavaScript file(s). app.get('*', function (request, response) { - response.sendFile(path.resolve(__dirname + '/dist', 'index.html')) + response.sendFile(join(dist, 'index.html')) }) app.listen(port) -console.log("server started on port " + port) +console.log(`server started on port ${port}`) diff --git a/server/server/Dockerfile b/server/server/Dockerfile new file mode 100644 index 0000000000..e2471add48 --- /dev/null +++ b/server/server/Dockerfile @@ -0,0 +1,8 @@ +FROM node + +WORKDIR /usr/src/app + +COPY bundle.js ./ + +EXPOSE 8080 +CMD [ "node", "bundle.js" ] diff --git a/server/server/kube/transactor.yml b/server/server/kube/transactor.yml new file mode 100644 index 0000000000..640296ec9b --- /dev/null +++ b/server/server/kube/transactor.yml @@ -0,0 +1,32 @@ + +apiVersion: apps/v1 +kind: Deployment +metadata: + name: transactor +spec: + replicas: 1 + selector: + matchLabels: + app: transactor + template: + metadata: + labels: + app: transactor + spec: + containers: + - name: app + image: anticrm/transactor + ports: + - containerPort: 3333 + imagePullPolicy: Always +--- +apiVersion: v1 +kind: Service +metadata: + name: transactor +spec: + selector: + app: transactor + ports: + - port: 80 + targetPort: 3333 diff --git a/server/server/package.json b/server/server/package.json index 92798a3391..16c6ef23f2 100644 --- a/server/server/package.json +++ b/server/server/package.json @@ -7,7 +7,10 @@ "scripts": { "start": "ts-node src/__start.ts", "build": "heft build", - "lint:fix": "eslint --fix src" + "lint:fix": "eslint --fix src", + "bundle": "esbuild src/__start.ts --bundle --minify --platform=node > bundle.js", + "docker:build": "docker build -t anticrm/transactor .", + "docker:push": "docker push anticrm/transactor" }, "devDependencies": { "@anticrm/platform-rig":"~0.6.0", @@ -19,7 +22,8 @@ "eslint-plugin-node":"11", "eslint":"^7.32.0", "@types/ws":"^7.4.7", - "ts-node":"^10.2.1" + "ts-node":"^10.2.1", + "esbuild":"^0.12.24" }, "dependencies": { "@anticrm/core": "~0.6.11", diff --git a/server/workspace/Dockerfile b/server/workspace/Dockerfile new file mode 100644 index 0000000000..fdb9340372 --- /dev/null +++ b/server/workspace/Dockerfile @@ -0,0 +1,8 @@ +FROM node + +WORKDIR /usr/src/app + +COPY bundle.js ./ + +EXPOSE 8080 +CMD [ "bash" ] diff --git a/server/workspace/package.json b/server/workspace/package.json index e1f87e1eda..be38331deb 100644 --- a/server/workspace/package.json +++ b/server/workspace/package.json @@ -7,7 +7,10 @@ "scripts": { "create": "ts-node src/__create.ts", "build": "heft build", - "lint:fix": "eslint --fix src" + "lint:fix": "eslint --fix src", + "bundle": "esbuild src/__create.ts --bundle --minify --platform=node > bundle.js", + "docker:build": "docker build -t anticrm/tools .", + "docker:push": "docker push anticrm/tools" }, "devDependencies": { "@anticrm/platform-rig":"~0.6.0", @@ -17,7 +20,8 @@ "eslint-plugin-promise":"4", "eslint-plugin-node":"11", "eslint":"^7.32.0", - "ts-node":"^10.2.1" + "ts-node":"^10.2.1", + "esbuild":"~0.12.24" }, "dependencies": { "@anticrm/core": "~0.6.11", diff --git a/server/workspace/run.sh b/server/workspace/run.sh new file mode 100755 index 0000000000..c75448b54b --- /dev/null +++ b/server/workspace/run.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# Copyright © 2020, 2021 Anticrm Platform Contributors. +# Copyright © 2021 Hardcore Engineering Inc. +# +# Licensed under the Eclipse Public License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. You may +# obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# +# See the License for the specific language governing permissions and +# limitations under the License. +# + +export MONGODB_ROOT_PASSWORD=$(kubectl get secret --namespace default mng-mongodb -o jsonpath="{.data.mongodb-root-password}" | base64 --decode) +kubectl run mng-mongodb-client --rm --tty -i --restart='Never' --env="MONGO_URL=mongodb://root:$MONGODB_ROOT_PASSWORD@mng-mongodb:27017/" --image anticrm/tools --command -- bash diff --git a/server/workspace/src/index.ts b/server/workspace/src/index.ts index 8ef88e948f..ed0bc13f93 100644 --- a/server/workspace/src/index.ts +++ b/server/workspace/src/index.ts @@ -19,6 +19,10 @@ import { DOMAIN_TX } from '@anticrm/core' import * as txJson from './model.tx.json' +const txes = (txJson as any).default + +console.log(txes) + /** * @public */ @@ -28,7 +32,7 @@ export async function createModel (url: string, dbName: string): Promise await client.connect() const db = client.db(dbName) await db.dropDatabase() - const result = await db.collection(DOMAIN_TX).insertMany(txJson as Document[]) + const result = await db.collection(DOMAIN_TX).insertMany(txes as Document[]) return result.insertedCount } finally { await client.close()