Skip to content

Commit

Permalink
fix: upgrade nctx (following node) (#315)
Browse files Browse the repository at this point in the history
* fix: upgrade nctx (following node)

* fix: up nctx

* fix: plugins tests

* fix: up modjo

* fix: deploy
  • Loading branch information
devthejo authored May 11, 2023
1 parent 58f5d55 commit 15d795b
Show file tree
Hide file tree
Showing 15 changed files with 210 additions and 304 deletions.
17 changes: 2 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"eslint-plugin-jest": "^27.0.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.0.0",
"fs-extra": "^11.1.0",
"fs-extra": "^11.1.1",
"husky": "^8.0.0",
"js-yaml": "^4.1.0",
"lint-staged": "^13.0.0",
Expand All @@ -27,18 +27,6 @@
"~dev-tools": "workspace:^"
},
"resolutions": {
"@modjo/http-server": "latest",
"@modjo/core": "latest",
"@modjo/config": "latest",
"@modjo/express": "latest",
"@modjo/express-monitor": "latest",
"@modjo/http-logger": "latest",
"@modjo/lightship": "latest",
"@modjo/logger": "latest",
"@modjo/microservice-oapi": "latest",
"@modjo/oa": "latest",
"@modjo/shutdown-handlers": "latest",
"@modjo/sentry": "latest",
"tar": "^6.1.9",
"multer": "^1.4.4-lts.1",
"fast-copy": "^3.0.0",
Expand Down Expand Up @@ -76,8 +64,7 @@
"docker:kontinuous:build": "DOCKER_BUILDKIT=1 docker build --progress=plain -f packages/kontinuous/Dockerfile -t kontinuous .",
"docker:kontinuous:run": "docker run -it -v $PWD:/workspace -v $(dirname $KUBECONFIG):/home/node/.kube -e KUBECONFIG=/home/node/.kube/$(basename $KUBECONFIG) kontinuous",
"docker:kontinuous": "yarn docker:kontinuous:build && yarn docker:kontinuous:run",
"logs:remote-webhook": "kubectl --context prod -n kontinuous-webhook logs -f --all-containers -l component=kontinuous-webhook",
"upgrade:modjo": "yarn up -R \"@modjo/*\""
"logs:remote-webhook": "kubectl --context prod -n kontinuous-webhook logs -f --all-containers -l component=kontinuous-webhook"
},
"lint-staged": {
"*.js": [
Expand Down
4 changes: 2 additions & 2 deletions packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
"decompress": "^4.2.1",
"direct-logger": "^2.7.3",
"dotenv": "^16.0.2",
"fs-extra": "^11.1.0",
"fs-extra": "^11.1.1",
"jest-diff": "^29.0.0",
"js-yaml": "^4.1.0",
"lodash.camelcase": "^4.3.0",
"lodash.kebabcase": "^4.1.1",
"lodash.set": "^4.3.2",
"micromatch": "^4.0.5",
"ms": "^2.1.3",
"nctx": "^1.7.1",
"nctx": "^2.2.0",
"parse-url": "^8.1.0",
"qs": "^6.11.0",
"slugify": "^1.6.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/helm-tree/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"dependencies": {
"decompress": "^4.2.1",
"fs-extra": "^11.1.0",
"fs-extra": "^11.1.1",
"~common": "workspace:^"
}
}
4 changes: 2 additions & 2 deletions packages/kontinuous/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"dree": "^4.0.0",
"enquirer": "^2.3.6",
"form-data": "^4.0.0",
"fs-extra": "^11.1.0",
"fs-extra": "^11.1.1",
"helm-tree": "workspace:^",
"launch-editor": "^2.4.0",
"link-module-alias": "^1.2.0",
Expand All @@ -32,7 +32,7 @@
"lodash.omit": "^4.5.0",
"lodash.pick": "^4.4.0",
"lodash.set": "^4.3.2",
"nctx": "^1.7.1",
"nctx": "^2.2.0",
"nowtest": "^1.1.1",
"qs": "^6.10.5",
"ts-node": "^10.8.1",
Expand Down
10 changes: 7 additions & 3 deletions packages/kontinuous/src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ const addCommands = [
require("./commands/test"),
]

