kube-workflow
Advanced tools
Comparing version 1.0.2 to 1.0.3
const builder = require("./builder") | ||
builder() | ||
builder() |
const os = require("os") | ||
const path = require("path") | ||
const { mkdtemp } = require('fs/promises'); | ||
const { mkdtemp } = require("fs/promises") | ||
const fs = require("fs-extra") | ||
@@ -16,17 +16,30 @@ const yaml = require("js-yaml") | ||
const logger = require("./utils/logger") | ||
const globalLogger = require("./utils/logger") | ||
module.exports = async (envVars) => { | ||
const { buildCtx } = require("./ctx") | ||
if (!envVars){ | ||
const builder = async (envVars) => { | ||
if (!envVars) { | ||
envVars = getEnv() | ||
} | ||
buildCtx.set("env", envVars) | ||
for (const requiredEnv of ["KUBEWORKFLOW_PATH", "WORKSPACE_PATH", "ENVIRONMENT"]){ | ||
if (!envVars[requiredEnv]){ | ||
for (const requiredEnv of [ | ||
"KUBEWORKFLOW_PATH", | ||
"WORKSPACE_PATH", | ||
"ENVIRONMENT", | ||
]) { | ||
if (!envVars[requiredEnv]) { | ||
throw new Error(`Missing mandatory var "${requiredEnv}"`) | ||
} | ||
} | ||
if (!envVars.KWBUILD_PATH) { | ||
envVars.KWBUILD_PATH = await mkdtemp( | ||
path.join(os.tmpdir(), `kube-workflow`) | ||
) | ||
} | ||
const { | ||
KWBUILD_PATH, | ||
KUBEWORKFLOW_PATH, | ||
@@ -36,35 +49,38 @@ ENVIRONMENT, | ||
WORKSPACE_SUBPATH = "/.kube-workflow", | ||
COMPONENTS, | ||
HELM_ARGS = "", | ||
} = envVars | ||
let { KWBUILD_PATH } = envVars | ||
if(!KWBUILD_PATH){ | ||
KWBUILD_PATH = await mkdtemp(path.join(os.tmpdir(), `kube-workflow`)); | ||
} | ||
const logger = globalLogger.child({ KWBUILD_PATH, WORKSPACE_PATH }) | ||
buildCtx.set("logger", logger) | ||
asyncShell.ctx.set("logger", logger) | ||
await fs.ensureDir(KWBUILD_PATH) | ||
process.chdir(KWBUILD_PATH) | ||
logger.debug("Merge charts and overlays") | ||
await fs.copy(`${KUBEWORKFLOW_PATH}/chart`, ".") | ||
await fs.copy(`${KUBEWORKFLOW_PATH}/chart`, KWBUILD_PATH) | ||
await Promise.all([ | ||
fs.copy("./env", "./env.autodevops"), | ||
fs.copy("./common", "./common.autodevops") | ||
fs.copy(`${KWBUILD_PATH}/env`, `${KWBUILD_PATH}/env.autodevops`), | ||
fs.copy(`${KWBUILD_PATH}/common`, `${KWBUILD_PATH}/common.autodevops`), | ||
]) | ||
const workspaceKubeworkflowPath = `${WORKSPACE_PATH}${WORKSPACE_SUBPATH}` | ||
if (await fs.pathExists(workspaceKubeworkflowPath)){ | ||
await fs.copy(workspaceKubeworkflowPath, ".", {dereference: true}) | ||
if (await fs.pathExists(workspaceKubeworkflowPath)) { | ||
await fs.copy(workspaceKubeworkflowPath, KWBUILD_PATH, { | ||
dereference: true, | ||
}) | ||
} | ||
logger.debug("Generate values file") | ||
const getValuesFile = async (file)=>{ | ||
for(const filePath of [ | ||
`${file}.yaml`, | ||
`${file}.yml` | ||
]){ | ||
const getValuesFile = async (file) => { | ||
for (const filePath of [ | ||
`${KWBUILD_PATH}/${file}.yaml`, | ||
`${KWBUILD_PATH}/${file}.yml`, | ||
]) { | ||
if (await fs.pathExists(filePath)) { | ||
return yaml.load(await fs.readFile(filePath, {encoding: "utf-8"})) | ||
return yaml.load(await fs.readFile(filePath, { encoding: "utf-8" })) | ||
} | ||
} | ||
return null | ||
} | ||
const defaultValues = generateValues(envVars) | ||
const defaultValues = generateValues() | ||
const [commonValues, envValues] = await Promise.all([ | ||
@@ -77,43 +93,56 @@ getValuesFile("common/values"), | ||
logger.debug("Compiling composite uses") | ||
await compileUses({ values }) | ||
await compileUses(values) | ||
logger.debug("Compiling additional subcharts instances") | ||
const chart = await compileChart(values) | ||
logger.debug("Merge .kube-workflow env templates") | ||
const envTemplatesDir = `${KWBUILD_PATH}/env/${ENVIRONMENT}/templates` | ||
if(await fs.pathExists(envTemplatesDir)){ | ||
await fs.copy(envTemplatesDir, "templates", { dereference: true }) | ||
if (await fs.pathExists(envTemplatesDir)) { | ||
await fs.copy(envTemplatesDir, `${KWBUILD_PATH}/templates`, { | ||
dereference: true, | ||
}) | ||
} | ||
const { COMPONENTS } = envVars | ||
if (COMPONENTS){ | ||
if (COMPONENTS) { | ||
const components = COMPONENTS.split(" ") | ||
for (const key of Object.keys(chart.dependencies)){ | ||
for (const key of Object.keys(chart.dependencies)) { | ||
values[key].enabled = components.includes(key) | ||
} | ||
} | ||
logger.debug("Write values file") | ||
await fs.writeFile("values.json", JSON.stringify(values)) | ||
await fs.writeFile(`${KWBUILD_PATH}/values.json`, JSON.stringify(values)) | ||
logger.debug("Build base manifest using helm") | ||
const { HELM_ARGS = "" } = envVars | ||
let baseManifests = await asyncShell(`helm template -f values.json ${HELM_ARGS} .`) | ||
let baseManifests = await asyncShell( | ||
`helm template -f values.json ${HELM_ARGS} .`, | ||
{ cwd: KWBUILD_PATH } | ||
) | ||
logger.debug("Set default namespace") | ||
baseManifests = await compiledefaultNs(baseManifests, values) | ||
logger.debug("Write base manifests file") | ||
await fs.writeFile("base/manifests.yaml", baseManifests) | ||
await fs.writeFile(`${KWBUILD_PATH}/base/manifests.yaml`, baseManifests) | ||
logger.debug("Build final manifests using kustomize") | ||
const manifests = await asyncShell(`kustomize build --load-restrictor=LoadRestrictionsNone env/${ENVIRONMENT}`) | ||
logger.debug("Write final manifests file") | ||
await fs.writeFile("manifests.yaml", manifests) | ||
logger.debug("Built manifests: $PWD/manifests.yaml") | ||
const manifests = await asyncShell( | ||
`kustomize build --load-restrictor=LoadRestrictionsNone env/${ENVIRONMENT}`, | ||
{ cwd: KWBUILD_PATH } | ||
) | ||
logger.debug(`Write final manifests file`) | ||
await fs.writeFile(`${KWBUILD_PATH}/manifests.yaml`, manifests) | ||
logger.debug(`Built manifests: ${KWBUILD_PATH}/manifests.yaml`) | ||
return manifests | ||
} | ||
module.exports = async (envVars) => { | ||
buildCtx.provide() | ||
asyncShell.ctx.provide() | ||
const manifests = await builder(envVars) | ||
return manifests | ||
} |
@@ -1,10 +0,15 @@ | ||
const fs = require('fs-extra'); | ||
const yaml = require('js-yaml'); | ||
const fs = require("fs-extra") | ||
const yaml = require("js-yaml") | ||
const { buildCtx } = require("./ctx") | ||
module.exports = async (values) => { | ||
const chart = yaml.load(await fs.readFile("Chart.yaml", { encoding: "utf-8" })) | ||
const { KWBUILD_PATH: rootDir } = buildCtx.require("env") | ||
const chart = yaml.load( | ||
await fs.readFile(`${rootDir}/Chart.yaml`, { encoding: "utf-8" }) | ||
) | ||
const { dependencies } = chart | ||
const dependenciesByName = dependencies.reduce((acc, value)=>{ | ||
const dependenciesByName = dependencies.reduce((acc, value) => { | ||
acc[value.name] = value | ||
@@ -16,9 +21,9 @@ return acc | ||
for (const {name} of [...dependencies]){ | ||
for (const componentKey of componentKeys){ | ||
if (componentKey !== name && componentKey.startsWith(name+"-")){ | ||
for (const { name } of [...dependencies]) { | ||
for (const componentKey of componentKeys) { | ||
if (componentKey !== name && componentKey.startsWith(`${name}-`)) { | ||
dependencies.push({ | ||
...dependenciesByName[name], | ||
alias: componentKey, | ||
condition: `${componentKey}.enabled` | ||
condition: `${componentKey}.enabled`, | ||
}) | ||
@@ -28,7 +33,7 @@ } | ||
} | ||
await fs.writeFile("Chart.yaml", yaml.dump(chart)) | ||
await fs.writeFile(`${rootDir}/Chart.yaml`, yaml.dump(chart)) | ||
for (const {name, alias} of dependencies){ | ||
for (const { name, alias } of dependencies) { | ||
const key = alias || name | ||
if (!values[key]){ | ||
if (!values[key]) { | ||
values[key] = {} | ||
@@ -40,3 +45,2 @@ } | ||
return chart | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
const yaml = require('js-yaml'); | ||
const yaml = require("js-yaml") | ||
@@ -7,10 +7,10 @@ module.exports = async (manifestsDocument, values) => { | ||
const manifests = [] | ||
for (const manifest of iterator){ | ||
if (!manifest){ | ||
for (const manifest of iterator) { | ||
if (!manifest) { | ||
continue | ||
} | ||
if(!manifest.metadata){ | ||
if (!manifest.metadata) { | ||
manifest.metadata = {} | ||
} | ||
if(!manifest.metadata.namespace){ | ||
if (!manifest.metadata.namespace) { | ||
manifest.metadata.namespace = defaultNamespace | ||
@@ -20,3 +20,3 @@ } | ||
} | ||
return manifests.join("---\n") | ||
return manifests.join("---\n") | ||
} |
@@ -1,32 +0,32 @@ | ||
const fs = require('fs-extra'); | ||
const fs = require("fs-extra") | ||
const yaml = require('js-yaml'); | ||
const yaml = require("js-yaml") | ||
const { generate } = require("@socialgouv/env-slug") | ||
const degit = require('degit') | ||
const degit = require("degit") | ||
const miniHash = require("./utils/miniHash") | ||
const logger = require("./utils/logger") | ||
const { buildCtx } = require("./ctx") | ||
const downloadingPromises = {} | ||
const userCwd = process.env.WORKING_DIR || process.env.OLDPWD || process.cwd() | ||
const requireUse = async (use) => { | ||
const logger = buildCtx.require("logger") | ||
const { KWBUILD_PATH: rootDir, WORKSPACE_PATH: userDir } = | ||
buildCtx.require("env") | ||
const slug = generate(use) | ||
use = use.replace("@", "#") | ||
let target = `uses/${slug}` | ||
if (!await fs.pathExists(`${process.cwd()}/${target}`)){ | ||
let loading = downloadingPromises[slug] | ||
if (!loading){ | ||
if (use.startsWith(".") || use.startsWith("/")){ | ||
const src = `${userCwd}/${use}` | ||
let target = `${rootDir}/uses/${slug}` | ||
if (!downloadingPromises[slug]) { | ||
downloadingPromises[slug] = (async () => { | ||
if (use.startsWith(".") || use.startsWith("/")) { | ||
const src = `${userDir}/${use}` | ||
logger.debug(`import local ${src}`) | ||
loading = fs.copy(src, target); | ||
await fs.copy(src, target) | ||
} else { | ||
logger.debug(`degit ${use}`) | ||
loading = degit(use).clone(target) | ||
await degit(use).clone(target) | ||
} | ||
downloadingPromises[slug] = loading | ||
} | ||
await loading | ||
})() | ||
} | ||
await downloadingPromises[slug] | ||
if ((await fs.stat(target)).isDirectory()) { | ||
@@ -38,7 +38,7 @@ target += "/use.yaml" | ||
module.exports = async function compile({ values, file }, parentScope = [], parentWith = {}) { | ||
if (file){ | ||
async function compile({ values, file }, parentScope = [], parentWith = {}) { | ||
if (file) { | ||
values = yaml.load(await fs.readFile(file, { encoding: "utf-8" })) | ||
} | ||
if (!values){ | ||
if (!values) { | ||
return values | ||
@@ -50,3 +50,3 @@ } | ||
const run = runs[i] | ||
if (!run.name) { | ||
@@ -63,11 +63,11 @@ run.name = miniHash(file) | ||
const currentScope = [] | ||
for(const sc of scope){ | ||
for (const sc of scope) { | ||
currentScope.push(sc) | ||
scopes.push(currentScope.join(".")) | ||
} | ||
if (scope.length > 1){ | ||
scopes.push([scope[0], scope[scope.length - 1]].join("..")) | ||
if (scope.length > 1) { | ||
scopes.push([scope[0], scope[scope.length - 1]].join("..")) | ||
} | ||
run.scopes = scopes | ||
run.parentWith = Object.assign({}, parentWith, run.with) | ||
run.parentWith = { ...parentWith, ...run.with } | ||
@@ -77,5 +77,5 @@ if (!run.needs) { | ||
} | ||
run.needs = run.needs.map((r) => [ scope[0], r ].join("..") ) | ||
run.needs = run.needs.map((r) => [scope[0], r].join("..")) | ||
if (!run.use){ | ||
if (!run.use) { | ||
newRuns.push(run) | ||
@@ -87,7 +87,7 @@ continue | ||
const compiled = await compile({ file: target }, scope, run.parentWith) | ||
if (compiled.runs){ | ||
const flat = compiled.runs.map(r => ({ | ||
if (compiled.runs) { | ||
const flat = compiled.runs.map((r) => ({ | ||
action: run.use, | ||
...Object.entries(r).reduce((acc, [key, value]) => { | ||
if (key != "use") { | ||
if (key !== "use") { | ||
acc[key] = value | ||
@@ -105,2 +105,6 @@ } | ||
return values | ||
} | ||
} | ||
module.exports = async (values) => { | ||
return compile({ values }) | ||
} |
@@ -1,9 +0,12 @@ | ||
const fs = require('fs-extra'); | ||
const fs = require("fs-extra") | ||
const envsDir = `${__dirname}/envs` | ||
const getFiles = (path) => fs.readdirSync(path).filter(file => fs.lstatSync(`${path}/${file}`).isFile()) | ||
const getFiles = (path) => | ||
fs | ||
.readdirSync(path) | ||
.filter((file) => fs.lstatSync(`${path}/${file}`).isFile()) | ||
const envs = getFiles(envsDir) | ||
module.exports = () => { | ||
const env = {...process.env} | ||
const env = { ...process.env } | ||
for (const envFile of envs) { | ||
@@ -10,0 +13,0 @@ const vars = require(`${envsDir}/${envFile}`) |
@@ -8,2 +8,2 @@ module.exports = { | ||
KUBEWORKFLOW_PATH: "GITHUB_ACTION_PATH", | ||
} | ||
} |
@@ -1,8 +0,14 @@ | ||
const { spawn } = require('child_process'); | ||
const { spawn } = require("child_process") | ||
const logger = require("./logger") | ||
const nctx = require("nctx") | ||
const globalLogger = require("./logger") | ||
const ctx = nctx.create("asyncShell") | ||
const promiseFromChildProcess = (child) => { | ||
const logger = ctx.get("logger") || globalLogger | ||
const out = [] | ||
child.stdout.on("data", (data)=>{ | ||
child.stdout.on("data", (data) => { | ||
out.push(data) | ||
@@ -15,25 +21,26 @@ }) | ||
return new Promise(function (resolve, reject) { | ||
child.on("close", (code)=>{ | ||
if (code===0){ | ||
if (err.length>0){ | ||
child.on("close", (code) => { | ||
if (code === 0) { | ||
if (err.length > 0) { | ||
logger.warn(err.join()) | ||
} | ||
resolve(out.join()) | ||
}else{ | ||
} else { | ||
reject(err.join()) | ||
} | ||
}); | ||
}); | ||
}) | ||
}) | ||
} | ||
const asyncShell = (arg, options = {}) => { | ||
if(typeof arg === "string"){ | ||
arg = arg.split(" ").filter(arg=>!!arg) | ||
if (typeof arg === "string") { | ||
arg = arg.split(" ").filter((a) => !!a) | ||
} | ||
const [cmd, ...args] = arg | ||
const defaultOptions = { encoding: "utf8" } | ||
const childProcess = spawn(cmd, args, {...defaultOptions, ...options}) | ||
const childProcess = spawn(cmd, args, { ...defaultOptions, ...options }) | ||
return promiseFromChildProcess(childProcess) | ||
} | ||
module.exports = asyncShell | ||
module.exports = asyncShell | ||
module.exports.ctx = ctx |
const pino = require("pino") | ||
const pretty = require('pino-pretty') | ||
const pretty = require("pino-pretty") | ||
const logger = pino(pretty()) | ||
if (process.env.DEBUG) { | ||
if ( | ||
process.env.DEBUG && | ||
process.env.DEBUG !== "0" && | ||
process.env.DEBUG !== "false" | ||
) { | ||
logger.level = pino.levels.values.debug | ||
} | ||
module.exports = logger | ||
module.exports = logger |
@@ -0,13 +1,14 @@ | ||
/* eslint-disable no-bitwise */ | ||
const miniHash = function jenkinsOneAtATimeHash(keyString) { | ||
let hash = 0; | ||
let hash = 0 | ||
for (let charIndex = 0; charIndex < keyString.length; ++charIndex) { | ||
hash += keyString.charCodeAt(charIndex); | ||
hash += hash << 10; | ||
hash ^= hash >> 6; | ||
hash += keyString.charCodeAt(charIndex) | ||
hash += hash << 10 | ||
hash ^= hash >> 6 | ||
} | ||
hash += hash << 3; | ||
hash ^= hash >> 11; | ||
hash += hash << 3 | ||
hash ^= hash >> 11 | ||
return (((hash + (hash << 15)) & 4294967295) >>> 0).toString(16) | ||
} | ||
module.exports = miniHash | ||
module.exports = miniHash |
@@ -1,5 +0,5 @@ | ||
const { execSync } = require('child_process'); | ||
const { execSync } = require("child_process") | ||
const shell = (cmd) => execSync(cmd, { encoding: 'utf8' }) | ||
const shell = (cmd) => execSync(cmd, { encoding: "utf8" }) | ||
module.exports = shell | ||
module.exports = shell |
const { generate } = require("@socialgouv/env-slug") | ||
function generateValues(envVars){ | ||
const { buildCtx } = require("./ctx") | ||
function generateValues() { | ||
const { | ||
@@ -18,31 +19,39 @@ REPOSITORY, | ||
GIT_HEAD_REF, | ||
} = envVars; | ||
} = buildCtx.require("env") | ||
const gitBranch = GIT_HEAD_REF ? GIT_HEAD_REF : GIT_REF | ||
const branchName = gitBranch.replace("refs/heads/", "").replace("refs/tags/",""); | ||
const gitBranch = GIT_HEAD_REF || GIT_REF | ||
const branchName = gitBranch | ||
.replace("refs/heads/", "") | ||
.replace("refs/tags/", "") | ||
const branchSlug = generate(branchName); | ||
const branchSlug = generate(branchName) | ||
const env = ENVIRONMENT | ||
const isProduction = env === "prod"; | ||
const isPreProduction = env === "preprod"; | ||
const isDev = !(isProduction || isPreProduction); | ||
const isProduction = env === "prod" | ||
const isPreProduction = env === "preprod" | ||
const isDev = !(isProduction || isPreProduction) | ||
const repository = REPOSITORY | ||
const repositoryName = repository.split("/").pop(); | ||
const repositoryName = repository.split("/").pop() | ||
const subdomain = isProduction ? repositoryName : isPreProduction ? `${repositoryName }-preprod` | ||
const subdomain = isProduction | ||
? repositoryName | ||
: isPreProduction | ||
? `${repositoryName}-preprod` | ||
: generate(`${repositoryName}-${branchName}`) | ||
const namespace = isProduction ? repositoryName : isPreProduction ? `${repositoryName}-preprod` | ||
const namespace = isProduction | ||
? repositoryName | ||
: isPreProduction | ||
? `${repositoryName}-preprod` | ||
: generate(`${repositoryName}-${branchName}`) | ||
const keepAlive = Boolean(KEEP_ALIVE); | ||
const keepAlive = Boolean(KEEP_ALIVE) | ||
const isRenovate = branchName.startsWith("renovate"); | ||
const isDestroyable = isDev && !keepAlive; | ||
const isRenovate = branchName.startsWith("renovate") | ||
const isDestroyable = isDev && !keepAlive | ||
const ttl = isDestroyable ? (isRenovate ? "1d" : "7d") : ""; | ||
const ttl = isDestroyable ? (isRenovate ? "1d" : "7d") : "" | ||
const sha = GIT_SHA; | ||
const sha = GIT_SHA | ||
const imageTag = isPreProduction | ||
@@ -52,25 +61,30 @@ ? `preprod-${sha}` | ||
? (gitBranch.split("/").pop() || "").substring(1) | ||
: `sha-${sha}`; | ||
: `sha-${sha}` | ||
const MAX_HOSTNAME_SIZE = 53; | ||
const MAX_HOSTNAME_SIZE = 53 | ||
const shortenHost = (hostname) => | ||
hostname.slice(0, MAX_HOSTNAME_SIZE).replace(/-+$/, ""); | ||
hostname.slice(0, MAX_HOSTNAME_SIZE).replace(/-+$/, "") | ||
const rootSocialGouvDomain = "fabrique.social.gouv.fr" | ||
const domain = isProduction ? rootSocialGouvDomain : `dev.${rootSocialGouvDomain}`; | ||
const domain = isProduction | ||
? rootSocialGouvDomain | ||
: `dev.${rootSocialGouvDomain}` | ||
const host = `${shortenHost(subdomain)}.${domain}`; | ||
const host = `${shortenHost(subdomain)}.${domain}` | ||
const registry = IMAGE_REGISTRY || "ghcr.io/socialgouv"; | ||
const imageName = IMAGE_NAME || repositoryName; | ||
const image = `${registry}/${imageName}`; | ||
const registry = IMAGE_REGISTRY || "ghcr.io/socialgouv" | ||
const imageName = IMAGE_NAME || repositoryName | ||
const image = `${registry}/${imageName}` | ||
const rancherProjectId = RANCHER_PROJECT_ID; | ||
const rancherProjectId = RANCHER_PROJECT_ID | ||
const certSecretName = | ||
CERT_SECRET_NAME || (isProduction ? `${repositoryName}-crt` : "wildcard-crt"); | ||
CERT_SECRET_NAME || | ||
(isProduction ? `${repositoryName}-crt` : "wildcard-crt") | ||
const pgSecretName = isProduction ? "pg-user" : | ||
isPreProduction ? "pg-user-preprod" | ||
const pgSecretName = isProduction | ||
? "pg-user" | ||
: isPreProduction | ||
? "pg-user-preprod" | ||
: `pg-user-${branchSlug}` | ||
@@ -80,12 +94,16 @@ | ||
const pgDatabase = isProduction ? productionDatabase : | ||
isPreProduction ? "preprod" | ||
: `autodevops_${branchSlug}` | ||
const pgUser = isProduction ? productionDatabase : | ||
isPreProduction ? "preprod" | ||
: `user_${branchSlug}` | ||
const pgDatabase = isProduction | ||
? productionDatabase | ||
: isPreProduction | ||
? "preprod" | ||
: `autodevops_${branchSlug}` | ||
const jobNamespace = (RANCHER_PROJECT_NAME || repositoryName)+"-ci" | ||
const pgUser = isProduction | ||
? productionDatabase | ||
: isPreProduction | ||
? "preprod" | ||
: `user_${branchSlug}` | ||
const jobNamespace = `${RANCHER_PROJECT_NAME || repositoryName}-ci` | ||
return { | ||
@@ -115,6 +133,5 @@ global: { | ||
}, | ||
}; | ||
} | ||
} | ||
module.exports = generateValues | ||
module.exports = generateValues |
{ | ||
"name": "kube-workflow", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"repository": "git@github.com:SocialGouv/kube-workflow.git", | ||
@@ -12,2 +12,3 @@ "license": "MIT", | ||
"lodash.defaultsdeep": "^4.6.1", | ||
"nctx": "^1.0.1", | ||
"pino": "^7.9.0", | ||
@@ -18,7 +19,13 @@ "pino-pretty": "^7.5.4" | ||
"dotenv": "^16.0.0", | ||
"eslint": "^8.11.0", | ||
"eslint": "^7.32.0", | ||
"eslint-config-airbnb-base": "^15.0.0", | ||
"eslint-config-node": "^4.1.0", | ||
"eslint-config-prettier": "^7", | ||
"eslint-plugin-import": "^2.25.4", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-prettier": "^3.4.1", | ||
"husky": "^7.0.4", | ||
"jest": "^27.5.1", | ||
"jest-specific-snapshot": "^5.0.0", | ||
"lint-staged": "^12.3.5", | ||
"lint-staged": "^11.1.2", | ||
"prettier": "^2.5.1" | ||
@@ -44,2 +51,4 @@ }, | ||
"test": "jest tests", | ||
"test:debug": "DEBUG=1 jest tests", | ||
"test:update-snapshots": "DEBUG=1 jest tests -u", | ||
"build-manifests": "node action/build/build.js", | ||
@@ -46,0 +55,0 @@ "version:patch": "npm version patch", |
@@ -92,3 +92,3 @@ # `socialgouv/kube-workflow` 🚀 | ||
- op: add | ||
path: "/metadata/annotations~1nginx.ingress.kubernetes.io/configuration-snippet" | ||
path: "/metadata/annotations~1nginx.ingress.kubernetes.io~1configuration-snippet" | ||
value: | | ||
@@ -95,0 +95,0 @@ more_set_headers "Content-Security-Policy: default-src 'none'; connect-src 'self' https://*.gouv.fr; font-src 'self'; img-src 'self'; prefetch-src 'self' https://*.gouv.fr; script-src 'self' https://*.gouv.fr; frame-src 'self' https://*.gouv.fr; style-src 'self' 'unsafe-inline'"; |
/* eslint-disable no-undef */ | ||
require('jest-specific-snapshot'); | ||
const os = require('os') | ||
const path = require('path') | ||
const fs = require('fs-extra') | ||
const { readFile, mkdtemp } = require('fs/promises'); | ||
const dotenv = require('dotenv') | ||
const builder = require('../action/build/builder') | ||
require("jest-specific-snapshot") | ||
const os = require("os") | ||
const path = require("path") | ||
const { mkdtemp } = require("fs/promises") | ||
const fs = require("fs-extra") | ||
const dotenv = require("dotenv") | ||
const builder = require("../action/build/builder") | ||
const getDirectories = source => | ||
fs.readdirSync(source, { withFileTypes: true }) | ||
.filter(dirent => dirent.isDirectory() || dirent.isSymbolicLink()) | ||
.map(dirent => dirent.name) | ||
const getDirectories = (source) => | ||
fs | ||
.readdirSync(source, { withFileTypes: true }) | ||
.filter((dirent) => dirent.isDirectory() || dirent.isSymbolicLink()) | ||
.map((dirent) => dirent.name) | ||
@@ -29,14 +30,19 @@ const rootPath = path.resolve(`${__dirname}/..`) | ||
const allEnvs = ["dev", "preprod", "prod"] | ||
for (const testdir of testdirs){ | ||
const specificEnv = testdir.split(".").pop() | ||
const environments = allEnvs.includes(specificEnv) ? [specificEnv] : allEnvs | ||
for (const testdir of testdirs) { | ||
const afterDot = testdir.split(".").pop() | ||
if (afterDot === "disabled") { | ||
continue | ||
} | ||
const environments = allEnvs.includes(afterDot) ? [afterDot] : allEnvs | ||
const testdirPath = `${samplesDir}/${testdir}` | ||
const envFile = `${testdirPath}/.env` | ||
if (fs.pathExistsSync(envFile)) { | ||
const dotenvConfig = dotenv.parse(fs.readFileSync(envFile, { encoding: "utf-8" })) | ||
const dotenvConfig = dotenv.parse( | ||
fs.readFileSync(envFile, { encoding: "utf-8" }) | ||
) | ||
Object.assign(env, dotenvConfig) | ||
} | ||
for (const environment of environments){ | ||
it(`build manifests for test "${testdir}" with env "${environment}"`, async () => { | ||
const tmpDir = await mkdtemp(path.join(os.tmpdir(), `kube-workflow`)); | ||
for (const environment of environments) { | ||
it(`${testdir}.${environment}`, async () => { | ||
const tmpDir = await mkdtemp(path.join(os.tmpdir(), `kube-workflow`)) | ||
const env = { | ||
@@ -52,7 +58,8 @@ ...process.env, | ||
} | ||
await builder(env) | ||
const output = await readFile(`${tmpDir}/manifests.yaml`, { encoding: "utf-8" }) | ||
expect(output).toMatchSpecificSnapshot(`./__snapshots__/${testdir}.${environment}.yaml`); | ||
}); | ||
const output = await builder(env) | ||
expect(output).toMatchSpecificSnapshot( | ||
`./__snapshots__/${testdir}.${environment}.yaml` | ||
) | ||
}) | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 2 instances in 1 package
530829
137
527
9
13
+ Addednctx@^1.0.1
+ Addedlodash.get@4.4.2(transitive)
+ Addedlodash.merge@4.6.2(transitive)
+ Addedlodash.set@4.3.2(transitive)
+ Addednctx@1.7.1(transitive)