From 88ed1446f4ef2b3222e702eda432a6bd3988dba3 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Fri, 9 Sep 2022 15:46:47 +0200 Subject: [PATCH] fix: secrets for PR --- apps/api/src/jobs/deployApplication.ts | 5 ++++- apps/api/src/lib/buildPacks/common.ts | 11 +++++++++-- apps/api/src/lib/buildPacks/deno.ts | 5 ++++- apps/api/src/lib/buildPacks/nextjs.ts | 5 ++++- apps/api/src/lib/buildPacks/node.ts | 5 ++++- apps/api/src/lib/buildPacks/nuxtjs.ts | 5 ++++- apps/api/src/lib/buildPacks/php.ts | 5 ++++- apps/api/src/lib/buildPacks/python.ts | 5 ++++- apps/api/src/lib/buildPacks/static.ts | 5 ++++- apps/api/src/routes/api/v1/applications/handlers.ts | 5 ++++- apps/ui/src/routes/index.svelte | 1 + 11 files changed, 46 insertions(+), 11 deletions(-) diff --git a/apps/api/src/jobs/deployApplication.ts b/apps/api/src/jobs/deployApplication.ts index 945883bb2..5722dbcfb 100644 --- a/apps/api/src/jobs/deployApplication.ts +++ b/apps/api/src/jobs/deployApplication.ts @@ -261,7 +261,10 @@ import * as buildpacks from '../lib/buildPacks'; if (secrets.length > 0) { secrets.forEach((secret) => { if (pullmergeRequestId) { - if (secret.isPRMRSecret) { + const isSecretFound = secrets.filter(s => s.name === secret.name && s.isPRMRSecret) + if (isSecretFound.length > 0) { + envs.push(`${secret.name}=${isSecretFound[0].value}`); + } else { envs.push(`${secret.name}=${secret.value}`); } } else { diff --git a/apps/api/src/lib/buildPacks/common.ts b/apps/api/src/lib/buildPacks/common.ts index 93b8ca076..f4195e24a 100644 --- a/apps/api/src/lib/buildPacks/common.ts +++ b/apps/api/src/lib/buildPacks/common.ts @@ -688,7 +688,10 @@ export async function buildCacheImageWithNode(data, imageForBuild) { secrets.forEach((secret) => { if (secret.isBuildSecret) { if (pullmergeRequestId) { - if (secret.isPRMRSecret) { + const isSecretFound = secrets.filter(s => s.name === secret.name && s.isPRMRSecret) + if (isSecretFound.length > 0) { + Dockerfile.push(`ARG ${secret.name}=${isSecretFound[0].value}`); + } else { Dockerfile.push(`ARG ${secret.name}=${secret.value}`); } } else { @@ -707,6 +710,7 @@ export async function buildCacheImageWithNode(data, imageForBuild) { Dockerfile.push(`RUN ${installCommand}`); } Dockerfile.push(`RUN ${buildCommand}`); + console.log(Dockerfile.join('\n')) await fs.writeFile(`${workdir}/Dockerfile-cache`, Dockerfile.join('\n')); await buildImage({ ...data, isCache: true }); } @@ -722,7 +726,10 @@ export async function buildCacheImageForLaravel(data, imageForBuild) { secrets.forEach((secret) => { if (secret.isBuildSecret) { if (pullmergeRequestId) { - if (secret.isPRMRSecret) { + const isSecretFound = secrets.filter(s => s.name === secret.name && s.isPRMRSecret) + if (isSecretFound.length > 0) { + Dockerfile.push(`ARG ${secret.name}=${isSecretFound[0].value}`); + } else { Dockerfile.push(`ARG ${secret.name}=${secret.value}`); } } else { diff --git a/apps/api/src/lib/buildPacks/deno.ts b/apps/api/src/lib/buildPacks/deno.ts index 6dafa55ed..f255a5983 100644 --- a/apps/api/src/lib/buildPacks/deno.ts +++ b/apps/api/src/lib/buildPacks/deno.ts @@ -27,7 +27,10 @@ const createDockerfile = async (data, image): Promise => { secrets.forEach((secret) => { if (secret.isBuildSecret) { if (pullmergeRequestId) { - if (secret.isPRMRSecret) { + const isSecretFound = secrets.filter(s => s.name === secret.name && s.isPRMRSecret) + if (isSecretFound.length > 0) { + Dockerfile.push(`ARG ${secret.name}=${isSecretFound[0].value}`); + } else { Dockerfile.push(`ARG ${secret.name}=${secret.value}`); } } else { diff --git a/apps/api/src/lib/buildPacks/nextjs.ts b/apps/api/src/lib/buildPacks/nextjs.ts index 90d80449e..90a70f89b 100644 --- a/apps/api/src/lib/buildPacks/nextjs.ts +++ b/apps/api/src/lib/buildPacks/nextjs.ts @@ -27,7 +27,10 @@ const createDockerfile = async (data, image): Promise => { secrets.forEach((secret) => { if (secret.isBuildSecret) { if (pullmergeRequestId) { - if (secret.isPRMRSecret) { + const isSecretFound = secrets.filter(s => s.name === secret.name && s.isPRMRSecret) + if (isSecretFound.length > 0) { + Dockerfile.push(`ARG ${secret.name}=${isSecretFound[0].value}`); + } else { Dockerfile.push(`ARG ${secret.name}=${secret.value}`); } } else { diff --git a/apps/api/src/lib/buildPacks/node.ts b/apps/api/src/lib/buildPacks/node.ts index ad234aed1..546942542 100644 --- a/apps/api/src/lib/buildPacks/node.ts +++ b/apps/api/src/lib/buildPacks/node.ts @@ -23,7 +23,10 @@ const createDockerfile = async (data, image): Promise => { secrets.forEach((secret) => { if (secret.isBuildSecret) { if (pullmergeRequestId) { - if (secret.isPRMRSecret) { + const isSecretFound = secrets.filter(s => s.name === secret.name && s.isPRMRSecret) + if (isSecretFound.length > 0) { + Dockerfile.push(`ARG ${secret.name}=${isSecretFound[0].value}`); + } else { Dockerfile.push(`ARG ${secret.name}=${secret.value}`); } } else { diff --git a/apps/api/src/lib/buildPacks/nuxtjs.ts b/apps/api/src/lib/buildPacks/nuxtjs.ts index 90d80449e..90a70f89b 100644 --- a/apps/api/src/lib/buildPacks/nuxtjs.ts +++ b/apps/api/src/lib/buildPacks/nuxtjs.ts @@ -27,7 +27,10 @@ const createDockerfile = async (data, image): Promise => { secrets.forEach((secret) => { if (secret.isBuildSecret) { if (pullmergeRequestId) { - if (secret.isPRMRSecret) { + const isSecretFound = secrets.filter(s => s.name === secret.name && s.isPRMRSecret) + if (isSecretFound.length > 0) { + Dockerfile.push(`ARG ${secret.name}=${isSecretFound[0].value}`); + } else { Dockerfile.push(`ARG ${secret.name}=${secret.value}`); } } else { diff --git a/apps/api/src/lib/buildPacks/php.ts b/apps/api/src/lib/buildPacks/php.ts index e6dc1699f..eaf97d1b1 100644 --- a/apps/api/src/lib/buildPacks/php.ts +++ b/apps/api/src/lib/buildPacks/php.ts @@ -16,7 +16,10 @@ const createDockerfile = async (data, image, htaccessFound): Promise => { secrets.forEach((secret) => { if (secret.isBuildSecret) { if (pullmergeRequestId) { - if (secret.isPRMRSecret) { + const isSecretFound = secrets.filter(s => s.name === secret.name && s.isPRMRSecret) + if (isSecretFound.length > 0) { + Dockerfile.push(`ARG ${secret.name}=${isSecretFound[0].value}`); + } else { Dockerfile.push(`ARG ${secret.name}=${secret.value}`); } } else { diff --git a/apps/api/src/lib/buildPacks/python.ts b/apps/api/src/lib/buildPacks/python.ts index 110471179..36d707f16 100644 --- a/apps/api/src/lib/buildPacks/python.ts +++ b/apps/api/src/lib/buildPacks/python.ts @@ -21,7 +21,10 @@ const createDockerfile = async (data, image): Promise => { secrets.forEach((secret) => { if (secret.isBuildSecret) { if (pullmergeRequestId) { - if (secret.isPRMRSecret) { + const isSecretFound = secrets.filter(s => s.name === secret.name && s.isPRMRSecret) + if (isSecretFound.length > 0) { + Dockerfile.push(`ARG ${secret.name}=${isSecretFound[0].value}`); + } else { Dockerfile.push(`ARG ${secret.name}=${secret.value}`); } } else { diff --git a/apps/api/src/lib/buildPacks/static.ts b/apps/api/src/lib/buildPacks/static.ts index 47fa0dfa4..c727985ca 100644 --- a/apps/api/src/lib/buildPacks/static.ts +++ b/apps/api/src/lib/buildPacks/static.ts @@ -24,7 +24,10 @@ const createDockerfile = async (data, image): Promise => { secrets.forEach((secret) => { if (secret.isBuildSecret) { if (pullmergeRequestId) { - if (secret.isPRMRSecret) { + const isSecretFound = secrets.filter(s => s.name === secret.name && s.isPRMRSecret) + if (isSecretFound.length > 0) { + Dockerfile.push(`ARG ${secret.name}=${isSecretFound[0].value}`); + } else { Dockerfile.push(`ARG ${secret.name}=${secret.value}`); } } else { diff --git a/apps/api/src/routes/api/v1/applications/handlers.ts b/apps/api/src/routes/api/v1/applications/handlers.ts index 65f2eac8e..c2b375c2a 100644 --- a/apps/api/src/routes/api/v1/applications/handlers.ts +++ b/apps/api/src/routes/api/v1/applications/handlers.ts @@ -373,7 +373,10 @@ export async function restartApplication(request: FastifyRequest, reply: if (secrets.length > 0) { secrets.forEach((secret) => { if (pullmergeRequestId) { - if (secret.isPRMRSecret) { + const isSecretFound = secrets.filter(s => s.name === secret.name && s.isPRMRSecret) + if (isSecretFound.length > 0) { + envs.push(`${secret.name}=${isSecretFound[0].value}`); + } else { envs.push(`${secret.name}=${secret.value}`); } } else { diff --git a/apps/ui/src/routes/index.svelte b/apps/ui/src/routes/index.svelte index f53aaef01..c0620a42e 100644 --- a/apps/ui/src/routes/index.svelte +++ b/apps/ui/src/routes/index.svelte @@ -188,6 +188,7 @@ return ( (service.name && service.name.toLowerCase().includes($search.toLowerCase())) || (service.type && service.type.toLowerCase().includes($search.toLowerCase())) || + (service.fqdn && service.fqdn.toLowerCase().includes($search.toLowerCase())) || (service.version && service.version.toLowerCase().includes($search.toLowerCase())) || (service.destinationDockerId && service.destinationDocker.name.toLowerCase().includes($search.toLowerCase()))