module.exports = async (args = process.argv) => {
ctx.provide()

const cli = async (args) => {
const logger = ctx.get("logger") || ctx.set("logger", createLogger())

const signals = ["SIGTERM", "SIGHUP", "SIGINT"]
Expand Down Expand Up @@ -129,3 +127,9 @@ module.exports = async (args = process.argv) => {
process.exit(exitCode)
}
}

module.exports = async (args = process.argv) => {
await ctx.provide(async () => {
await cli(args)
})
}
10 changes: 7 additions & 3 deletions packages/kontinuous/src/deploy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ const buildDeployPlugins = require("./build-deploy-plugins")
const deploySidecars = require("./deploy-sidecars")
const deployWith = require("./deploy-with")

module.exports = async (options) => {
ctx.provide()

const deploy = async (options) => {
await buildDeployPlugins()

const config = ctx.require("config")
Expand Down Expand Up @@ -174,3 +172,9 @@ module.exports = async (options) => {
throw new ExitError(err)
}
}

module.exports = async (options) => {
await ctx.provide(async () => {
await deploy(options)
})
}
45 changes: 23 additions & 22 deletions packages/kontinuous/tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,29 +99,30 @@ describe("test build manifests with snapshots", () => {
)
Object.assign(env, dotenvConfig)
}
ctx.provide()
ctx.set("env", env)

const logger = createLogger({
fields: {
workspacePath: removePrefix(testdirPath, `${process.cwd()}/`),
buildPath,
},
})
ctx.set("logger", logger)

try {
await cli([...process.argv.slice(0, 2), "build"])
} catch (error) {
if (!(error instanceof MockExit && error.exitCode === 0)) {
throw error
await ctx.provide(async () => {
ctx.set("env", env)

const logger = createLogger({
fields: {
workspacePath: removePrefix(testdirPath, `${process.cwd()}/`),
buildPath,
},
})
ctx.set("logger", logger)

try {
await cli([...process.argv.slice(0, 2), "build"])
} catch (error) {
if (!(error instanceof MockExit && error.exitCode === 0)) {
throw error
}
}
}

const result = ctx.require("result")
const { manifests } = result
expect(manifests).toMatchSpecificSnapshot(
`./__snapshots__/${testdir}.${environment}.yaml`
)
const result = ctx.require("result")
const { manifests } = result
expect(manifests).toMatchSpecificSnapshot(
`./__snapshots__/${testdir}.${environment}.yaml`
)
})
})
})
12 changes: 6 additions & 6 deletions packages/webhook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@
"test": "jest tests"
},
"dependencies": {
"@modjo/core": "latest",
"@modjo/express": "^1.0.14",
"@modjo/microservice-oapi": "^1.0.5",
"@modjo/sentry": "^1.2.0",
"@modjo/core": "^1.2.6",
"@modjo/express": "^1.2.6",
"@modjo/microservice-oapi": "^1.2.6",
"@modjo/sentry": "^1.2.6",
"@vercel/ncc": "^0.36.0",
"async-retry": "^1.3.3",
"chokidar": "^3.5.3",
"fs-extra": "^11.1.0",
"fs-extra": "^11.1.1",
"helm-tree": "workspace:^",
"link-module-alias": "^1.2.0",
"lodash.defaultsdeep": "^4.6.1",
"lodash.mergewith": "^4.6.2",
"nctx": "^1.7.1",
"nctx": "^2.2.0",
"node-cron": "^3.0.0",
"rimraf": "^4.1.2",
"uuid": "^9.0.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/webhook/src/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ module.exports = async () => {
return
}

ctx.provide()

