@vaharoni/devops 1.0.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -0
- package/dist/app-support/crypto/index.d.ts +15 -0
- package/dist/app-support/crypto/index.d.ts.map +1 -0
- package/dist/app-support/crypto/index.js +30 -0
- package/dist/app-support/crypto/internal-token.d.ts +20 -0
- package/dist/app-support/crypto/internal-token.d.ts.map +1 -0
- package/dist/app-support/crypto/internal-token.js +42 -0
- package/dist/app-support/crypto/internal-token.spec.d.ts +2 -0
- package/dist/app-support/crypto/internal-token.spec.d.ts.map +1 -0
- package/dist/app-support/crypto/internal-token.spec.js +45 -0
- package/dist/app-support/crypto/secret.d.ts +3 -0
- package/dist/app-support/crypto/secret.d.ts.map +1 -0
- package/dist/app-support/crypto/secret.js +12 -0
- package/dist/app-support/crypto/secret.spec.d.ts +2 -0
- package/dist/app-support/crypto/secret.spec.d.ts.map +1 -0
- package/dist/app-support/crypto/secret.spec.js +15 -0
- package/dist/app-support/discovery/dev-discovery-loader.d.ts +2 -0
- package/dist/app-support/discovery/dev-discovery-loader.d.ts.map +1 -0
- package/dist/app-support/discovery/dev-discovery-loader.js +30 -0
- package/dist/app-support/discovery/service-endpoint.d.ts +2 -0
- package/dist/app-support/discovery/service-endpoint.d.ts.map +1 -0
- package/dist/app-support/discovery/service-endpoint.js +10 -0
- package/dist/cli/affected.d.ts +11 -0
- package/dist/cli/affected.d.ts.map +1 -0
- package/dist/cli/affected.js +103 -0
- package/dist/cli/common.d.ts +89 -0
- package/dist/cli/common.d.ts.map +1 -0
- package/dist/cli/common.js +236 -0
- package/dist/cli/common.spec.d.ts +2 -0
- package/dist/cli/common.spec.d.ts.map +1 -0
- package/dist/cli/common.spec.js +64 -0
- package/dist/cli/console.d.ts +11 -0
- package/dist/cli/console.d.ts.map +1 -0
- package/dist/cli/console.js +35 -0
- package/dist/cli/constant.d.ts +11 -0
- package/dist/cli/constant.d.ts.map +1 -0
- package/dist/cli/constant.js +22 -0
- package/dist/cli/db.d.ts +11 -0
- package/dist/cli/db.d.ts.map +1 -0
- package/dist/cli/db.js +119 -0
- package/dist/cli/dml.d.ts +11 -0
- package/dist/cli/dml.d.ts.map +1 -0
- package/dist/cli/dml.js +116 -0
- package/dist/cli/env.d.ts +11 -0
- package/dist/cli/env.d.ts.map +1 -0
- package/dist/cli/env.js +67 -0
- package/dist/cli/exec.d.ts +11 -0
- package/dist/cli/exec.d.ts.map +1 -0
- package/dist/cli/exec.js +50 -0
- package/dist/cli/image.d.ts +11 -0
- package/dist/cli/image.d.ts.map +1 -0
- package/dist/cli/image.js +140 -0
- package/dist/cli/init.d.ts +11 -0
- package/dist/cli/init.d.ts.map +1 -0
- package/dist/cli/init.js +66 -0
- package/dist/cli/internal-curl.d.ts +11 -0
- package/dist/cli/internal-curl.d.ts.map +1 -0
- package/dist/cli/internal-curl.js +43 -0
- package/dist/cli/job.d.ts +11 -0
- package/dist/cli/job.d.ts.map +1 -0
- package/dist/cli/job.js +67 -0
- package/dist/cli/jwt.d.ts +11 -0
- package/dist/cli/jwt.d.ts.map +1 -0
- package/dist/cli/jwt.js +27 -0
- package/dist/cli/namespace.d.ts +11 -0
- package/dist/cli/namespace.d.ts.map +1 -0
- package/dist/cli/namespace.js +70 -0
- package/dist/cli/prep-build.d.ts +11 -0
- package/dist/cli/prep-build.d.ts.map +1 -0
- package/dist/cli/prep-build.js +82 -0
- package/dist/cli/prisma.d.ts +11 -0
- package/dist/cli/prisma.d.ts.map +1 -0
- package/dist/cli/prisma.js +25 -0
- package/dist/cli/redis.d.ts +11 -0
- package/dist/cli/redis.d.ts.map +1 -0
- package/dist/cli/redis.js +76 -0
- package/dist/cli/registry.d.ts +11 -0
- package/dist/cli/registry.d.ts.map +1 -0
- package/dist/cli/registry.js +58 -0
- package/dist/cli/run-many.d.ts +11 -0
- package/dist/cli/run-many.d.ts.map +1 -0
- package/dist/cli/run-many.js +50 -0
- package/dist/cli/run.d.ts +11 -0
- package/dist/cli/run.d.ts.map +1 -0
- package/dist/cli/run.js +37 -0
- package/dist/cli/template.d.ts +11 -0
- package/dist/cli/template.d.ts.map +1 -0
- package/dist/cli/template.js +123 -0
- package/dist/cli/test.d.ts +11 -0
- package/dist/cli/test.d.ts.map +1 -0
- package/dist/cli/test.js +28 -0
- package/dist/devops.d.ts +3 -0
- package/dist/devops.d.ts.map +1 -0
- package/dist/devops.js +103 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/libs/affected-entities.d.ts +15 -0
- package/dist/libs/affected-entities.d.ts.map +1 -0
- package/dist/libs/affected-entities.js +52 -0
- package/dist/libs/config.d.ts +6 -0
- package/dist/libs/config.d.ts.map +1 -0
- package/dist/libs/config.js +98 -0
- package/dist/libs/dependencies.d.ts +19 -0
- package/dist/libs/dependencies.d.ts.map +1 -0
- package/dist/libs/dependencies.js +62 -0
- package/dist/libs/dependencies.spec.d.ts +2 -0
- package/dist/libs/dependencies.spec.d.ts.map +1 -0
- package/dist/libs/dependencies.spec.js +21 -0
- package/dist/libs/digital-ocean/container-reg.d.ts +6 -0
- package/dist/libs/digital-ocean/container-reg.d.ts.map +1 -0
- package/dist/libs/digital-ocean/container-reg.js +69 -0
- package/dist/libs/discovery/dependencies.d.ts +19 -0
- package/dist/libs/discovery/dependencies.d.ts.map +1 -0
- package/dist/libs/discovery/dependencies.js +62 -0
- package/dist/libs/discovery/dependencies.spec.d.ts +2 -0
- package/dist/libs/discovery/dependencies.spec.d.ts.map +1 -0
- package/dist/libs/discovery/dependencies.spec.js +21 -0
- package/dist/libs/discovery/images.d.ts +5 -0
- package/dist/libs/discovery/images.d.ts.map +1 -0
- package/dist/libs/discovery/images.js +45 -0
- package/dist/libs/discovery/index.d.ts +5 -0
- package/dist/libs/discovery/index.d.ts.map +1 -0
- package/dist/libs/discovery/index.js +55 -0
- package/dist/libs/discovery/package-json-processor.d.ts +3 -0
- package/dist/libs/discovery/package-json-processor.d.ts.map +1 -0
- package/dist/libs/discovery/package-json-processor.js +34 -0
- package/dist/libs/discovery/process-common.d.ts +25 -0
- package/dist/libs/discovery/process-common.d.ts.map +1 -0
- package/dist/libs/discovery/process-common.js +40 -0
- package/dist/libs/discovery/process-package-json.d.ts +3 -0
- package/dist/libs/discovery/process-package-json.d.ts.map +1 -0
- package/dist/libs/discovery/process-package-json.js +34 -0
- package/dist/libs/discovery/process-pyproject-toml.d.ts +3 -0
- package/dist/libs/discovery/process-pyproject-toml.d.ts.map +1 -0
- package/dist/libs/discovery/process-pyproject-toml.js +36 -0
- package/dist/libs/discovery/pyproject-toml-processor.d.ts +3 -0
- package/dist/libs/discovery/pyproject-toml-processor.d.ts.map +1 -0
- package/dist/libs/discovery/pyproject-toml-processor.js +39 -0
- package/dist/libs/git-helpers.d.ts +8 -0
- package/dist/libs/git-helpers.d.ts.map +1 -0
- package/dist/libs/git-helpers.js +20 -0
- package/dist/libs/hetzner/reg-secret.d.ts +3 -0
- package/dist/libs/hetzner/reg-secret.d.ts.map +1 -0
- package/dist/libs/hetzner/reg-secret.js +39 -0
- package/dist/libs/k8s-constants.d.ts +12 -0
- package/dist/libs/k8s-constants.d.ts.map +1 -0
- package/dist/libs/k8s-constants.js +66 -0
- package/dist/libs/k8s-db.d.ts +18 -0
- package/dist/libs/k8s-db.d.ts.map +1 -0
- package/dist/libs/k8s-db.js +73 -0
- package/dist/libs/k8s-generate.d.ts +17 -0
- package/dist/libs/k8s-generate.d.ts.map +1 -0
- package/dist/libs/k8s-generate.js +179 -0
- package/dist/libs/k8s-helpers.d.ts +11 -0
- package/dist/libs/k8s-helpers.d.ts.map +1 -0
- package/dist/libs/k8s-helpers.js +42 -0
- package/dist/libs/k8s-image-config.d.ts +8 -0
- package/dist/libs/k8s-image-config.d.ts.map +1 -0
- package/dist/libs/k8s-image-config.js +113 -0
- package/dist/libs/k8s-job-waiter.d.ts +8 -0
- package/dist/libs/k8s-job-waiter.d.ts.map +1 -0
- package/dist/libs/k8s-job-waiter.js +84 -0
- package/dist/libs/k8s-namespace.d.ts +7 -0
- package/dist/libs/k8s-namespace.d.ts.map +1 -0
- package/dist/libs/k8s-namespace.js +27 -0
- package/dist/libs/k8s-redis.d.ts +6 -0
- package/dist/libs/k8s-redis.d.ts.map +1 -0
- package/dist/libs/k8s-redis.js +31 -0
- package/dist/libs/k8s-secrets-manager.d.ts +5 -0
- package/dist/libs/k8s-secrets-manager.d.ts.map +1 -0
- package/dist/libs/k8s-secrets-manager.js +61 -0
- package/dist/libs/validate-env.d.ts +56 -0
- package/dist/libs/validate-env.d.ts.map +1 -0
- package/dist/libs/validate-env.js +214 -0
- package/dist/libs/validate-env.spec.d.ts +2 -0
- package/dist/libs/validate-env.spec.d.ts.map +1 -0
- package/dist/libs/validate-env.spec.js +168 -0
- package/dist/libs/workspace-discovery.d.ts +2 -0
- package/dist/libs/workspace-discovery.d.ts.map +1 -0
- package/dist/libs/workspace-discovery.js +75 -0
- package/dist/test.d.ts +2 -0
- package/dist/test.d.ts.map +1 -0
- package/dist/test.js +1 -0
- package/dist/types/index.d.ts +925 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +79 -0
- package/package.json +55 -0
- package/src/app-support/crypto/index.ts +31 -0
- package/src/app-support/crypto/internal-token.spec.ts +53 -0
- package/src/app-support/crypto/internal-token.ts +82 -0
- package/src/app-support/crypto/secret.spec.ts +18 -0
- package/src/app-support/crypto/secret.ts +13 -0
- package/src/app-support/discovery/dev-discovery-loader.ts +35 -0
- package/src/app-support/discovery/service-endpoint.ts +12 -0
- package/src/cli/affected.ts +116 -0
- package/src/cli/common.spec.ts +78 -0
- package/src/cli/common.ts +323 -0
- package/src/cli/console.ts +46 -0
- package/src/cli/constant.ts +25 -0
- package/src/cli/db.ts +133 -0
- package/src/cli/dml.ts +126 -0
- package/src/cli/env.ts +87 -0
- package/src/cli/exec.sh +21 -0
- package/src/cli/exec.ts +57 -0
- package/src/cli/image.ts +197 -0
- package/src/cli/init.ts +75 -0
- package/src/cli/internal-curl.ts +48 -0
- package/src/cli/job.ts +80 -0
- package/src/cli/jwt.ts +32 -0
- package/src/cli/namespace.ts +78 -0
- package/src/cli/prep-build.ts +96 -0
- package/src/cli/prisma.ts +33 -0
- package/src/cli/redis.ts +83 -0
- package/src/cli/registry.ts +76 -0
- package/src/cli/run-many.ts +61 -0
- package/src/cli/run.ts +46 -0
- package/src/cli/template.ts +169 -0
- package/src/cli/test.ts +30 -0
- package/src/devops.ts +119 -0
- package/src/index.ts +3 -0
- package/src/libs/affected-entities.ts +71 -0
- package/src/libs/config.ts +117 -0
- package/src/libs/digital-ocean/container-reg.ts +81 -0
- package/src/libs/discovery/dependencies.spec.ts +25 -0
- package/src/libs/discovery/dependencies.ts +73 -0
- package/src/libs/discovery/images.ts +57 -0
- package/src/libs/discovery/index.ts +60 -0
- package/src/libs/discovery/process-common.ts +55 -0
- package/src/libs/discovery/process-package-json.ts +47 -0
- package/src/libs/discovery/process-pyproject-toml.ts +43 -0
- package/src/libs/git-helpers.ts +32 -0
- package/src/libs/hetzner/reg-secret.ts +54 -0
- package/src/libs/k8s-constants.ts +83 -0
- package/src/libs/k8s-db.ts +83 -0
- package/src/libs/k8s-generate.ts +211 -0
- package/src/libs/k8s-helpers.ts +59 -0
- package/src/libs/k8s-image-config.ts +165 -0
- package/src/libs/k8s-job-waiter.ts +124 -0
- package/src/libs/k8s-namespace.ts +41 -0
- package/src/libs/k8s-redis.ts +31 -0
- package/src/libs/k8s-secrets-manager.ts +79 -0
- package/src/libs/validate-env.spec.ts +223 -0
- package/src/libs/validate-env.ts +266 -0
- package/src/target-templates/.devops/config/constants.yaml +17 -0
- package/src/target-templates/.devops/config/images.yaml +88 -0
- package/src/target-templates/.devops/docker-images/common/docker-common.sh +23 -0
- package/src/target-templates/.devops/docker-images/node-services/node-exec.sh +8 -0
- package/src/target-templates/.devops/docker-images/node-services/node-run.sh +8 -0
- package/src/target-templates/.devops/docker-images/node-services.Dockerfile +34 -0
- package/src/target-templates/.devops/docker-images/python-services/python-exec.sh +8 -0
- package/src/target-templates/.devops/docker-images/python-services/python-run.sh +8 -0
- package/src/target-templates/.devops/docker-images/python-services.Dockerfile +29 -0
- package/src/target-templates/.devops/env.example.yaml +23 -0
- package/src/target-templates/.devops/infra/hetzner/abandoned/harbor-values.yaml +30 -0
- package/src/target-templates/.devops/infra/hetzner/abandoned/hcloud-config.yaml +134 -0
- package/src/target-templates/.devops/infra/hetzner/cert-manager.yaml +25 -0
- package/src/target-templates/.devops/infra/hetzner/harbor-cert.yaml +13 -0
- package/src/target-templates/.devops/infra/hetzner/harbor-values.yaml +76 -0
- package/src/target-templates/.devops/infra/hetzner/hcloud-config.yaml +113 -0
- package/src/target-templates/.devops/infra/hetzner/ingress-nginx-annotations.yaml +49 -0
- package/src/target-templates/.devops/infra/hetzner/ingress-nginx-configmap.yaml +8 -0
- package/src/target-templates/.devops/infra/hetzner/retain-storage-class.yaml +8 -0
- package/src/target-templates/.devops/infra/monitoring-ingress.yaml +62 -0
- package/src/target-templates/.devops/infra/stackgres-ui-ingress.yaml +35 -0
- package/src/target-templates/.devops/infra/test.yaml +60 -0
- package/src/target-templates/.devops/manifests/_index.yaml +21 -0
- package/src/target-templates/.devops/manifests/cron-jobs.yaml.hb +55 -0
- package/src/target-templates/.devops/manifests/db-migrate-job.yaml.hb +42 -0
- package/src/target-templates/.devops/manifests/deployment-debug.yaml.hb +44 -0
- package/src/target-templates/.devops/manifests/deployment-process.yaml.hb +47 -0
- package/src/target-templates/.devops/manifests/deployment-web.yaml.hb +53 -0
- package/src/target-templates/.devops/manifests/ingress.yaml.hb +21 -0
- package/src/target-templates/.devops/manifests/prefect.yaml.hb +62 -0
- package/src/target-templates/.devops/manifests/service.yaml.hb +15 -0
- package/src/target-templates/.devops/milvus/production/milvus-values.yaml +2 -0
- package/src/target-templates/.devops/milvus/staging/milvus-values.yaml +2 -0
- package/src/target-templates/.devops/postgres/DailyOperatorRestart.yaml +54 -0
- package/src/target-templates/.devops/postgres/production/cluster/PodDisruptionBudget.yaml +27 -0
- package/src/target-templates/.devops/postgres/production/cluster/SGCluster.yaml +47 -0
- package/src/target-templates/.devops/postgres/production/cluster/StackGres-alerts.yaml +191 -0
- package/src/target-templates/.devops/postgres/production/configurations/06-SGDistributedLogs.yaml +11 -0
- package/src/target-templates/.devops/postgres/production/configurations/07-SGObjectStorage.yaml +18 -0
- package/src/target-templates/.devops/postgres/production/configurations/08-SGScript.yaml +12 -0
- package/src/target-templates/.devops/postgres/staging/cluster/SGCluster.yaml +42 -0
- package/src/target-templates/.devops/postgres/staging/configurations/07-SGObjectStorage.yaml +18 -0
- package/src/target-templates/.devops/postgres/staging/configurations/08-SGScript.yaml +12 -0
- package/src/target-templates/.devops/prefect/production/prefect-values.yaml +14 -0
- package/src/target-templates/.devops/prefect/staging/prefect-values.yaml +14 -0
- package/src/target-templates/.devops/redis/production/redis-values.yaml +20 -0
- package/src/target-templates/.devops/redis/staging/redis-values.yaml +8 -0
- package/src/target-templates/.envrc +5 -0
- package/src/target-templates/.github/actions/build-image@v1/action.yaml +86 -0
- package/src/target-templates/.github/actions/connect-to-digital-ocean@v1/action.yaml +29 -0
- package/src/target-templates/.github/actions/connect-to-hetzner@v1/action.yaml +31 -0
- package/src/target-templates/.github/actions/connect-to-infra@v1/action.yaml +46 -0
- package/src/target-templates/.github/actions/db-migrate@v1/action.yaml +23 -0
- package/src/target-templates/.github/actions/deploy-image@v1/action.yaml +33 -0
- package/src/target-templates/.github/actions/setup-prereq@v1/action.yaml +29 -0
- package/src/target-templates/.github/workflows/k8s-build.yaml +84 -0
- package/src/target-templates/applications/example-data-pipeline/pyproject.toml +14 -0
- package/src/target-templates/applications/example-data-pipeline/src/example_data_pipeline/main.py +38 -0
- package/src/target-templates/applications/example-node/index.ts +30 -0
- package/src/target-templates/applications/example-node/package.json +26 -0
- package/src/target-templates/applications/example-node/tsconfig.json +3 -0
- package/src/target-templates/applications/example-python/pyproject.toml +20 -0
- package/src/target-templates/applications/example-python/src/example_python/__init__.py +0 -0
- package/src/target-templates/applications/example-python/src/example_python/main.py +13 -0
- package/src/target-templates/applications/example-python/src/example_python/scripts.py +17 -0
- package/src/target-templates/applications/example-python/tests/__init__.py +0 -0
- package/src/target-templates/applications/jobs/README.md +68 -0
- package/src/target-templates/applications/jobs/index.ts +1 -0
- package/src/target-templates/applications/jobs/package.json +30 -0
- package/src/target-templates/applications/jobs/tsconfig.json +3 -0
- package/src/target-templates/config/.env.development +1 -0
- package/src/target-templates/config/.env.global +4 -0
- package/src/target-templates/config/.env.test +1 -0
- package/src/target-templates/db/db/__init__.py +0 -0
- package/src/target-templates/db/db/db_client_test.py +46 -0
- package/src/target-templates/db/db-client-test.ts +140 -0
- package/src/target-templates/db/db-client.ts +19 -0
- package/src/target-templates/db/env.yaml +4 -0
- package/src/target-templates/db/package.json +17 -0
- package/src/target-templates/db/prisma/schema.prisma +24 -0
- package/src/target-templates/db/prisma-setup-vitest.ts +27 -0
- package/src/target-templates/db/pyproject.toml +14 -0
- package/src/target-templates/db/tsconfig.json +3 -0
- package/src/target-templates/devops +3 -0
- package/src/target-templates/devopspy +3 -0
- package/src/target-templates/dml/package.json +7 -0
- package/src/target-templates/dml/tsconfig.json +3 -0
- package/src/target-templates/libs/example-node-lib/bun.lock +27 -0
- package/src/target-templates/libs/example-node-lib/index.ts +3 -0
- package/src/target-templates/libs/example-node-lib/package.json +12 -0
- package/src/target-templates/libs/example-node-lib/tsconfig.json +3 -0
- package/src/target-templates/libs/example-python-lib/pyproject.toml +11 -0
- package/src/target-templates/libs/example-python-lib/src/example_python_lib/__init__.py +2 -0
- package/src/target-templates/pyproject.toml +19 -0
- package/src/target-templates/tmp/.gitkeep +0 -0
- package/src/target-templates/tsconfig.json +27 -0
- package/src/test.ts +0 -0
- package/src/types/index.ts +173 -0
package/src/cli/env.ts
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
import { globSync } from "glob";
|
2
|
+
import {
|
3
|
+
deleteMonorepoSecret,
|
4
|
+
getMonorepoSecret,
|
5
|
+
setMonorepoSecret,
|
6
|
+
} from "../libs/k8s-secrets-manager";
|
7
|
+
import { CombinedEnvValidator } from "../libs/validate-env";
|
8
|
+
import {
|
9
|
+
CLICommandParser,
|
10
|
+
dotEnvFilesForEnv,
|
11
|
+
printUsageAndExit,
|
12
|
+
} from "./common";
|
13
|
+
|
14
|
+
const oneLiner = "Commands to manipulate env variables";
|
15
|
+
const keyExamples = `
|
16
|
+
$ devops env get --env staging
|
17
|
+
$ devops env get KEY1 KEY2 --env staging
|
18
|
+
$ devops env set KEY1=123 KEY2=345 --env staging
|
19
|
+
$ devops env delete KEY1 KEY2 --env staging
|
20
|
+
$ devops env validate
|
21
|
+
`;
|
22
|
+
|
23
|
+
const usage = `
|
24
|
+
${oneLiner}
|
25
|
+
|
26
|
+
COMMANDS
|
27
|
+
get Fetches secrets for the chosen environment and printes them to console
|
28
|
+
set Sets specific secrets for the chosen environment
|
29
|
+
delete Deletes specific secrets for the chosen environment
|
30
|
+
validate Validate locally, verifying the existence and type of environment variables against all env.yaml files
|
31
|
+
|
32
|
+
EXAMPLES
|
33
|
+
${keyExamples}
|
34
|
+
`;
|
35
|
+
|
36
|
+
function run(cmdObj: CLICommandParser) {
|
37
|
+
if (cmdObj.help || cmdObj.args.length === 0) printUsageAndExit(usage);
|
38
|
+
const [command, ...rest] = cmdObj.args;
|
39
|
+
switch (command) {
|
40
|
+
case "validate": {
|
41
|
+
const envYamlFiles = globSync("**/env.yaml");
|
42
|
+
|
43
|
+
// We have to have a _validate so that we go through a CommandExecutor which injects env variables into the process
|
44
|
+
cmdObj
|
45
|
+
.executorFromEnv(
|
46
|
+
`devops env _validate ${envYamlFiles.join(" ")}`,
|
47
|
+
{ quiet: false }
|
48
|
+
)
|
49
|
+
.exec();
|
50
|
+
break;
|
51
|
+
}
|
52
|
+
|
53
|
+
case "_validate": {
|
54
|
+
const options = cmdObj.parseOptions({ booleans: ["--skip-dotenv"] });
|
55
|
+
const [_subcmd, ...envYamlFiles] = options.args;
|
56
|
+
const envFiles = options.options["--skip-dotenv"]
|
57
|
+
? []
|
58
|
+
: dotEnvFilesForEnv(cmdObj.env);
|
59
|
+
const validator = new CombinedEnvValidator(envYamlFiles, envFiles);
|
60
|
+
validator.validate();
|
61
|
+
break;
|
62
|
+
}
|
63
|
+
|
64
|
+
case "get": {
|
65
|
+
console.log(getMonorepoSecret(cmdObj.env, rest));
|
66
|
+
break;
|
67
|
+
}
|
68
|
+
|
69
|
+
case "set": {
|
70
|
+
setMonorepoSecret(cmdObj.env, rest);
|
71
|
+
break;
|
72
|
+
}
|
73
|
+
|
74
|
+
case "delete": {
|
75
|
+
deleteMonorepoSecret(cmdObj.env, rest);
|
76
|
+
break;
|
77
|
+
}
|
78
|
+
|
79
|
+
default: {
|
80
|
+
printUsageAndExit(usage);
|
81
|
+
}
|
82
|
+
}
|
83
|
+
}
|
84
|
+
|
85
|
+
export default {
|
86
|
+
env: { oneLiner, keyExamples, run },
|
87
|
+
};
|
package/src/cli/exec.sh
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# The following:
|
4
|
+
# run.sh some-dir some-command arg1 args
|
5
|
+
# Changes the current directory to some-dir and then runs the following command before returning to the original directory:
|
6
|
+
# some-command arg1 arg2
|
7
|
+
#
|
8
|
+
# We cannot use `cwd` in exec or spawn since dotenvx won't inject the env variables properly
|
9
|
+
|
10
|
+
# Change to the provided directory
|
11
|
+
pushd "$1" &> /dev/null || exit
|
12
|
+
|
13
|
+
# Execute the rest of the arguments
|
14
|
+
"${@:2}"
|
15
|
+
|
16
|
+
EXIT_CODE=$?
|
17
|
+
|
18
|
+
# Return to the previous directory
|
19
|
+
popd &> /dev/null
|
20
|
+
|
21
|
+
exit $EXIT_CODE
|
package/src/cli/exec.ts
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
import { CLICommandParser, CommandExecutor, printUsageAndExit } from "./common";
|
2
|
+
import url from "url";
|
3
|
+
import path from "path";
|
4
|
+
import { getWorkspace } from "../libs/discovery";
|
5
|
+
|
6
|
+
const __file__ = url.fileURLToPath(import.meta.url);
|
7
|
+
const __src__ = path.join(path.dirname(__file__), "../..", "src");
|
8
|
+
const execShPath = path.join(__src__, "cli/exec.sh");
|
9
|
+
|
10
|
+
const oneLiner =
|
11
|
+
"Executes a command after injecting env variables, either globally or in a workspace";
|
12
|
+
const keyExamples = `
|
13
|
+
$ devops exec tmp/test.sh
|
14
|
+
$ devops exec bun test.ts --in myworkspace --env staging
|
15
|
+
`.trim();
|
16
|
+
|
17
|
+
const usage = `
|
18
|
+
${oneLiner}
|
19
|
+
|
20
|
+
USAGE
|
21
|
+
devops exec <command>
|
22
|
+
devops exec --in <workspace> <command>
|
23
|
+
devops exec --in <workspace> <command> --interactive
|
24
|
+
|
25
|
+
EXAMPLES
|
26
|
+
${keyExamples}
|
27
|
+
`;
|
28
|
+
|
29
|
+
function run(cmdObj: CLICommandParser) {
|
30
|
+
if (cmdObj.help || cmdObj.args.length === 0) printUsageAndExit(usage);
|
31
|
+
const parsed = cmdObj.parseOptions({
|
32
|
+
params: ["--in"],
|
33
|
+
booleans: ["--interactive"],
|
34
|
+
});
|
35
|
+
const workspace = parsed.options["--in"] as string | undefined;
|
36
|
+
let executor: CommandExecutor;
|
37
|
+
if (workspace) {
|
38
|
+
const rootPath = getWorkspace(workspace).rootPath;
|
39
|
+
executor = cmdObj.executorFromEnv(
|
40
|
+
`${execShPath} ${rootPath} ${parsed.argsStr}`,
|
41
|
+
{ checkEnvYaml: true }
|
42
|
+
);
|
43
|
+
} else {
|
44
|
+
executor = cmdObj.executorFromEnv(parsed.argsStr, { checkEnvYaml: true });
|
45
|
+
}
|
46
|
+
|
47
|
+
const interactive = Boolean(parsed.options["--interactive"]);
|
48
|
+
if (interactive) {
|
49
|
+
executor.spawn();
|
50
|
+
} else {
|
51
|
+
executor.exec();
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
export default {
|
56
|
+
exec: { oneLiner, keyExamples, run },
|
57
|
+
};
|
package/src/cli/image.ts
ADDED
@@ -0,0 +1,197 @@
|
|
1
|
+
import { deleteImageVersion, getImageVersion, getWorkspaceScale, resetWorkspaceScale, setImageVersion, setWorkspaceScale } from "../libs/k8s-image-config";
|
2
|
+
import { CLICommandParser, printUsageAndExit, StrongParams } from "../../src/cli/common";
|
3
|
+
import { generateImageDeployments } from "../libs/k8s-generate";
|
4
|
+
import { applyHandler } from "../libs/k8s-helpers";
|
5
|
+
|
6
|
+
const oneLiner = "Applies image-related manifests, retrieves or set the version deployed, and scales deployments of applications";
|
7
|
+
const keyExamples = `
|
8
|
+
$ devops image deployment gen main-node sha --env staging
|
9
|
+
$ devops image deployment create main-node sha --env staging
|
10
|
+
$ devops image deployment delete main-node --env staging
|
11
|
+
$ devops image version get main-node --env staging
|
12
|
+
$ devops image version set main-node sha --env staging
|
13
|
+
$ devops image version unset main-node --env staging
|
14
|
+
$ devops image scale get main-node --env staging
|
15
|
+
$ devops image scale get main-node www --env staging
|
16
|
+
$ devops image scale set main-node www 3 --env staging
|
17
|
+
$ devops image scale unset main-node --env staging
|
18
|
+
$ devops image scale unset main-node www --env staging
|
19
|
+
`.trim();
|
20
|
+
|
21
|
+
const usage = `
|
22
|
+
${oneLiner}
|
23
|
+
|
24
|
+
GENERATING DEPLOYMENT MANIFESTS
|
25
|
+
devops image deployment gen|create|delete <image-name> <sha>
|
26
|
+
|
27
|
+
gen - generates the manifest file with all applications that are deployed with the image
|
28
|
+
create - generates the manifest file and then runs kubectl apply
|
29
|
+
delete - generates the manifest file and then runs kubectl delete
|
30
|
+
|
31
|
+
MANAGINE APPLICATION SCALE
|
32
|
+
devops image scale get|unset <image-name> [<workspace-name>]
|
33
|
+
devops image scale set <image-name> <workspace-name> <replica-count>
|
34
|
+
|
35
|
+
set - sets the scale count in the image's config map so that it persists across deployments.
|
36
|
+
get - retrieves the current scale count. If workspace is not provided, all workspaces are returned.
|
37
|
+
unset - resets the scale count by removing the key from the image's config map. If workspace is not provided, all workspaces are reset.
|
38
|
+
|
39
|
+
Both 'set' and 'unset' return the previous scale count prior to the operation.
|
40
|
+
|
41
|
+
MANAGING IMAGE VERSIONS
|
42
|
+
devops image version get|unset <image>
|
43
|
+
devops image version set <image> <sha>
|
44
|
+
|
45
|
+
Meant to be called during deployment in order to maintain a record of the most recent deployed version.
|
46
|
+
|
47
|
+
EXAMPLES
|
48
|
+
${keyExamples}
|
49
|
+
`;
|
50
|
+
|
51
|
+
const handlers = {
|
52
|
+
deployment: {
|
53
|
+
gen: (opts: StrongParams) => {
|
54
|
+
console.log(
|
55
|
+
generateImageDeployments(
|
56
|
+
opts.required("env"),
|
57
|
+
opts.required("image"),
|
58
|
+
opts.required("sha")
|
59
|
+
)
|
60
|
+
)
|
61
|
+
},
|
62
|
+
create: (opts: StrongParams) => {
|
63
|
+
applyHandler(
|
64
|
+
'apply-deployment-',
|
65
|
+
'apply',
|
66
|
+
generateImageDeployments(
|
67
|
+
opts.required("env"),
|
68
|
+
opts.required("image"),
|
69
|
+
opts.required("sha")
|
70
|
+
)
|
71
|
+
)
|
72
|
+
},
|
73
|
+
delete: (opts: StrongParams) => {
|
74
|
+
applyHandler(
|
75
|
+
'delete-deployment-',
|
76
|
+
'delete',
|
77
|
+
generateImageDeployments(
|
78
|
+
opts.required("env"),
|
79
|
+
opts.required("image"),
|
80
|
+
"dummy-sha"
|
81
|
+
)
|
82
|
+
)
|
83
|
+
},
|
84
|
+
},
|
85
|
+
scale: {
|
86
|
+
set: (opts: StrongParams) => {
|
87
|
+
const workspace = opts.required("workspace");
|
88
|
+
const image = opts.required("image");
|
89
|
+
const replicas = Number(opts.required("replicas"));
|
90
|
+
const res = setWorkspaceScale(
|
91
|
+
opts.required("env"),
|
92
|
+
image,
|
93
|
+
workspace,
|
94
|
+
replicas
|
95
|
+
);
|
96
|
+
if (res) {
|
97
|
+
console.warn(
|
98
|
+
`Scale for ${workspace} in ${image} set to ${replicas}. Previous value:`
|
99
|
+
);
|
100
|
+
console.log(res);
|
101
|
+
}
|
102
|
+
},
|
103
|
+
get: (opts: StrongParams) => {
|
104
|
+
const workspace = opts.optional("workspace");
|
105
|
+
// Satiate the type checker
|
106
|
+
if (!workspace) {
|
107
|
+
console.log(
|
108
|
+
getWorkspaceScale(
|
109
|
+
opts.required("env"),
|
110
|
+
opts.required("image"),
|
111
|
+
)
|
112
|
+
)
|
113
|
+
} else {
|
114
|
+
console.log(
|
115
|
+
getWorkspaceScale(
|
116
|
+
opts.required("env"),
|
117
|
+
opts.required("image"),
|
118
|
+
workspace
|
119
|
+
)
|
120
|
+
)
|
121
|
+
}
|
122
|
+
},
|
123
|
+
unset: (opts: StrongParams) => {
|
124
|
+
const image = opts.required("image");
|
125
|
+
const workspace = opts.optional("workspace");
|
126
|
+
|
127
|
+
const prev = resetWorkspaceScale(opts.required("env"), image, workspace);
|
128
|
+
if (workspace) {
|
129
|
+
console.warn(`Scale for ${workspace} in ${image} unset. Previous scale:`);
|
130
|
+
console.log(prev);
|
131
|
+
} else {
|
132
|
+
console.warn(
|
133
|
+
`Scale for all workspaces in ${image} unset. Previous scale:`
|
134
|
+
);
|
135
|
+
console.log(prev);
|
136
|
+
}
|
137
|
+
},
|
138
|
+
},
|
139
|
+
version: {
|
140
|
+
get: (opts: StrongParams) => {
|
141
|
+
const version = getImageVersion(
|
142
|
+
opts.required("env"),
|
143
|
+
opts.required("image")
|
144
|
+
)
|
145
|
+
console.log(version ?? "")
|
146
|
+
},
|
147
|
+
set: (opts: StrongParams) => {
|
148
|
+
setImageVersion(
|
149
|
+
opts.required("env"),
|
150
|
+
opts.required("image"),
|
151
|
+
opts.required("sha")
|
152
|
+
)
|
153
|
+
},
|
154
|
+
unset: (opts: StrongParams) => {
|
155
|
+
deleteImageVersion(
|
156
|
+
opts.required("env"),
|
157
|
+
opts.required("image")
|
158
|
+
)
|
159
|
+
},
|
160
|
+
},
|
161
|
+
};
|
162
|
+
|
163
|
+
function run(cmdObj: CLICommandParser) {
|
164
|
+
if (cmdObj.help || cmdObj.args.length < 1) printUsageAndExit(usage);
|
165
|
+
|
166
|
+
const [command, subcommand, image, param1, param2] = cmdObj.args;
|
167
|
+
const commandHandler = handlers[command as keyof typeof handlers];
|
168
|
+
if (!commandHandler) {
|
169
|
+
console.error(`Unknown command: ${command}`);
|
170
|
+
printUsageAndExit(usage);
|
171
|
+
}
|
172
|
+
const handler = commandHandler[subcommand as keyof typeof commandHandler] as (opts: StrongParams) => void;
|
173
|
+
if (!handler) {
|
174
|
+
console.error(`Unknown subcommand: ${subcommand}`);
|
175
|
+
printUsageAndExit(usage);
|
176
|
+
}
|
177
|
+
|
178
|
+
function getExtraParams() {
|
179
|
+
if (command === 'scale') {
|
180
|
+
return subcommand === 'set' ? { workspace: param1, replicas: param2 } : { workspace: param1 };
|
181
|
+
} else {
|
182
|
+
return { sha: param1 };
|
183
|
+
}
|
184
|
+
}
|
185
|
+
|
186
|
+
const params = new StrongParams(usage, {
|
187
|
+
env: cmdObj.env,
|
188
|
+
subcommand,
|
189
|
+
image,
|
190
|
+
...getExtraParams()
|
191
|
+
});
|
192
|
+
handler(params);
|
193
|
+
}
|
194
|
+
|
195
|
+
export default {
|
196
|
+
image: { oneLiner, keyExamples, run },
|
197
|
+
};
|
package/src/cli/init.ts
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
import url from "url";
|
2
|
+
import path from "path";
|
3
|
+
import fs from "fs-extra";
|
4
|
+
|
5
|
+
const __file__ = url.fileURLToPath(import.meta.url);
|
6
|
+
const __root__ = path.join(path.dirname(__file__), "../..");
|
7
|
+
const templatesDir = path.join(__root__, "src/target-templates");
|
8
|
+
const targetDir = process.cwd(); // User's current working directory
|
9
|
+
|
10
|
+
import { CLICommandParser, printUsageAndExit } from "./common";
|
11
|
+
|
12
|
+
const oneLiner =
|
13
|
+
"Initializes the devops utility by copying template files to the current folder";
|
14
|
+
const keyExamples = `$ devops init`;
|
15
|
+
|
16
|
+
const usage = `
|
17
|
+
${oneLiner}
|
18
|
+
|
19
|
+
NOTE
|
20
|
+
No files are overwritten.
|
21
|
+
|
22
|
+
EXAMPLES
|
23
|
+
${keyExamples}
|
24
|
+
`;
|
25
|
+
|
26
|
+
async function run(cmdObj: CLICommandParser) {
|
27
|
+
if (cmdObj.help) printUsageAndExit(usage);
|
28
|
+
copyTemplates();
|
29
|
+
}
|
30
|
+
|
31
|
+
export default {
|
32
|
+
init: { oneLiner, keyExamples, run },
|
33
|
+
};
|
34
|
+
|
35
|
+
async function copyTemplates() {
|
36
|
+
console.log(`Initializing devops files from ${templatesDir} to ${targetDir}`);
|
37
|
+
|
38
|
+
try {
|
39
|
+
// Copy files without overriding existing ones
|
40
|
+
await fs.copy(templatesDir, targetDir, {
|
41
|
+
overwrite: false,
|
42
|
+
errorOnExist: false,
|
43
|
+
dereference: false,
|
44
|
+
});
|
45
|
+
|
46
|
+
console.log(successMessage);
|
47
|
+
} catch (error) {
|
48
|
+
console.error("❌ Failed to initialize devops files:", error);
|
49
|
+
process.exit(1);
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
const successMessage = `
|
54
|
+
✅ Devops files initialized successfully!
|
55
|
+
|
56
|
+
To finish the setup:
|
57
|
+
|
58
|
+
1. add the following entry to the main package.json:
|
59
|
+
"workspaces": [
|
60
|
+
"libs/**",
|
61
|
+
"applications/**",
|
62
|
+
"db/**",
|
63
|
+
"dml/**"
|
64
|
+
],
|
65
|
+
|
66
|
+
2. add the following to your .gitignore:
|
67
|
+
.envrc
|
68
|
+
**/.DS_Store
|
69
|
+
**/.env*
|
70
|
+
config/kubeconfig
|
71
|
+
tmp/**
|
72
|
+
!tmp/**/.gitkeep
|
73
|
+
venv/
|
74
|
+
**/__pycache__
|
75
|
+
`;
|
@@ -0,0 +1,48 @@
|
|
1
|
+
import { InternalToken } from "../app-support/crypto";
|
2
|
+
import { CLICommandParser, printUsageAndExit } from "./common";
|
3
|
+
|
4
|
+
const oneLiner =
|
5
|
+
"Runs a curl command bearing an internal jwt-like token to allow verifying internal communication within the namespace";
|
6
|
+
const keyExamples = `$ devops internal-curl jobs http://service-name:port/path`;
|
7
|
+
|
8
|
+
const usage = `
|
9
|
+
${oneLiner}
|
10
|
+
|
11
|
+
GENERAL USAGE
|
12
|
+
devops internal-curl <subject> [curl-options] <url>
|
13
|
+
|
14
|
+
NOTE
|
15
|
+
--env should not be used with this command. It is expected to be run inside pods in the namespace.
|
16
|
+
Relies on the MONOREPO_BASE_SECRET environment variable for signing the token.
|
17
|
+
|
18
|
+
'subject' is the subject of the token. Receiving endpoints should verify it matches the expected value using the
|
19
|
+
'InternalToken' class exposed by @vaharoni/devops.
|
20
|
+
|
21
|
+
EXAMPLES
|
22
|
+
${keyExamples}
|
23
|
+
`;
|
24
|
+
|
25
|
+
async function run(cmdObj: CLICommandParser) {
|
26
|
+
if (cmdObj.help || cmdObj.args.length === 0 || cmdObj.envForced) printUsageAndExit(usage);
|
27
|
+
const [subject, ...rest] = cmdObj.args;
|
28
|
+
|
29
|
+
// A trick to allow running this command locally while setting the MONOREPO_BASE_SECRET in .env.global.
|
30
|
+
// Basically we have to inject the env variables into the shell, which is why we execute 'devops jwt' first
|
31
|
+
let token;
|
32
|
+
if (process.env.MONOREPO_BASE_SECRET) {
|
33
|
+
token = new InternalToken(subject).generate();
|
34
|
+
} else {
|
35
|
+
const res = cmdObj.executorFromEnv(`devops jwt ${subject}`).exec({ asObject: true });
|
36
|
+
if (res.statusCode !== 0) {
|
37
|
+
console.error("Failed to generate token. Aborting.");
|
38
|
+
process.exit(1);
|
39
|
+
}
|
40
|
+
token = res.stdout.trim();
|
41
|
+
}
|
42
|
+
|
43
|
+
cmdObj.executorFromEnv(`curl -H "Authorization: Bearer ${token}" ${rest.join(" ")}`).exec();
|
44
|
+
}
|
45
|
+
|
46
|
+
export default {
|
47
|
+
'internal-curl': { oneLiner, keyExamples, run },
|
48
|
+
};
|
package/src/cli/job.ts
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
import {
|
2
|
+
} from "../libs/k8s-image-config";
|
3
|
+
import { CLICommandParser, printUsageAndExit, StrongParams } from "../../src/cli/common";
|
4
|
+
import { generateDbMigrateJob } from "../libs/k8s-generate";
|
5
|
+
import { applyHandler } from "../libs/k8s-helpers";
|
6
|
+
import { k8sJobWaiter, printJobStatuses } from "../libs/k8s-job-waiter";
|
7
|
+
import { dbMigrateJobName } from "../libs/k8s-constants";
|
8
|
+
|
9
|
+
const oneLiner = "Creates a k8s job and waits for it to run";
|
10
|
+
const keyExamples = `
|
11
|
+
$ devops job db-migrate gen main-node <sha> --env staging
|
12
|
+
$ devops job db-migrate create main-node <sha> --env staging --timeout 120
|
13
|
+
`.trim();
|
14
|
+
|
15
|
+
const usage = `
|
16
|
+
${oneLiner}
|
17
|
+
|
18
|
+
GENERAL USAGE
|
19
|
+
devops job db-migrate gen <image> <sha>
|
20
|
+
devops job db-migrate create <image> <sha> --timeout <timeout>
|
21
|
+
|
22
|
+
EXAMPLES
|
23
|
+
${keyExamples}
|
24
|
+
`;
|
25
|
+
|
26
|
+
const handlers = {
|
27
|
+
gen: (opts: StrongParams) => {
|
28
|
+
console.log(
|
29
|
+
generateDbMigrateJob(opts.required("env"), opts.required("image"), opts.required("sha"))
|
30
|
+
)
|
31
|
+
},
|
32
|
+
create: async (opts: StrongParams) => {
|
33
|
+
const env = opts.required("env");
|
34
|
+
const image = opts.required("image");
|
35
|
+
const sha = opts.required("sha");
|
36
|
+
const timeout = opts.optional("timeout") ?? '240';
|
37
|
+
const manifest = generateDbMigrateJob(env, image, sha);
|
38
|
+
const jobName = dbMigrateJobName(sha);
|
39
|
+
|
40
|
+
applyHandler(`apply-${jobName}`, 'apply', manifest);
|
41
|
+
const statuses = await k8sJobWaiter(env, Number(timeout ?? '240'), [jobName]);
|
42
|
+
if (statuses && Object.keys(statuses).length > 0) {
|
43
|
+
printJobStatuses(statuses);
|
44
|
+
}
|
45
|
+
},
|
46
|
+
};
|
47
|
+
|
48
|
+
function run(cmdObj: CLICommandParser) {
|
49
|
+
if (cmdObj.help || cmdObj.args.length < 1) printUsageAndExit(usage);
|
50
|
+
|
51
|
+
const parsedArgs = cmdObj.parseOptions({
|
52
|
+
params: ["--timeout"]
|
53
|
+
});
|
54
|
+
|
55
|
+
const [jobName, command, image, sha] = parsedArgs.args;
|
56
|
+
|
57
|
+
if (jobName !== 'db-migrate') {
|
58
|
+
console.error(`Unknown job: ${jobName}. Only db-migrate is supported at this time.`);
|
59
|
+
process.exit(1)
|
60
|
+
}
|
61
|
+
|
62
|
+
const handler = handlers[command as keyof typeof handlers];
|
63
|
+
if (!handler) {
|
64
|
+
console.error(`Unknown command: ${command}`);
|
65
|
+
printUsageAndExit(usage);
|
66
|
+
}
|
67
|
+
|
68
|
+
const timeout = parsedArgs.options["--timeout"] as string | undefined;
|
69
|
+
const params = new StrongParams(usage, {
|
70
|
+
env: cmdObj.env,
|
71
|
+
image,
|
72
|
+
sha,
|
73
|
+
timeout
|
74
|
+
});
|
75
|
+
handler(params);
|
76
|
+
}
|
77
|
+
|
78
|
+
export default {
|
79
|
+
job: { oneLiner, keyExamples, run },
|
80
|
+
};
|
package/src/cli/jwt.ts
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
import { InternalToken } from "../app-support/crypto";
|
2
|
+
import { CLICommandParser, printUsageAndExit } from "./common";
|
3
|
+
|
4
|
+
const oneLiner =
|
5
|
+
"Returns a JWT-like token to allow verifying internal communication within the namespace";
|
6
|
+
const keyExamples = `$ devops jwt jobs`;
|
7
|
+
|
8
|
+
const usage = `
|
9
|
+
${oneLiner}
|
10
|
+
|
11
|
+
GENERAL USAGE
|
12
|
+
devops jwt <subject>
|
13
|
+
|
14
|
+
NOTE
|
15
|
+
The token is valid for 60 seconds and bears the specified subject.
|
16
|
+
--env should not be used with this command. It is expected to be run inside pods in the namespace.
|
17
|
+
Relies on the MONOREPO_BASE_SECRET environment variable for signing the token.
|
18
|
+
|
19
|
+
EXAMPLES
|
20
|
+
${keyExamples}
|
21
|
+
`;
|
22
|
+
|
23
|
+
async function run(cmdObj: CLICommandParser) {
|
24
|
+
if (cmdObj.help || cmdObj.args.length === 0 || cmdObj.envForced) printUsageAndExit(usage);
|
25
|
+
const subject = cmdObj.args[0];
|
26
|
+
|
27
|
+
console.log(new InternalToken(subject).generate());
|
28
|
+
}
|
29
|
+
|
30
|
+
export default {
|
31
|
+
jwt: { oneLiner, keyExamples, run },
|
32
|
+
};
|
@@ -0,0 +1,78 @@
|
|
1
|
+
import {
|
2
|
+
} from "../libs/k8s-image-config";
|
3
|
+
import { CLICommandParser, printUsageAndExit, StrongParams } from "../../src/cli/common";
|
4
|
+
import {
|
5
|
+
copySecretHarborToNamespace,
|
6
|
+
patchServiceAccountImagePullSecret,
|
7
|
+
} from "../../src/libs/hetzner/reg-secret";
|
8
|
+
import { checkEnvSetup, createEmptyEnvSecret, createNamespace, deleteNamespace, patchBaseSecret } from "../libs/k8s-namespace";
|
9
|
+
|
10
|
+
const oneLiner = "Creates the basic prerequisites for a monorepo";
|
11
|
+
const keyExamples = `
|
12
|
+
$ devops namespace create --env staging
|
13
|
+
$ devops namespace delete --env staging
|
14
|
+
$ devops namespace check --env staging
|
15
|
+
`.trim();
|
16
|
+
|
17
|
+
const usage = `
|
18
|
+
${oneLiner}
|
19
|
+
|
20
|
+
GENERAL USAGE
|
21
|
+
devops namespcae create|delete|check --env <env>
|
22
|
+
|
23
|
+
'create' does the following:
|
24
|
+
1. Creates the namepace
|
25
|
+
2. Creates a secret to hold environment variables (used by devops env) and the base cryptographic secret
|
26
|
+
3. On Hetzner, copies the Harbor secret to the namespace and patches the default service account to use it
|
27
|
+
|
28
|
+
'delete' removes the namespace in kubernetes, which deletes all entities within it.
|
29
|
+
|
30
|
+
'check' returns exit code 0 if the namespace exists in kubernetes, 1 otherwise.
|
31
|
+
|
32
|
+
EXAMPLES
|
33
|
+
${keyExamples}
|
34
|
+
`;
|
35
|
+
|
36
|
+
const handlers = {
|
37
|
+
create (opts: StrongParams) {
|
38
|
+
const env = opts.required("env");
|
39
|
+
createNamespace(env);
|
40
|
+
createEmptyEnvSecret(env);
|
41
|
+
patchBaseSecret(env);
|
42
|
+
copySecretHarborToNamespace(env);
|
43
|
+
patchServiceAccountImagePullSecret(env);
|
44
|
+
},
|
45
|
+
delete (opts: StrongParams) {
|
46
|
+
deleteNamespace(opts.required("env"));
|
47
|
+
},
|
48
|
+
check (opts: StrongParams) {
|
49
|
+
const exists = checkEnvSetup(opts.required("env"));
|
50
|
+
if (exists) return;
|
51
|
+
console.error(`
|
52
|
+
The environment does not exist in the cluster.
|
53
|
+
In order to create resources for it in the cluster, it must be first set up. This is done to protect from unintentional resource creation.
|
54
|
+
To set up the environment, run the following from your dev machine:
|
55
|
+
$ devops namespace create --env <env>
|
56
|
+
`);
|
57
|
+
process.exit(1);
|
58
|
+
},
|
59
|
+
};
|
60
|
+
|
61
|
+
function run(cmdObj: CLICommandParser) {
|
62
|
+
if (cmdObj.help || cmdObj.args.length < 1) printUsageAndExit(usage);
|
63
|
+
|
64
|
+
const [command] = cmdObj.args;
|
65
|
+
const handler = handlers[command as keyof typeof handlers];
|
66
|
+
if (!handler) {
|
67
|
+
console.error(`Unknown command: ${command}`);
|
68
|
+
printUsageAndExit(usage);
|
69
|
+
}
|
70
|
+
const params = new StrongParams(usage, {
|
71
|
+
env: cmdObj.env,
|
72
|
+
});
|
73
|
+
handler(params);
|
74
|
+
}
|
75
|
+
|
76
|
+
export default {
|
77
|
+
namespace: { oneLiner, keyExamples, run },
|
78
|
+
};
|