Skip to content

Commit

Permalink
feat(general-data-source): add new component (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thrimbda authored Nov 17, 2023
1 parent 224d4cd commit 0d55caf
Show file tree
Hide file tree
Showing 17 changed files with 1,053 additions and 0 deletions.
411 changes: 411 additions & 0 deletions apps/general-data-source/api-extractor.json

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions apps/general-data-source/build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# syntax = docker/dockerfile:1.4

FROM node:18.17.0-bullseye-slim

LABEL maintainer="Siyuan Wang <[email protected]>"

# https://github.com/nodejs/docker-node/blob/main/docs/BestPractices.md#handling-kernel-signals
ARG TINI_VERSION=v0.19.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
RUN chmod a+x /tini
ENTRYPOINT ["/tini", "--"]

USER node

WORKDIR /app

ENV NODE_ENV=production

COPY --chown=node:node ./out/app-general-data-source-out /app

RUN node create-links.js create

WORKDIR /app/apps/general-data-source

# USER nobody
CMD ["node", "./lib/index.js"]
3 changes: 3 additions & 0 deletions apps/general-data-source/config/jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@rushstack/heft-node-rig/profiles/default/config/jest.config.json"
}
18 changes: 18 additions & 0 deletions apps/general-data-source/config/rig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// The "rig.json" file directs tools to look for their config files in an external package.
// Documentation for this system: https://www.npmjs.com/package/@rushstack/rig-package
{
"$schema": "https://developer.microsoft.com/json-schemas/rig-package/rig.schema.json",

/**
* (Required) The name of the rig package to inherit from.
* It should be an NPM package name with the "-rig" suffix.
*/
"rigPackageName": "@rushstack/heft-node-rig"

/**
* (Optional) Selects a config profile from the rig package. The name must consist of
* lowercase alphanumeric words separated by hyphens, for example "sample-profile".
* If omitted, then the "default" profile will be used."
*/
// "rigProfile": "your-profile-name"
}
87 changes: 87 additions & 0 deletions apps/general-data-source/config/typescript.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/**
* Configures the TypeScript plugin for Heft. This plugin also manages linting.
*/
{
"$schema": "https://developer.microsoft.com/json-schemas/heft/typescript.schema.json",

/**
* Optionally specifies another JSON config file that this file extends from. This provides a way for standard
* settings to be shared across multiple projects.
*/
// "extends": "base-project/config/typescript.json",

/**
* Can be set to "copy" or "hardlink". If set to "copy", copy files from cache.
* If set to "hardlink", files will be hardlinked to the cache location.
* This option is useful when producing a tarball of build output as TAR files don't
* handle these hardlinks correctly. "hardlink" is the default behavior.
*/
// "copyFromCacheMode": "copy",

/**
* If provided, emit these module kinds in addition to the modules specified in the tsconfig.
* Note that this option only applies to the main tsconfig.json configuration.
*/
"additionalModuleKindsToEmit": [
{
"moduleKind": "esnext",
"outFolderName": "dist"
}
// {
// /**
// * (Required) Must be one of "commonjs", "amd", "umd", "system", "es2015", "esnext"
// */
// "moduleKind": "amd",
//
// /**
// * (Required) The name of the folder where the output will be written.
// */
// "outFolderName": "lib-amd"
// }
],

/**
* Specifies the intermediary folder that tests will use. Because Jest uses the
* Node.js runtime to execute tests, the module format must be CommonJS.
*
* The default value is "lib".
*/
// "emitFolderNameForTests": "lib-commonjs",

/**
* If set to "true", the TSlint task will not be invoked.
*/
// "disableTslint": true,

/**
* Set this to change the maximum number of file handles that will be opened concurrently for writing.
* The default is 50.
*/
// "maxWriteParallelism": 50,

/**
* Configures additional file types that should be copied into the TypeScript compiler's emit folders, for example
* so that these files can be resolved by import statements.
*/
"staticAssetsToCopy": {
/**
* File extensions that should be copied from the src folder to the destination folder(s).
*/
// "fileExtensions": [
// ".json", ".css"
// ],
/**
* Glob patterns that should be explicitly included.
*/
// "includeGlobs": [
// "some/path/*.js"
// ],
/**
* Glob patterns that should be explicitly excluded. This takes precedence over globs listed
* in "includeGlobs" and files that match the file extensions provided in "fileExtensions".
*/
// "excludeGlobs": [
// "some/path/*.css"
// ]
}
}
9 changes: 9 additions & 0 deletions apps/general-data-source/etc/app-general-data-source.api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## API Report File for "@yuants/app-general-data-source"

> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts

// (No @packageDocumentation comment for this package)

```
37 changes: 37 additions & 0 deletions apps/general-data-source/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "@yuants/app-general-data-source",
"version": "0.0.0",
"main": "lib/index.js",
"files": [
"dist",
"lib",
"temp"
],
"scripts": {
"build": "heft test --clean && api-extractor run --local && yuan-toolkit post-build"
},
"dependencies": {
"@yuants/protocol": "workspace:*",
"ajv": "~8.12.0",
"cron": "~2.3.0",
"rxjs": "~7.5.6",
"@yuants/utils": "workspace:*"
},
"devDependencies": {
"@microsoft/api-extractor": "~7.30.0",
"@rushstack/heft": "~0.47.5",
"@rushstack/heft-jest-plugin": "~0.3.30",
"@rushstack/heft-node-rig": "~1.10.7",
"@types/cron": "~2.0.1",
"@types/heft-jest": "1.0.3",
"@types/json-schema": "~7.0.11",
"@types/node": "18",
"@yuants/extension": "workspace:*",
"@yuants/tool-kit": "workspace:*",
"typescript": "~4.7.4"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org"
}
}
88 changes: 88 additions & 0 deletions apps/general-data-source/src/extension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { IExtensionContext, makeDockerEnvs, makeK8sEnvs } from '@yuants/extension';
export default (context: IExtensionContext) => {
context.registerDeployProvider({
make_json_schema: () => ({
type: 'object',
title: 'General Data Source',
properties: {
env: {
type: 'object',
required: ['HV_URL', 'STORAGE_TERMINAL_ID'],
properties: {
TERMINAL_ID: { type: 'string' },
HV_URL: { type: 'string' },
STORAGE_TERMINAL_ID: { type: 'string' },
},
},
},
}),
make_docker_compose_file: async (ctx, envCtx) => ({
[`general-data-source`]: {
image: `registry.ap-southeast-1.aliyuncs.com/ntnl-y/app-general-data-source:${
ctx.version ?? envCtx.version
}`,
environment: makeDockerEnvs(ctx.env),
},
}),
make_k8s_resource_objects: async (ctx, envCtx) => {
return {
deployment: {
apiVersion: 'apps/v1',
kind: 'Deployment',
metadata: {
labels: {
'y.ntnl.io/version': ctx.version ?? envCtx.version,
'y.ntnl.io/component': 'general-data-source',
},
name: `general-data-source`,
namespace: 'yuan',
},
spec: {
replicas: 1,
selector: {
matchLabels: {
'y.ntnl.io/component': 'general-data-source',
},
},
template: {
metadata: {
labels: {
'y.ntnl.io/version': ctx.version ?? envCtx.version,
'y.ntnl.io/component': 'general-data-source',
},
},
spec: {
containers: [
{
env: makeK8sEnvs(ctx.env),
image: `registry.ap-southeast-1.aliyuncs.com/ntnl-y/app-general-data-source:${
ctx.version ?? envCtx.version
}`,
imagePullPolicy: 'IfNotPresent',
name: 'general-data-source',
resources: {
limits: {
cpu: ctx.cpu?.max ?? '400m',
memory: ctx.memory?.max ?? '512Mi',
},
requests: {
cpu: ctx.cpu?.min ?? '20m',
memory: ctx.memory?.min ?? '64Mi',
},
},
},
],
hostname: 'general-data-source',
imagePullSecrets: [
{
name: 'pull-secret',
},
],
},
},
},
},
};
},
});
};
Loading

0 comments on commit 0d55caf

Please sign in to comment.