// at minute 0 past every 6th hour. see https://crontab.guru/
cron.schedule("0 */6 * * *", cleanArtifact)
await ctx.provide(async () => {
// at minute 0 past every 6th hour. see https://crontab.guru/
cron.schedule("0 */6 * * *", cleanArtifact)
})
}
5 changes: 3 additions & 2 deletions packages/webhook/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module.exports = async (options = {}) => {
},
},
})
commonCtx.provide()
await modjo(options)
await commonCtx.provide(async () => {
await modjo(options)
})
}
33 changes: 17 additions & 16 deletions plugins/contrib/debug-manifests/tests/resources-tree-infos.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,22 @@ samples.forEach((sample) => {
}
)
const manifests = utils.yaml.loadAll(rawYaml)
ctx.provide()
const { logger, removeAllAnsiColors } = utils
logger.minLevel("debug")
ctx.set("logger", logger)
const spy = jest.spyOn(process.stderr, "write")
resourceTreeInfos(
manifests,
{},
{
ctx,
utils,
}
)
expect(
removeAllAnsiColors(spy.mock.calls.map((c) => c[0]).join(""))
).toMatchSnapshot()
await ctx.provide(async () => {
const { logger, removeAllAnsiColors } = utils
logger.minLevel("debug")
ctx.set("logger", logger)
const spy = jest.spyOn(process.stderr, "write")
resourceTreeInfos(
manifests,
{},
{
ctx,
utils,
}
)
expect(
removeAllAnsiColors(spy.mock.calls.map((c) => c[0]).join(""))
).toMatchSnapshot()
})
})
})
2 changes: 1 addition & 1 deletion plugins/contrib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dependencies": {
"async": "^3.2.4",
"async-retry": "^1.3.3",
"fs-extra": "^11.1.0",
"fs-extra": "^11.1.1",
"kubernetes-resource-parser": "^0.1.0",
"lodash.camelcase": "^4.3.0",
"lodash.clonedeep": "^4.5.0",
Expand Down
43 changes: 25 additions & 18 deletions plugins/contrib/patches/tests/janitor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,58 @@ metadata:
name: some-ns
`

const runJanitor = (config, values) => {
const runJanitor = async (config, values) => {
const ctx = require("~common/ctx")
const utils = require("~common/utils")

const manifests = utils.yaml.loadAll(rawNs)
const { logger } = utils
logger.minLevel("debug")
ctx.provide()
ctx.set("logger", logger)
return janitor(
manifests,
{},
{
config,
values,
ctx,
utils,
}
)
return ctx.provide(async () => {
ctx.set("logger", logger)
return janitor(
manifests,
{},
{
config,
values,
ctx,
utils,
}
)
})
}

test(`add janitor annotation in dev`, async () => {
const result = runJanitor({ environment: "dev", gitBranch: "test-branch" })
const result = await runJanitor({
environment: "dev",
gitBranch: "test-branch",
})
expect(result[0].metadata.annotations["janitor/ttl"]).toEqual("7d")
})

test(`add custom janitor annotation in dev`, async () => {
const result = runJanitor(
const result = await runJanitor(
{ environment: "dev", gitBranch: "test-branch" },
{ ttl: "24h" }
)
expect(result[0].metadata.annotations["janitor/ttl"]).toEqual("24h")
})

test(`DONT add janitor in persist env`, async () => {
const result = runJanitor({ environment: "dev", gitBranch: "test/persist" })
const result = await runJanitor({
environment: "dev",
gitBranch: "test/persist",
})
expect(() => result[0].metadata.annotations["janitor/ttl"]).toThrow()
})

test(`DONT add janitor annotation in preprod`, async () => {
const result = runJanitor({ environment: "preprod" })
const result = await runJanitor({ environment: "preprod" })
expect(() => result[0].metadata.annotations["janitor/ttl"]).toThrow()
})

test(`DONT add janitor annotation in prod`, async () => {
const result = runJanitor({ environment: "prod" })
const result = await runJanitor({ environment: "prod" })
expect(() => result[0].metadata.annotations["janitor/ttl"]).toThrow()
})
10 changes: 5 additions & 5 deletions plugins/contrib/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1579,14 +1579,14 @@ __metadata:
languageName: node
linkType: hard

"fs-extra@npm:^11.1.0":
version: 11.1.0
resolution: "fs-extra@npm:11.1.0"
"fs-extra@npm:^11.1.1":
version: 11.1.1
resolution: "fs-extra@npm:11.1.1"
dependencies:
graceful-fs: "npm:^4.2.0"
jsonfile: "npm:^6.0.1"
universalify: "npm:^2.0.0"
checksum: 20d9909070e7d9754cb651af067ae4343b5fc9b05fa9b8765a9348dab7dfa9b78c0f1ebe791774f06d4cca4231f4be9889a916d0457e8e87097a613e6bdd1746
checksum: 9bc3e5ce6860e97abf1fb408f1d716253e1bb16da36203b2ee3f71160e5ec1e7a9d2b9bae4c99a50598a250be6db0e3b17e8031ea7c498c24513857f48db5402
languageName: node
linkType: hard

Expand Down Expand Up @@ -3615,7 +3615,7 @@ __metadata:
dependencies:
async: "npm:^3.2.4"
async-retry: "npm:^1.3.3"
fs-extra: "npm:^11.1.0"
fs-extra: "npm:^11.1.1"
jest: "npm:^29.3.1"
kubernetes-resource-parser: "npm:^0.1.0"
lodash.camelcase: "npm:^4.3.0"
Expand Down
Loading

0 comments on commit 15d795b

Please sign in to comment.