fix: cleanupStuckedContainers

This commit is contained in:
Andras Bacsai
2023-01-23 10:37:14 +01:00
parent 18ed2527e8
commit ade7c8566d
415 changed files with 9686 additions and 6 deletions

View File

@@ -0,0 +1,842 @@
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var common_exports = {};
__export(common_exports, {
buildCacheImageForLaravel: () => buildCacheImageForLaravel,
buildCacheImageWithCargo: () => buildCacheImageWithCargo,
buildCacheImageWithNode: () => buildCacheImageWithNode,
buildImage: () => buildImage,
checkPnpm: () => checkPnpm,
copyBaseConfigurationFiles: () => copyBaseConfigurationFiles,
makeLabelForSimpleDockerfile: () => makeLabelForSimpleDockerfile,
makeLabelForStandaloneApplication: () => makeLabelForStandaloneApplication,
saveBuildLog: () => saveBuildLog,
saveDockerRegistryCredentials: () => saveDockerRegistryCredentials,
scanningTemplates: () => scanningTemplates,
setDefaultBaseImage: () => setDefaultBaseImage,
setDefaultConfiguration: () => setDefaultConfiguration
});
module.exports = __toCommonJS(common_exports);
var import_common = require("../common");
var import_fs = require("fs");
var import_dayjs = require("../dayjs");
var import_prisma = require("../../prisma");
var import_executeCommand = require("../executeCommand");
const staticApps = ["static", "react", "vuejs", "svelte", "gatsby", "astro", "eleventy"];
const nodeBased = [
"react",
"preact",
"vuejs",
"svelte",
"gatsby",
"astro",
"eleventy",
"node",
"nestjs",
"nuxtjs",
"nextjs"
];
function setDefaultBaseImage(buildPack, deploymentType = null) {
const nodeVersions = [
{
value: "node:lts",
label: "node:lts"
},
{
value: "node:18",
label: "node:18"
},
{
value: "node:17",
label: "node:17"
},
{
value: "node:16",
label: "node:16"
},
{
value: "node:14",
label: "node:14"
},
{
value: "node:12",
label: "node:12"
}
];
const staticVersions = [
{
value: "webdevops/nginx:alpine",
label: "webdevops/nginx:alpine"
},
{
value: "webdevops/apache:alpine",
label: "webdevops/apache:alpine"
},
{
value: "nginx:alpine",
label: "nginx:alpine"
},
{
value: "httpd:alpine",
label: "httpd:alpine (Apache)"
}
];
const rustVersions = [
{
value: "rust:latest",
label: "rust:latest"
},
{
value: "rust:1.60",
label: "rust:1.60"
},
{
value: "rust:1.60-buster",
label: "rust:1.60-buster"
},
{
value: "rust:1.60-bullseye",
label: "rust:1.60-bullseye"
},
{
value: "rust:1.60-slim-buster",
label: "rust:1.60-slim-buster"
},
{
value: "rust:1.60-slim-bullseye",
label: "rust:1.60-slim-bullseye"
},
{
value: "rust:1.60-alpine3.14",
label: "rust:1.60-alpine3.14"
},
{
value: "rust:1.60-alpine3.15",
label: "rust:1.60-alpine3.15"
}
];
const phpVersions = [
{
value: "webdevops/php-apache:8.2",
label: "webdevops/php-apache:8.2"
},
{
value: "webdevops/php-nginx:8.2",
label: "webdevops/php-nginx:8.2"
},
{
value: "webdevops/php-apache:8.1",
label: "webdevops/php-apache:8.1"
},
{
value: "webdevops/php-nginx:8.1",
label: "webdevops/php-nginx:8.1"
},
{
value: "webdevops/php-apache:8.0",
label: "webdevops/php-apache:8.0"
},
{
value: "webdevops/php-nginx:8.0",
label: "webdevops/php-nginx:8.0"
},
{
value: "webdevops/php-apache:7.4",
label: "webdevops/php-apache:7.4"
},
{
value: "webdevops/php-nginx:7.4",
label: "webdevops/php-nginx:7.4"
},
{
value: "webdevops/php-apache:7.3",
label: "webdevops/php-apache:7.3"
},
{
value: "webdevops/php-nginx:7.3",
label: "webdevops/php-nginx:7.3"
},
{
value: "webdevops/php-apache:7.2",
label: "webdevops/php-apache:7.2"
},
{
value: "webdevops/php-nginx:7.2",
label: "webdevops/php-nginx:7.2"
},
{
value: "webdevops/php-apache:7.1",
label: "webdevops/php-apache:7.1"
},
{
value: "webdevops/php-nginx:7.1",
label: "webdevops/php-nginx:7.1"
},
{
value: "webdevops/php-apache:7.0",
label: "webdevops/php-apache:7.0"
},
{
value: "webdevops/php-nginx:7.0",
label: "webdevops/php-nginx:7.0"
},
{
value: "webdevops/php-apache:5.6",
label: "webdevops/php-apache:5.6"
},
{
value: "webdevops/php-nginx:5.6",
label: "webdevops/php-nginx:5.6"
},
{
value: "webdevops/php-apache:8.2-alpine",
label: "webdevops/php-apache:8.2-alpine"
},
{
value: "webdevops/php-nginx:8.2-alpine",
label: "webdevops/php-nginx:8.2-alpine"
},
{
value: "webdevops/php-apache:8.1-alpine",
label: "webdevops/php-apache:8.1-alpine"
},
{
value: "webdevops/php-nginx:8.1-alpine",
label: "webdevops/php-nginx:8.1-alpine"
},
{
value: "webdevops/php-apache:8.0-alpine",
label: "webdevops/php-apache:8.0-alpine"
},
{
value: "webdevops/php-nginx:8.0-alpine",
label: "webdevops/php-nginx:8.0-alpine"
},
{
value: "webdevops/php-apache:7.4-alpine",
label: "webdevops/php-apache:7.4-alpine"
},
{
value: "webdevops/php-nginx:7.4-alpine",
label: "webdevops/php-nginx:7.4-alpine"
},
{
value: "webdevops/php-apache:7.3-alpine",
label: "webdevops/php-apache:7.3-alpine"
},
{
value: "webdevops/php-nginx:7.3-alpine",
label: "webdevops/php-nginx:7.3-alpine"
},
{
value: "webdevops/php-apache:7.2-alpine",
label: "webdevops/php-apache:7.2-alpine"
},
{
value: "webdevops/php-nginx:7.2-alpine",
label: "webdevops/php-nginx:7.2-alpine"
},
{
value: "webdevops/php-apache:7.1-alpine",
label: "webdevops/php-apache:7.1-alpine"
},
{
value: "php:8.1-fpm",
label: "php:8.1-fpm"
},
{
value: "php:8.0-fpm",
label: "php:8.0-fpm"
},
{
value: "php:8.1-fpm-alpine",
label: "php:8.1-fpm-alpine"
},
{
value: "php:8.0-fpm-alpine",
label: "php:8.0-fpm-alpine"
}
];
const pythonVersions = [
{
value: "python:3.10-alpine",
label: "python:3.10-alpine"
},
{
value: "python:3.10-buster",
label: "python:3.10-buster"
},
{
value: "python:3.10-bullseye",
label: "python:3.10-bullseye"
},
{
value: "python:3.10-slim-bullseye",
label: "python:3.10-slim-bullseye"
},
{
value: "python:3.9-alpine",
label: "python:3.9-alpine"
},
{
value: "python:3.9-buster",
label: "python:3.9-buster"
},
{
value: "python:3.9-bullseye",
label: "python:3.9-bullseye"
},
{
value: "python:3.9-slim-bullseye",
label: "python:3.9-slim-bullseye"
},
{
value: "python:3.8-alpine",
label: "python:3.8-alpine"
},
{
value: "python:3.8-buster",
label: "python:3.8-buster"
},
{
value: "python:3.8-bullseye",
label: "python:3.8-bullseye"
},
{
value: "python:3.8-slim-bullseye",
label: "python:3.8-slim-bullseye"
},
{
value: "python:3.7-alpine",
label: "python:3.7-alpine"
},
{
value: "python:3.7-buster",
label: "python:3.7-buster"
},
{
value: "python:3.7-bullseye",
label: "python:3.7-bullseye"
},
{
value: "python:3.7-slim-bullseye",
label: "python:3.7-slim-bullseye"
}
];
const herokuVersions = [
{
value: "heroku/builder:22",
label: "heroku/builder:22"
},
{
value: "heroku/buildpacks:20",
label: "heroku/buildpacks:20"
},
{
value: "heroku/builder-classic:22",
label: "heroku/builder-classic:22"
}
];
let payload = {
baseImage: null,
baseBuildImage: null,
baseImages: [],
baseBuildImages: []
};
if (nodeBased.includes(buildPack)) {
if (deploymentType === "static") {
payload.baseImage = (0, import_common.isARM)(process.arch) ? "nginx:alpine" : "webdevops/nginx:alpine";
payload.baseImages = (0, import_common.isARM)(process.arch) ? staticVersions.filter((version2) => !version2.value.includes("webdevops")) : staticVersions;
payload.baseBuildImage = "node:lts";
payload.baseBuildImages = nodeVersions;
} else {
payload.baseImage = "node:lts";
payload.baseImages = nodeVersions;
payload.baseBuildImage = "node:lts";
payload.baseBuildImages = nodeVersions;
}
}
if (staticApps.includes(buildPack)) {
payload.baseImage = (0, import_common.isARM)(process.arch) ? "nginx:alpine" : "webdevops/nginx:alpine";
payload.baseImages = (0, import_common.isARM)(process.arch) ? staticVersions.filter((version2) => !version2.value.includes("webdevops")) : staticVersions;
payload.baseBuildImage = "node:lts";
payload.baseBuildImages = nodeVersions;
}
if (buildPack === "python") {
payload.baseImage = "python:3.10-alpine";
payload.baseImages = pythonVersions;
}
if (buildPack === "rust") {
payload.baseImage = "rust:latest";
payload.baseBuildImage = "rust:latest";
payload.baseImages = rustVersions;
payload.baseBuildImages = rustVersions;
}
if (buildPack === "deno") {
payload.baseImage = "denoland/deno:latest";
}
if (buildPack === "php") {
payload.baseImage = (0, import_common.isARM)(process.arch) ? "php:8.1-fpm-alpine" : "webdevops/php-apache:8.2-alpine";
payload.baseImages = (0, import_common.isARM)(process.arch) ? phpVersions.filter((version2) => !version2.value.includes("webdevops")) : phpVersions;
}
if (buildPack === "laravel") {
payload.baseImage = (0, import_common.isARM)(process.arch) ? "php:8.1-fpm-alpine" : "webdevops/php-apache:8.2-alpine";
payload.baseImages = (0, import_common.isARM)(process.arch) ? phpVersions.filter((version2) => !version2.value.includes("webdevops")) : phpVersions;
payload.baseBuildImage = "node:18";
payload.baseBuildImages = nodeVersions;
}
if (buildPack === "heroku") {
payload.baseImage = "heroku/buildpacks:20";
payload.baseImages = herokuVersions;
}
return payload;
}
const setDefaultConfiguration = async (data) => {
let {
buildPack,
port,
installCommand,
startCommand,
buildCommand,
publishDirectory,
baseDirectory,
dockerFileLocation,
dockerComposeFileLocation,
denoMainFile
} = data;
const template = scanningTemplates[buildPack];
if (!port) {
port = template?.port || 3e3;
if (buildPack === "static")
port = 80;
else if (buildPack === "node")
port = 3e3;
else if (buildPack === "php")
port = 80;
else if (buildPack === "python")
port = 8e3;
}
if (!installCommand && buildPack !== "static" && buildPack !== "laravel")
installCommand = template?.installCommand || "yarn install";
if (!startCommand && buildPack !== "static" && buildPack !== "laravel")
startCommand = template?.startCommand || "yarn start";
if (!buildCommand && buildPack !== "static" && buildPack !== "laravel")
buildCommand = template?.buildCommand || null;
if (!publishDirectory)
publishDirectory = template?.publishDirectory || null;
if (baseDirectory) {
if (!baseDirectory.startsWith("/"))
baseDirectory = `/${baseDirectory}`;
if (baseDirectory.endsWith("/") && baseDirectory !== "/")
baseDirectory = baseDirectory.slice(0, -1);
}
if (dockerFileLocation) {
if (!dockerFileLocation.startsWith("/"))
dockerFileLocation = `/${dockerFileLocation}`;
if (dockerFileLocation.endsWith("/"))
dockerFileLocation = dockerFileLocation.slice(0, -1);
} else {
dockerFileLocation = "/Dockerfile";
}
if (dockerComposeFileLocation) {
if (!dockerComposeFileLocation.startsWith("/"))
dockerComposeFileLocation = `/${dockerComposeFileLocation}`;
if (dockerComposeFileLocation.endsWith("/"))
dockerComposeFileLocation = dockerComposeFileLocation.slice(0, -1);
} else {
dockerComposeFileLocation = "/Dockerfile";
}
if (!denoMainFile) {
denoMainFile = "main.ts";
}
return {
buildPack,
port,
installCommand,
startCommand,
buildCommand,
publishDirectory,
baseDirectory,
dockerFileLocation,
dockerComposeFileLocation,
denoMainFile
};
};
const scanningTemplates = {
"@sveltejs/kit": {
buildPack: "nodejs"
},
astro: {
buildPack: "astro"
},
"@11ty/eleventy": {
buildPack: "eleventy"
},
svelte: {
buildPack: "svelte"
},
"@nestjs/core": {
buildPack: "nestjs"
},
next: {
buildPack: "nextjs"
},
nuxt: {
buildPack: "nuxtjs"
},
"react-scripts": {
buildPack: "react"
},
"parcel-bundler": {
buildPack: "static"
},
"@vue/cli-service": {
buildPack: "vuejs"
},
vuejs: {
buildPack: "vuejs"
},
gatsby: {
buildPack: "gatsby"
},
"preact-cli": {
buildPack: "react"
}
};
const saveBuildLog = async ({
line,
buildId,
applicationId
}) => {
if (buildId === "undefined" || buildId === "null" || !buildId)
return;
if (applicationId === "undefined" || applicationId === "null" || !applicationId)
return;
const { default: got } = await import("got");
if (typeof line === "object" && line) {
if (line.shortMessage) {
line = line.shortMessage + "\n" + line.stderr;
} else {
line = JSON.stringify(line);
}
}
if (line && typeof line === "string" && line.includes("ghs_")) {
const regex = /ghs_.*@/g;
line = line.replace(regex, "<SENSITIVE_DATA_DELETED>@");
}
const addTimestamp = `[${(0, import_common.generateTimestamp)()}] ${line}`;
const fluentBitUrl = import_common.isDev ? process.env.COOLIFY_CONTAINER_DEV === "true" ? "http://coolify-fluentbit:24224" : "http://localhost:24224" : "http://coolify-fluentbit:24224";
if (import_common.isDev && !process.env.COOLIFY_CONTAINER_DEV) {
console.debug(`[${applicationId}] ${addTimestamp}`);
}
try {
return await got.post(`${fluentBitUrl}/${applicationId}_buildlog_${buildId}.csv`, {
json: {
line: (0, import_common.encrypt)(line)
}
});
} catch (error) {
return await import_prisma.prisma.buildLog.create({
data: {
line: addTimestamp,
buildId,
time: Number((0, import_dayjs.day)().valueOf()),
applicationId
}
});
}
};
async function copyBaseConfigurationFiles(buildPack, workdir, buildId, applicationId, baseImage) {
try {
if (buildPack === "php") {
await import_fs.promises.writeFile(`${workdir}/entrypoint.sh`, `chown -R 1000 /app`);
await saveBuildLog({
line: "Copied default configuration file for PHP.",
buildId,
applicationId
});
} else if (baseImage?.includes("nginx")) {
await import_fs.promises.writeFile(
`${workdir}/nginx.conf`,
`user nginx;
worker_processes auto;
error_log /docker.stdout;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /docker.stdout main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
server {
listen 80;
server_name localhost;
location / {
root /app;
index index.html;
try_files $uri $uri/index.html $uri/ /index.html =404;
}
error_page 404 /50x.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /app;
}
}
}
`
);
}
} catch (error) {
throw new Error(error);
}
}
function checkPnpm(installCommand = null, buildCommand = null, startCommand = null) {
return installCommand?.includes("pnpm") || buildCommand?.includes("pnpm") || startCommand?.includes("pnpm");
}
async function saveDockerRegistryCredentials({ url, username, password, workdir }) {
if (!username || !password) {
return null;
}
let decryptedPassword = (0, import_common.decrypt)(password);
const location = `${workdir}/.docker`;
try {
await import_fs.promises.mkdir(`${workdir}/.docker`);
} catch (error) {
}
const payload = JSON.stringify({
auths: {
[url]: {
auth: Buffer.from(`${username}:${decryptedPassword}`).toString("base64")
}
}
});
await import_fs.promises.writeFile(`${location}/config.json`, payload);
return location;
}
async function buildImage({
applicationId,
tag,
workdir,
buildId,
dockerId,
isCache = false,
debug = false,
dockerFileLocation = "/Dockerfile",
commit,
forceRebuild = false
}) {
if (isCache) {
await saveBuildLog({ line: `Building cache image...`, buildId, applicationId });
} else {
await saveBuildLog({ line: `Building production image...`, buildId, applicationId });
}
const dockerFile = isCache ? `${dockerFileLocation}-cache` : `${dockerFileLocation}`;
const cache = `${applicationId}:${tag}${isCache ? "-cache" : ""}`;
let location = null;
const { dockerRegistry } = await import_prisma.prisma.application.findUnique({
where: { id: applicationId },
select: { dockerRegistry: true }
});
if (dockerRegistry) {
const { url, username, password } = dockerRegistry;
location = await saveDockerRegistryCredentials({ url, username, password, workdir });
}
await (0, import_executeCommand.executeCommand)({
stream: true,
debug,
buildId,
applicationId,
dockerId,
command: `docker ${location ? `--config ${location}` : ""} build ${forceRebuild ? "--no-cache" : ""} --progress plain -f ${workdir}/${dockerFile} -t ${cache} --build-arg SOURCE_COMMIT=${commit} ${workdir}`
});
const { status } = await import_prisma.prisma.build.findUnique({ where: { id: buildId } });
if (status === "canceled") {
throw new Error("Canceled.");
}
}
function makeLabelForSimpleDockerfile({ applicationId, port, type }) {
return [
"coolify.managed=true",
`coolify.version=${import_common.version}`,
`coolify.applicationId=${applicationId}`,
`coolify.type=standalone-application`
];
}
function makeLabelForStandaloneApplication({
applicationId,
fqdn,
name,
type,
pullmergeRequestId = null,
buildPack,
repository,
branch,
projectId,
port,
commit,
installCommand,
buildCommand,
startCommand,
baseDirectory,
publishDirectory
}) {
if (pullmergeRequestId) {
const protocol = fqdn.startsWith("https://") ? "https" : "http";
const domain = (0, import_common.getDomain)(fqdn);
fqdn = `${protocol}://${pullmergeRequestId}.${domain}`;
}
return [
"coolify.managed=true",
`coolify.version=${import_common.version}`,
`coolify.applicationId=${applicationId}`,
`coolify.type=standalone-application`,
`coolify.name=${name}`,
`coolify.configuration=${(0, import_common.base64Encode)(
JSON.stringify({
applicationId,
fqdn,
name,
type,
pullmergeRequestId,
buildPack,
repository,
branch,
projectId,
port,
commit,
installCommand,
buildCommand,
startCommand,
baseDirectory,
publishDirectory
})
)}`
];
}
async function buildCacheImageWithNode(data, imageForBuild) {
const {
workdir,
buildId,
baseDirectory,
installCommand,
buildCommand,
secrets,
pullmergeRequestId
} = data;
const isPnpm = checkPnpm(installCommand, buildCommand);
const Dockerfile = [];
Dockerfile.push(`FROM ${imageForBuild}`);
Dockerfile.push("WORKDIR /app");
Dockerfile.push(`LABEL coolify.buildId=${buildId}`);
if (secrets.length > 0) {
(0, import_common.generateSecrets)(secrets, pullmergeRequestId, true).forEach((env) => {
Dockerfile.push(env);
});
}
if (isPnpm) {
Dockerfile.push("RUN curl -f https://get.pnpm.io/v6.16.js | node - add --global pnpm@7");
}
Dockerfile.push(`COPY .${baseDirectory || ""} ./`);
if (installCommand) {
Dockerfile.push(`RUN ${installCommand}`);
}
Dockerfile.push(`RUN ${buildCommand}`);
await import_fs.promises.writeFile(`${workdir}/Dockerfile-cache`, Dockerfile.join("\n"));
await buildImage({ ...data, isCache: true });
}
async function buildCacheImageForLaravel(data, imageForBuild) {
const { workdir, buildId, secrets, pullmergeRequestId } = data;
const Dockerfile = [];
Dockerfile.push(`FROM ${imageForBuild}`);
Dockerfile.push("WORKDIR /app");
Dockerfile.push(`LABEL coolify.buildId=${buildId}`);
if (secrets.length > 0) {
(0, import_common.generateSecrets)(secrets, pullmergeRequestId, true).forEach((env) => {
Dockerfile.push(env);
});
}
Dockerfile.push(`COPY *.json *.mix.js /app/`);
Dockerfile.push(`COPY resources /app/resources`);
Dockerfile.push(`RUN yarn install && yarn production`);
await import_fs.promises.writeFile(`${workdir}/Dockerfile-cache`, Dockerfile.join("\n"));
await buildImage({ ...data, isCache: true });
}
async function buildCacheImageWithCargo(data, imageForBuild) {
const { applicationId, workdir, buildId } = data;
const Dockerfile = [];
Dockerfile.push(`FROM ${imageForBuild} as planner-${applicationId}`);
Dockerfile.push(`LABEL coolify.buildId=${buildId}`);
Dockerfile.push("WORKDIR /app");
Dockerfile.push("RUN cargo install cargo-chef");
Dockerfile.push("COPY . .");
Dockerfile.push("RUN cargo chef prepare --recipe-path recipe.json");
Dockerfile.push(`FROM ${imageForBuild}`);
Dockerfile.push(`LABEL coolify.buildId=${buildId}`);
Dockerfile.push("WORKDIR /app");
Dockerfile.push("RUN cargo install cargo-chef");
Dockerfile.push(`COPY --from=planner-${applicationId} /app/recipe.json recipe.json`);
Dockerfile.push("RUN cargo chef cook --release --recipe-path recipe.json");
await import_fs.promises.writeFile(`${workdir}/Dockerfile-cache`, Dockerfile.join("\n"));
await buildImage({ ...data, isCache: true });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
buildCacheImageForLaravel,
buildCacheImageWithCargo,
buildCacheImageWithNode,
buildImage,
checkPnpm,
copyBaseConfigurationFiles,
makeLabelForSimpleDockerfile,
makeLabelForStandaloneApplication,
saveBuildLog,
saveDockerRegistryCredentials,
scanningTemplates,
setDefaultBaseImage,
setDefaultConfiguration
});

View File

@@ -0,0 +1,137 @@
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var compose_exports = {};
__export(compose_exports, {
default: () => compose_default
});
module.exports = __toCommonJS(compose_exports);
var import_fs = require("fs");
var import_common = require("../common");
var import_common2 = require("./common");
var import_js_yaml = __toESM(require("js-yaml"));
var import_docker = require("../docker");
var import_executeCommand = require("../executeCommand");
async function compose_default(data) {
let {
applicationId,
debug,
buildId,
dockerId,
network,
volumes,
labels,
workdir,
baseDirectory,
secrets,
pullmergeRequestId,
dockerComposeConfiguration,
dockerComposeFileLocation
} = data;
const fileYaml = `${workdir}${baseDirectory}${dockerComposeFileLocation}`;
const dockerComposeRaw = await import_fs.promises.readFile(fileYaml, "utf8");
const dockerComposeYaml = import_js_yaml.default.load(dockerComposeRaw);
if (!dockerComposeYaml.services) {
throw "No Services found in docker-compose file.";
}
let envs = [];
if (secrets.length > 0) {
envs = [...envs, ...(0, import_common.generateSecrets)(secrets, pullmergeRequestId, false, null)];
}
const composeVolumes = [];
if (volumes.length > 0) {
for (const volume of volumes) {
let [v, path] = volume.split(":");
composeVolumes[v] = {
name: v
};
}
}
let networks = {};
for (let [key, value] of Object.entries(dockerComposeYaml.services)) {
value["container_name"] = `${applicationId}-${key}`;
let environment = typeof value["environment"] === "undefined" ? [] : value["environment"];
value["environment"] = [...environment, ...envs];
value["labels"] = labels;
if (value["volumes"]?.length > 0) {
value["volumes"] = value["volumes"].map((volume) => {
let [v, path, permission] = volume.split(":");
if (!path) {
path = v;
v = `${applicationId}${v.replace(/\//gi, "-").replace(/\./gi, "")}`;
} else {
v = `${applicationId}${v.replace(/\//gi, "-").replace(/\./gi, "")}`;
}
composeVolumes[v] = {
name: v
};
return `${v}:${path}${permission ? ":" + permission : ""}`;
});
}
if (volumes.length > 0) {
for (const volume of volumes) {
value["volumes"].push(volume);
}
}
if (dockerComposeConfiguration[key].port) {
value["expose"] = [dockerComposeConfiguration[key].port];
}
if (value["networks"]?.length > 0) {
value["networks"].forEach((network2) => {
networks[network2] = {
name: network2
};
});
}
value["networks"] = [...value["networks"] || "", network];
dockerComposeYaml.services[key] = {
...dockerComposeYaml.services[key],
restart: (0, import_docker.defaultComposeConfiguration)(network).restart,
deploy: (0, import_docker.defaultComposeConfiguration)(network).deploy
};
}
if (Object.keys(composeVolumes).length > 0) {
dockerComposeYaml["volumes"] = { ...composeVolumes };
}
dockerComposeYaml["networks"] = Object.assign({ ...networks }, { [network]: { external: true } });
await import_fs.promises.writeFile(fileYaml, import_js_yaml.default.dump(dockerComposeYaml));
await (0, import_executeCommand.executeCommand)({
debug,
buildId,
applicationId,
dockerId,
command: `docker compose --project-directory ${workdir} pull`
});
await (0, import_common2.saveBuildLog)({ line: "Pulling images from Compose file...", buildId, applicationId });
await (0, import_executeCommand.executeCommand)({
debug,
buildId,
applicationId,
dockerId,
command: `docker compose --project-directory ${workdir} build --progress plain`
});
await (0, import_common2.saveBuildLog)({ line: "Building images from Compose file...", buildId, applicationId });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {});

View File

@@ -0,0 +1,74 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var deno_exports = {};
__export(deno_exports, {
default: () => deno_default
});
module.exports = __toCommonJS(deno_exports);
var import_fs = require("fs");
var import_common = require("../common");
var import_common2 = require("./common");
const createDockerfile = async (data, image) => {
const {
workdir,
port,
baseDirectory,
secrets,
pullmergeRequestId,
denoMainFile,
denoOptions,
buildId
} = data;
const Dockerfile = [];
let depsFound = false;
try {
await import_fs.promises.readFile(`${workdir}${baseDirectory || ""}/deps.ts`);
depsFound = true;
} catch (error) {
}
Dockerfile.push(`FROM ${image}`);
Dockerfile.push("WORKDIR /app");
Dockerfile.push(`LABEL coolify.buildId=${buildId}`);
if (secrets.length > 0) {
(0, import_common.generateSecrets)(secrets, pullmergeRequestId, true).forEach((env) => {
Dockerfile.push(env);
});
}
if (depsFound) {
Dockerfile.push(`COPY .${baseDirectory || ""}/deps.ts /app`);
Dockerfile.push(`RUN deno cache deps.ts`);
}
Dockerfile.push(`COPY .${baseDirectory || ""} ./`);
Dockerfile.push(`RUN deno cache ${denoMainFile}`);
Dockerfile.push(`ENV NO_COLOR true`);
Dockerfile.push(`EXPOSE ${port}`);
Dockerfile.push(`CMD deno run ${denoOptions || ""} ${denoMainFile}`);
await import_fs.promises.writeFile(`${workdir}/Dockerfile`, Dockerfile.join("\n"));
};
async function deno_default(data) {
try {
const { baseImage, baseBuildImage } = data;
await createDockerfile(data, baseImage);
await (0, import_common2.buildImage)(data);
} catch (error) {
throw error;
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {});

View File

@@ -0,0 +1,51 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var docker_exports = {};
__export(docker_exports, {
default: () => docker_default
});
module.exports = __toCommonJS(docker_exports);
var import_fs = require("fs");
var import_common = require("../common");
var import_common2 = require("./common");
async function docker_default(data) {
let { workdir, buildId, baseDirectory, secrets, pullmergeRequestId, dockerFileLocation } = data;
const file = `${workdir}${baseDirectory}${dockerFileLocation}`;
data.workdir = `${workdir}${baseDirectory}`;
const DockerfileRaw = await import_fs.promises.readFile(`${file}`, "utf8");
const Dockerfile = DockerfileRaw.toString().trim().split("\n");
Dockerfile.forEach((line, index) => {
if (line.startsWith("FROM")) {
Dockerfile.splice(index + 1, 0, `LABEL coolify.buildId=${buildId}`);
}
});
if (secrets.length > 0) {
(0, import_common.generateSecrets)(secrets, pullmergeRequestId, true).forEach((env) => {
Dockerfile.forEach((line, index) => {
if (line.startsWith("FROM")) {
Dockerfile.splice(index + 1, 0, env);
}
});
});
}
await import_fs.promises.writeFile(`${data.workdir}${dockerFileLocation}`, Dockerfile.join("\n"));
await (0, import_common2.buildImage)(data);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {});

View File

@@ -0,0 +1,50 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var gatsby_exports = {};
__export(gatsby_exports, {
default: () => gatsby_default
});
module.exports = __toCommonJS(gatsby_exports);
var import_fs = require("fs");
var import_common = require("./common");
const createDockerfile = async (data, imageforBuild) => {
const { applicationId, tag, workdir, publishDirectory, baseImage, buildId, port } = data;
const Dockerfile = [];
Dockerfile.push(`FROM ${imageforBuild}`);
Dockerfile.push("WORKDIR /app");
Dockerfile.push(`LABEL coolify.buildId=${buildId}`);
Dockerfile.push(`COPY --from=${applicationId}:${tag}-cache /app/${publishDirectory} ./`);
if (baseImage?.includes("nginx")) {
Dockerfile.push(`COPY /nginx.conf /etc/nginx/nginx.conf`);
}
Dockerfile.push(`EXPOSE ${port}`);
await import_fs.promises.writeFile(`${workdir}/Dockerfile`, Dockerfile.join("\n"));
};
async function gatsby_default(data) {
try {
const { baseImage, baseBuildImage } = data;
await (0, import_common.buildCacheImageWithNode)(data, baseBuildImage);
await createDockerfile(data, baseImage);
await (0, import_common.buildImage)(data);
} catch (error) {
throw error;
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {});

View File

@@ -0,0 +1,41 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var heroku_exports = {};
__export(heroku_exports, {
default: () => heroku_default
});
module.exports = __toCommonJS(heroku_exports);
var import_executeCommand = require("../executeCommand");
var import_common = require("./common");
async function heroku_default(data) {
const { buildId, applicationId, tag, dockerId, debug, workdir, baseDirectory, baseImage } = data;
try {
await (0, import_common.saveBuildLog)({ line: `Building production image...`, buildId, applicationId });
await (0, import_executeCommand.executeCommand)({
buildId,
debug,
dockerId,
command: `pack build -p ${workdir}${baseDirectory} ${applicationId}:${tag} --builder ${baseImage}`
});
} catch (error) {
throw error;
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {});

View File

@@ -0,0 +1,88 @@
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var buildPacks_exports = {};
__export(buildPacks_exports, {
astro: () => import_static2.default,
compose: () => import_compose.default,
deno: () => import_deno.default,
docker: () => import_docker.default,
eleventy: () => import_static3.default,
gatsby: () => import_gatsby.default,
heroku: () => import_heroku.default,
laravel: () => import_laravel.default,
nestjs: () => import_nestjs.default,
nextjs: () => import_nextjs.default,
node: () => import_node.default,
nuxtjs: () => import_nuxtjs.default,
php: () => import_php.default,
python: () => import_python.default,
react: () => import_react.default,
rust: () => import_rust.default,
staticApp: () => import_static.default,
svelte: () => import_svelte.default,
vuejs: () => import_vuejs.default
});
module.exports = __toCommonJS(buildPacks_exports);
var import_node = __toESM(require("./node"));
var import_static = __toESM(require("./static"));
var import_docker = __toESM(require("./docker"));
var import_gatsby = __toESM(require("./gatsby"));
var import_svelte = __toESM(require("./svelte"));
var import_react = __toESM(require("./react"));
var import_nestjs = __toESM(require("./nestjs"));
var import_nextjs = __toESM(require("./nextjs"));
var import_nuxtjs = __toESM(require("./nuxtjs"));
var import_vuejs = __toESM(require("./vuejs"));
var import_php = __toESM(require("./php"));
var import_rust = __toESM(require("./rust"));
var import_static2 = __toESM(require("./static"));
var import_static3 = __toESM(require("./static"));
var import_python = __toESM(require("./python"));
var import_deno = __toESM(require("./deno"));
var import_laravel = __toESM(require("./laravel"));
var import_heroku = __toESM(require("./heroku"));
var import_compose = __toESM(require("./compose"));
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
astro,
compose,
deno,
docker,
eleventy,
gatsby,
heroku,
laravel,
nestjs,
nextjs,
node,
nuxtjs,
php,
python,
react,
rust,
staticApp,
svelte,
vuejs
});

View File

@@ -0,0 +1,68 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var laravel_exports = {};
__export(laravel_exports, {
default: () => laravel_default
});
module.exports = __toCommonJS(laravel_exports);
var import_fs = require("fs");
var import_common = require("../common");
var import_common2 = require("./common");
const createDockerfile = async (data, image) => {
const { workdir, applicationId, tag, buildId, port, secrets, pullmergeRequestId } = data;
const Dockerfile = [];
Dockerfile.push(`FROM ${image}`);
Dockerfile.push(`LABEL coolify.buildId=${buildId}`);
if (secrets.length > 0) {
(0, import_common.generateSecrets)(secrets, pullmergeRequestId, true).forEach((env) => {
Dockerfile.push(env);
});
}
Dockerfile.push("WORKDIR /app");
Dockerfile.push(`ENV WEB_DOCUMENT_ROOT /app/public`);
Dockerfile.push(`COPY --chown=application:application composer.* ./`);
Dockerfile.push(`COPY --chown=application:application database/ database/`);
Dockerfile.push(
`RUN composer install --ignore-platform-reqs --no-interaction --no-plugins --no-scripts --prefer-dist`
);
Dockerfile.push(
`COPY --chown=application:application --from=${applicationId}:${tag}-cache /app/public/js/ /app/public/js/`
);
Dockerfile.push(
`COPY --chown=application:application --from=${applicationId}:${tag}-cache /app/public/css/ /app/public/css/`
);
Dockerfile.push(
`COPY --chown=application:application --from=${applicationId}:${tag}-cache /app/mix-manifest.json /app/public/mix-manifest.json`
);
Dockerfile.push(`COPY --chown=application:application . ./`);
Dockerfile.push(`EXPOSE ${port}`);
await import_fs.promises.writeFile(`${workdir}/Dockerfile`, Dockerfile.join("\n"));
};
async function laravel_default(data) {
const { baseImage, baseBuildImage } = data;
try {
await (0, import_common2.buildCacheImageForLaravel)(data, baseBuildImage);
await createDockerfile(data, baseImage);
await (0, import_common2.buildImage)(data);
} catch (error) {
throw error;
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {});

View File

@@ -0,0 +1,52 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var nestjs_exports = {};
__export(nestjs_exports, {
default: () => nestjs_default
});
module.exports = __toCommonJS(nestjs_exports);
var import_fs = require("fs");
var import_common = require("./common");
const createDockerfile = async (data, image) => {
const { buildId, applicationId, tag, port, startCommand, workdir, baseDirectory } = data;
const Dockerfile = [];
const isPnpm = startCommand.includes("pnpm");
Dockerfile.push(`FROM ${image}`);
Dockerfile.push("WORKDIR /app");
Dockerfile.push(`LABEL coolify.buildId=${buildId}`);
if (isPnpm) {
Dockerfile.push("RUN curl -f https://get.pnpm.io/v6.16.js | node - add --global pnpm@7");
}
Dockerfile.push(`COPY --from=${applicationId}:${tag}-cache /app/${baseDirectory || ""} ./`);
Dockerfile.push(`EXPOSE ${port}`);
Dockerfile.push(`CMD ${startCommand}`);
await import_fs.promises.writeFile(`${workdir}/Dockerfile`, Dockerfile.join("\n"));
};
async function nestjs_default(data) {
try {
const { baseImage, baseBuildImage } = data;
await (0, import_common.buildCacheImageWithNode)(data, baseBuildImage);
await createDockerfile(data, baseImage);
await (0, import_common.buildImage)(data);
} catch (error) {
throw error;
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {});

View File

@@ -0,0 +1,89 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var nextjs_exports = {};
__export(nextjs_exports, {
default: () => nextjs_default
});
module.exports = __toCommonJS(nextjs_exports);
var import_fs = require("fs");
var import_common = require("../common");
var import_common2 = require("./common");
const createDockerfile = async (data, image) => {
const {
applicationId,
buildId,
tag,
workdir,
publishDirectory,
port,
installCommand,
buildCommand,
startCommand,
baseDirectory,
secrets,
pullmergeRequestId,
deploymentType,
baseImage
} = data;
const Dockerfile = [];
const isPnpm = (0, import_common2.checkPnpm)(installCommand, buildCommand, startCommand);
Dockerfile.push(`FROM ${image}`);
Dockerfile.push("WORKDIR /app");
Dockerfile.push(`LABEL coolify.buildId=${buildId}`);
if (secrets.length > 0) {
(0, import_common.generateSecrets)(secrets, pullmergeRequestId, true).forEach((env) => {
Dockerfile.push(env);
});
}
if (isPnpm) {
Dockerfile.push("RUN curl -f https://get.pnpm.io/v6.16.js | node - add --global pnpm@7");
}
if (deploymentType === "node") {
Dockerfile.push(`COPY .${baseDirectory || ""} ./`);
Dockerfile.push(`RUN ${installCommand}`);
Dockerfile.push(`RUN ${buildCommand}`);
Dockerfile.push(`EXPOSE ${port}`);
Dockerfile.push(`CMD ${startCommand}`);
} else if (deploymentType === "static") {
if (baseImage?.includes("nginx")) {
Dockerfile.push(`COPY /nginx.conf /etc/nginx/nginx.conf`);
}
Dockerfile.push(`COPY --from=${applicationId}:${tag}-cache /app/${publishDirectory} ./`);
Dockerfile.push(`EXPOSE 80`);
}
await import_fs.promises.writeFile(`${workdir}/Dockerfile`, Dockerfile.join("\n"));
};
async function nextjs_default(data) {
try {
const { baseImage, baseBuildImage, deploymentType, buildCommand } = data;
if (deploymentType === "node") {
await createDockerfile(data, baseImage);
await (0, import_common2.buildImage)(data);
} else if (deploymentType === "static") {
if (buildCommand)
await (0, import_common2.buildCacheImageWithNode)(data, baseBuildImage);
await createDockerfile(data, baseImage);
await (0, import_common2.buildImage)(data);
}
} catch (error) {
throw error;
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {});

View File

@@ -0,0 +1,71 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var node_exports = {};
__export(node_exports, {
default: () => node_default
});
module.exports = __toCommonJS(node_exports);
var import_fs = require("fs");
var import_common = require("../common");
var import_common2 = require("./common");
const createDockerfile = async (data, image) => {
const {
workdir,
port,
installCommand,
buildCommand,
startCommand,
baseDirectory,
secrets,
pullmergeRequestId,
buildId
} = data;
const Dockerfile = [];
const isPnpm = (0, import_common2.checkPnpm)(installCommand, buildCommand, startCommand);
Dockerfile.push(`FROM ${image}`);
Dockerfile.push("WORKDIR /app");
Dockerfile.push(`LABEL coolify.buildId=${buildId}`);
if (secrets.length > 0) {
(0, import_common.generateSecrets)(secrets, pullmergeRequestId, true).forEach((env) => {
Dockerfile.push(env);
});
}
if (isPnpm) {
Dockerfile.push("RUN curl -f https://get.pnpm.io/v6.16.js | node - add --global pnpm@7");
}
Dockerfile.push(`COPY .${baseDirectory || ""} ./`);
Dockerfile.push(`RUN ${installCommand}`);
if (buildCommand) {
Dockerfile.push(`RUN ${buildCommand}`);
}
Dockerfile.push(`EXPOSE ${port}`);
Dockerfile.push(`CMD ${startCommand}`);
await import_fs.promises.writeFile(`${workdir}/Dockerfile`, Dockerfile.join("\n"));
};
async function node_default(data) {
try {
const { baseImage } = data;
await createDockerfile(data, baseImage);
await (0, import_common2.buildImage)(data);
} catch (error) {
throw error;
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {});

View File

@@ -0,0 +1,89 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var nuxtjs_exports = {};
__export(nuxtjs_exports, {
default: () => nuxtjs_default
});
module.exports = __toCommonJS(nuxtjs_exports);
var import_fs = require("fs");
var import_common = require("../common");
var import_common2 = require("./common");
const createDockerfile = async (data, image) => {
const {
applicationId,
buildId,
tag,
workdir,
publishDirectory,
port,
installCommand,
buildCommand,
startCommand,
baseDirectory,
secrets,
pullmergeRequestId,
deploymentType,
baseImage
} = data;
const Dockerfile = [];
const isPnpm = (0, import_common2.checkPnpm)(installCommand, buildCommand, startCommand);
Dockerfile.push(`FROM ${image}`);
Dockerfile.push("WORKDIR /app");
Dockerfile.push(`LABEL coolify.buildId=${buildId}`);
if (secrets.length > 0) {
(0, import_common.generateSecrets)(secrets, pullmergeRequestId, true).forEach((env) => {
Dockerfile.push(env);
});
}
if (isPnpm) {
Dockerfile.push("RUN curl -f https://get.pnpm.io/v6.16.js | node - add --global pnpm@7");
}
if (deploymentType === "node") {
Dockerfile.push(`COPY .${baseDirectory || ""} ./`);
Dockerfile.push(`RUN ${installCommand}`);
Dockerfile.push(`RUN ${buildCommand}`);
Dockerfile.push(`EXPOSE ${port}`);
Dockerfile.push(`CMD ${startCommand}`);
} else if (deploymentType === "static") {
if (baseImage?.includes("nginx")) {
Dockerfile.push(`COPY /nginx.conf /etc/nginx/nginx.conf`);
}
Dockerfile.push(`COPY --from=${applicationId}:${tag}-cache /app/${publishDirectory} ./`);
Dockerfile.push(`EXPOSE 80`);
}
await import_fs.promises.writeFile(`${workdir}/Dockerfile`, Dockerfile.join("\n"));
};
async function nuxtjs_default(data) {
try {
const { baseImage, baseBuildImage, deploymentType, buildCommand } = data;
if (deploymentType === "node") {
await createDockerfile(data, baseImage);
await (0, import_common2.buildImage)(data);
} else if (deploymentType === "static") {
if (buildCommand)
await (0, import_common2.buildCacheImageWithNode)(data, baseBuildImage);
await createDockerfile(data, baseImage);
await (0, import_common2.buildImage)(data);
}
} catch (error) {
throw error;
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {});

View File

@@ -0,0 +1,71 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var php_exports = {};
__export(php_exports, {
default: () => php_default
});
module.exports = __toCommonJS(php_exports);
var import_fs = require("fs");
var import_common = require("../common");
var import_common2 = require("./common");
const createDockerfile = async (data, image, htaccessFound) => {
const { workdir, baseDirectory, buildId, port, secrets, pullmergeRequestId } = data;
const Dockerfile = [];
let composerFound = false;
try {
await import_fs.promises.readFile(`${workdir}${baseDirectory || ""}/composer.json`);
composerFound = true;
} catch (error) {
}
Dockerfile.push(`FROM ${image}`);
Dockerfile.push(`LABEL coolify.buildId=${buildId}`);
if (secrets.length > 0) {
(0, import_common.generateSecrets)(secrets, pullmergeRequestId, true).forEach((env) => {
Dockerfile.push(env);
});
}
Dockerfile.push("WORKDIR /app");
Dockerfile.push(`COPY .${baseDirectory || ""} /app`);
if (htaccessFound) {
Dockerfile.push(`COPY .${baseDirectory || ""}/.htaccess ./`);
}
if (composerFound) {
Dockerfile.push(`RUN composer install`);
}
Dockerfile.push(`COPY /entrypoint.sh /opt/docker/provision/entrypoint.d/30-entrypoint.sh`);
Dockerfile.push(`EXPOSE ${port}`);
await import_fs.promises.writeFile(`${workdir}/Dockerfile`, Dockerfile.join("\n"));
};
async function php_default(data) {
const { workdir, baseDirectory, baseImage } = data;
try {
let htaccessFound = false;
try {
await import_fs.promises.readFile(`${workdir}${baseDirectory || ""}/.htaccess`);
htaccessFound = true;
} catch (e) {
}
await createDockerfile(data, baseImage, htaccessFound);
await (0, import_common2.buildImage)(data);
} catch (error) {
throw error;
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {});

View File

@@ -0,0 +1,86 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var python_exports = {};
__export(python_exports, {
default: () => python_default
});
module.exports = __toCommonJS(python_exports);
var import_fs = require("fs");
var import_common = require("../common");
var import_common2 = require("./common");
const createDockerfile = async (data, image) => {
const {
workdir,
port,
baseDirectory,
secrets,
pullmergeRequestId,
pythonWSGI,
pythonModule,
pythonVariable,
buildId
} = data;
const Dockerfile = [];
Dockerfile.push(`FROM ${image}`);
Dockerfile.push("WORKDIR /app");
Dockerfile.push(`LABEL coolify.buildId=${buildId}`);
if (secrets.length > 0) {
(0, import_common.generateSecrets)(secrets, pullmergeRequestId, true).forEach((env) => {
Dockerfile.push(env);
});
}
if (pythonWSGI?.toLowerCase() === "gunicorn") {
Dockerfile.push(`RUN pip install gunicorn`);
} else if (pythonWSGI?.toLowerCase() === "uvicorn") {
Dockerfile.push(`RUN pip install uvicorn`);
} else if (pythonWSGI?.toLowerCase() === "uwsgi") {
Dockerfile.push(`RUN apk add --no-cache uwsgi-python3`);
}
try {
await import_fs.promises.stat(`${workdir}${baseDirectory || ""}/requirements.txt`);
Dockerfile.push(`COPY .${baseDirectory || ""}/requirements.txt ./`);
Dockerfile.push(`RUN pip install --no-cache-dir -r .${baseDirectory || ""}/requirements.txt`);
} catch (e) {
}
Dockerfile.push(`COPY .${baseDirectory || ""} ./`);
Dockerfile.push(`EXPOSE ${port}`);
if (pythonWSGI?.toLowerCase() === "gunicorn") {
Dockerfile.push(`CMD gunicorn -w=4 -b=0.0.0.0:8000 ${pythonModule}:${pythonVariable}`);
} else if (pythonWSGI?.toLowerCase() === "uvicorn") {
Dockerfile.push(`CMD uvicorn ${pythonModule}:${pythonVariable} --port ${port} --host 0.0.0.0`);
} else if (pythonWSGI?.toLowerCase() === "uwsgi") {
Dockerfile.push(
`CMD uwsgi --master -p 4 --http-socket 0.0.0.0:8000 --uid uwsgi --plugins python3 --protocol uwsgi --wsgi ${pythonModule}:${pythonVariable}`
);
} else {
Dockerfile.push(`CMD python ${pythonModule}`);
}
await import_fs.promises.writeFile(`${workdir}/Dockerfile`, Dockerfile.join("\n"));
};
async function python_default(data) {
try {
const { baseImage, baseBuildImage } = data;
await createDockerfile(data, baseImage);
await (0, import_common2.buildImage)(data);
} catch (error) {
throw error;
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {});

View File

@@ -0,0 +1,50 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var react_exports = {};
__export(react_exports, {
default: () => react_default
});
module.exports = __toCommonJS(react_exports);
var import_fs = require("fs");
var import_common = require("./common");
const createDockerfile = async (data, image) => {
const { applicationId, tag, workdir, publishDirectory, baseImage, buildId, port } = data;
const Dockerfile = [];
Dockerfile.push(`FROM ${image}`);
Dockerfile.push(`LABEL coolify.buildId=${buildId}`);
Dockerfile.push("WORKDIR /app");
Dockerfile.push(`COPY --from=${applicationId}:${tag}-cache /app/${publishDirectory} ./`);
if (baseImage?.includes("nginx")) {
Dockerfile.push(`COPY /nginx.conf /etc/nginx/nginx.conf`);
}
Dockerfile.push(`EXPOSE ${port}`);
await import_fs.promises.writeFile(`${workdir}/Dockerfile`, Dockerfile.join("\n"));
};
async function react_default(data) {
try {
const { baseImage, baseBuildImage } = data;
await (0, import_common.buildCacheImageWithNode)(data, baseBuildImage);
await createDockerfile(data, baseImage);
await (0, import_common.buildImage)(data);
} catch (error) {
throw error;
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {});

View File

@@ -0,0 +1,69 @@
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var rust_exports = {};
__export(rust_exports, {
default: () => rust_default
});
module.exports = __toCommonJS(rust_exports);
var import_fs = require("fs");
var import_toml = __toESM(require("@iarna/toml"));
var import_common = require("./common");
var import_executeCommand = require("../executeCommand");
const createDockerfile = async (data, image, name) => {
const { workdir, port, applicationId, tag, buildId } = data;
const Dockerfile = [];
Dockerfile.push(`FROM ${image}`);
Dockerfile.push("WORKDIR /app");
Dockerfile.push(`LABEL coolify.buildId=${buildId}`);
Dockerfile.push(`COPY --from=${applicationId}:${tag}-cache /app/target target`);
Dockerfile.push(`COPY --from=${applicationId}:${tag}-cache /usr/local/cargo /usr/local/cargo`);
Dockerfile.push(`COPY . .`);
Dockerfile.push(`RUN cargo build --release --bin ${name}`);
Dockerfile.push("FROM debian:buster-slim");
Dockerfile.push("WORKDIR /app");
Dockerfile.push(
`RUN apt-get update -y && apt-get install -y --no-install-recommends openssl libcurl4 ca-certificates && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/*`
);
Dockerfile.push(`RUN update-ca-certificates`);
Dockerfile.push(`COPY --from=${applicationId}:${tag}-cache /app/target/release/${name} ${name}`);
Dockerfile.push(`EXPOSE ${port}`);
Dockerfile.push(`CMD ["/app/${name}"]`);
await import_fs.promises.writeFile(`${workdir}/Dockerfile`, Dockerfile.join("\n"));
};
async function rust_default(data) {
try {
const { workdir, baseImage, baseBuildImage } = data;
const { stdout: cargoToml } = await (0, import_executeCommand.executeCommand)({ command: `cat ${workdir}/Cargo.toml` });
const parsedToml = import_toml.default.parse(cargoToml);
const name = parsedToml.package.name;
await (0, import_common.buildCacheImageWithCargo)(data, baseBuildImage);
await createDockerfile(data, baseImage, name);
await (0, import_common.buildImage)(data);
} catch (error) {
throw error;
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {});

View File

@@ -0,0 +1,77 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var static_exports = {};
__export(static_exports, {
default: () => static_default
});
module.exports = __toCommonJS(static_exports);
var import_fs = require("fs");
var import_common = require("../common");
var import_common2 = require("./common");
const createDockerfile = async (data, image) => {
const {
applicationId,
tag,
workdir,
buildCommand,
baseDirectory,
publishDirectory,
secrets,
pullmergeRequestId,
baseImage,
buildId,
port
} = data;
const Dockerfile = [];
Dockerfile.push(`FROM ${image}`);
if (baseImage?.includes("httpd")) {
Dockerfile.push("WORKDIR /usr/local/apache2/htdocs/");
} else {
Dockerfile.push("WORKDIR /app");
}
Dockerfile.push(`LABEL coolify.buildId=${buildId}`);
if (secrets.length > 0) {
(0, import_common.generateSecrets)(secrets, pullmergeRequestId, true).forEach((env) => {
Dockerfile.push(env);
});
}
if (buildCommand) {
Dockerfile.push(`COPY --from=${applicationId}:${tag}-cache /app/${publishDirectory} ./`);
} else {
Dockerfile.push(`COPY .${baseDirectory || ""} ./`);
}
if (baseImage?.includes("nginx")) {
Dockerfile.push(`COPY /nginx.conf /etc/nginx/nginx.conf`);
}
Dockerfile.push(`EXPOSE ${port}`);
await import_fs.promises.writeFile(`${workdir}/Dockerfile`, Dockerfile.join("\n"));
};
async function static_default(data) {
try {
const { baseImage, baseBuildImage } = data;
if (data.buildCommand)
await (0, import_common2.buildCacheImageWithNode)(data, baseBuildImage);
await createDockerfile(data, baseImage);
await (0, import_common2.buildImage)(data);
} catch (error) {
throw error;
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {});

View File

@@ -0,0 +1,50 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var svelte_exports = {};
__export(svelte_exports, {
default: () => svelte_default
});
module.exports = __toCommonJS(svelte_exports);
var import_fs = require("fs");
var import_common = require("./common");
const createDockerfile = async (data, image) => {
const { applicationId, tag, workdir, publishDirectory, baseImage, buildId, port } = data;
const Dockerfile = [];
Dockerfile.push(`FROM ${image}`);
Dockerfile.push("WORKDIR /app");
Dockerfile.push(`LABEL coolify.buildId=${buildId}`);
Dockerfile.push(`COPY --from=${applicationId}:${tag}-cache /app/${publishDirectory} ./`);
if (baseImage?.includes("nginx")) {
Dockerfile.push(`COPY /nginx.conf /etc/nginx/nginx.conf`);
}
Dockerfile.push(`EXPOSE ${port}`);
await import_fs.promises.writeFile(`${workdir}/Dockerfile`, Dockerfile.join("\n"));
};
async function svelte_default(data) {
try {
const { baseImage, baseBuildImage } = data;
await (0, import_common.buildCacheImageWithNode)(data, baseBuildImage);
await createDockerfile(data, baseImage);
await (0, import_common.buildImage)(data);
} catch (error) {
throw error;
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {});

View File

@@ -0,0 +1,50 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var vuejs_exports = {};
__export(vuejs_exports, {
default: () => vuejs_default
});
module.exports = __toCommonJS(vuejs_exports);
var import_fs = require("fs");
var import_common = require("./common");
const createDockerfile = async (data, image) => {
const { applicationId, tag, workdir, publishDirectory, baseImage, buildId, port } = data;
const Dockerfile = [];
Dockerfile.push(`FROM ${image}`);
Dockerfile.push("WORKDIR /app");
Dockerfile.push(`LABEL coolify.buildId=${buildId}`);
Dockerfile.push(`COPY --from=${applicationId}:${tag}-cache /app/${publishDirectory} ./`);
if (baseImage?.includes("nginx")) {
Dockerfile.push(`COPY /nginx.conf /etc/nginx/nginx.conf`);
}
Dockerfile.push(`EXPOSE ${port}`);
await import_fs.promises.writeFile(`${workdir}/Dockerfile`, Dockerfile.join("\n"));
};
async function vuejs_default(data) {
try {
const { baseImage, baseBuildImage } = data;
await (0, import_common.buildCacheImageWithNode)(data, baseBuildImage);
await createDockerfile(data, baseImage);
await (0, import_common.buildImage)(data);
} catch (error) {
throw error;
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {});

View File

@@ -0,0 +1,952 @@
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var common_exports = {};
__export(common_exports, {
asyncSleep: () => asyncSleep,
base64Decode: () => base64Decode,
base64Encode: () => base64Encode,
checkDomainsIsValidInDNS: () => checkDomainsIsValidInDNS,
checkExposedPort: () => checkExposedPort,
cleanupDB: () => cleanupDB,
comparePassword: () => comparePassword,
configureNetworkTraefikProxy: () => configureNetworkTraefikProxy,
createDirectories: () => createDirectories,
decrypt: () => decrypt,
decryptApplication: () => decryptApplication,
defaultTraefikImage: () => defaultTraefikImage,
encrypt: () => encrypt,
fixType: () => fixType,
generateRangeArray: () => generateRangeArray,
generateSecrets: () => generateSecrets,
generateTimestamp: () => generateTimestamp,
getAPIUrl: () => getAPIUrl,
getContainerUsage: () => getContainerUsage,
getCurrentUser: () => getCurrentUser,
getDomain: () => getDomain,
getFreeExposedPort: () => getFreeExposedPort,
getTags: () => getTags,
getTeamInvitation: () => getTeamInvitation,
getTemplates: () => getTemplates,
getUIUrl: () => getUIUrl,
hashPassword: () => hashPassword,
isARM: () => isARM,
isDev: () => isDev,
isDomainConfigured: () => isDomainConfigured,
listSettings: () => listSettings,
makeLabelForServices: () => makeLabelForServices,
pushToRegistry: () => pushToRegistry,
removeService: () => removeService,
saveDockerRegistryCredentials: () => saveDockerRegistryCredentials,
scanningTemplates: () => scanningTemplates,
sentryDSN: () => sentryDSN,
setDefaultConfiguration: () => setDefaultConfiguration,
startTraefikProxy: () => startTraefikProxy,
startTraefikTCPProxy: () => startTraefikTCPProxy,
stopTraefikProxy: () => stopTraefikProxy,
uniqueName: () => uniqueName,
version: () => version
});
module.exports = __toCommonJS(common_exports);
var import_prisma = require("../prisma");
var import_bcryptjs = __toESM(require("bcryptjs"));
var import_crypto = __toESM(require("crypto"));
var import_dns = require("dns");
var import_promises = __toESM(require("fs/promises"));
var import_unique_names_generator = require("unique-names-generator");
var import_env = require("../env");
var import_dayjs = require("./dayjs");
var import_executeCommand = require("./executeCommand");
var import_logging = require("./logging");
var import_docker = require("./docker");
var import_js_yaml = __toESM(require("js-yaml"));
const customConfig = {
dictionaries: [import_unique_names_generator.adjectives, import_unique_names_generator.colors, import_unique_names_generator.animals],
style: "capital",
separator: " ",
length: 3
};
const algorithm = "aes-256-ctr";
const isDev = import_env.env.NODE_ENV === "development";
const version = "3.13.0";
const sentryDSN = "https://409f09bcb7af47928d3e0f46b78987f3@o1082494.ingest.sentry.io/4504236622217216";
const defaultTraefikImage = `traefik:v2.8`;
function getAPIUrl() {
if (process.env.GITPOD_WORKSPACE_URL) {
const { href } = new URL(process.env.GITPOD_WORKSPACE_URL);
const newURL = href.replace("https://", "https://3001-").replace(/\/$/, "");
return newURL;
}
if (process.env.CODESANDBOX_HOST) {
return `https://${process.env.CODESANDBOX_HOST.replace(/\$PORT/, "3001")}`;
}
return isDev ? "http://host.docker.internal:3001" : "http://localhost:3000";
}
function getUIUrl() {
if (process.env.GITPOD_WORKSPACE_URL) {
const { href } = new URL(process.env.GITPOD_WORKSPACE_URL);
const newURL = href.replace("https://", "https://3000-").replace(/\/$/, "");
return newURL;
}
if (process.env.CODESANDBOX_HOST) {
return `https://${process.env.CODESANDBOX_HOST.replace(/\$PORT/, "3000")}`;
}
return "http://localhost:3000";
}
const mainTraefikEndpoint = isDev ? `${getAPIUrl()}/webhooks/traefik/main.json` : "http://coolify:3000/webhooks/traefik/main.json";
const otherTraefikEndpoint = isDev ? `${getAPIUrl()}/webhooks/traefik/other.json` : "http://coolify:3000/webhooks/traefik/other.json";
async function listSettings() {
return await import_prisma.prisma.setting.findUnique({ where: { id: "0" } });
}
async function getCurrentUser(userId) {
return await import_prisma.prisma.user.findUnique({
where: { id: userId },
include: { teams: true, permission: true }
});
}
async function getTeamInvitation(userId) {
return await import_prisma.prisma.teamInvitation.findMany({ where: { uid: userId } });
}
async function hashPassword(password) {
const saltRounds = 15;
return import_bcryptjs.default.hash(password, saltRounds);
}
async function comparePassword(password, hashedPassword) {
return import_bcryptjs.default.compare(password, hashedPassword);
}
const uniqueName = () => (0, import_unique_names_generator.uniqueNamesGenerator)(customConfig);
const decrypt = (hashString) => {
if (hashString) {
try {
const hash = JSON.parse(hashString);
const decipher = import_crypto.default.createDecipheriv(
algorithm,
import_env.env.COOLIFY_SECRET_KEY,
Buffer.from(hash.iv, "hex")
);
const decrpyted = Buffer.concat([
decipher.update(Buffer.from(hash.content, "hex")),
decipher.final()
]);
return decrpyted.toString();
} catch (error) {
if (error instanceof Error) {
console.log({ decryptionError: error.message });
}
return hashString;
}
}
return false;
};
function generateRangeArray(start, end) {
return Array.from({ length: end - start }, (_v, k) => k + start);
}
function generateTimestamp() {
return `${(0, import_dayjs.day)().format("HH:mm:ss.SSS")}`;
}
const encrypt = (text) => {
if (text) {
const iv = import_crypto.default.randomBytes(16);
const cipher = import_crypto.default.createCipheriv(algorithm, import_env.env.COOLIFY_SECRET_KEY, iv);
const encrypted = Buffer.concat([cipher.update(text.trim()), cipher.final()]);
return JSON.stringify({
iv: iv.toString("hex"),
content: encrypted.toString("hex")
});
}
return false;
};
async function getTemplates() {
const templatePath = isDev ? "./templates.json" : "/app/templates.json";
const open = await import_promises.default.open(templatePath, "r");
try {
let data = await open.readFile({ encoding: "utf-8" });
let jsonData = JSON.parse(data);
if (isARM(process.arch)) {
jsonData = jsonData.filter((d) => d.arch !== "amd64");
}
return jsonData;
} catch (error) {
return [];
} finally {
await open?.close();
}
}
function isARM(arch) {
if (arch === "arm" || arch === "arm64" || arch === "aarch" || arch === "aarch64") {
return true;
}
return false;
}
async function removeService({ id }) {
await import_prisma.prisma.serviceSecret.deleteMany({ where: { serviceId: id } });
await import_prisma.prisma.serviceSetting.deleteMany({ where: { serviceId: id } });
await import_prisma.prisma.servicePersistentStorage.deleteMany({ where: { serviceId: id } });
await import_prisma.prisma.meiliSearch.deleteMany({ where: { serviceId: id } });
await import_prisma.prisma.fider.deleteMany({ where: { serviceId: id } });
await import_prisma.prisma.ghost.deleteMany({ where: { serviceId: id } });
await import_prisma.prisma.umami.deleteMany({ where: { serviceId: id } });
await import_prisma.prisma.hasura.deleteMany({ where: { serviceId: id } });
await import_prisma.prisma.plausibleAnalytics.deleteMany({ where: { serviceId: id } });
await import_prisma.prisma.minio.deleteMany({ where: { serviceId: id } });
await import_prisma.prisma.vscodeserver.deleteMany({ where: { serviceId: id } });
await import_prisma.prisma.wordpress.deleteMany({ where: { serviceId: id } });
await import_prisma.prisma.glitchTip.deleteMany({ where: { serviceId: id } });
await import_prisma.prisma.moodle.deleteMany({ where: { serviceId: id } });
await import_prisma.prisma.appwrite.deleteMany({ where: { serviceId: id } });
await import_prisma.prisma.searxng.deleteMany({ where: { serviceId: id } });
await import_prisma.prisma.weblate.deleteMany({ where: { serviceId: id } });
await import_prisma.prisma.taiga.deleteMany({ where: { serviceId: id } });
await import_prisma.prisma.service.delete({ where: { id } });
}
const createDirectories = async ({
repository,
buildId
}) => {
if (repository)
repository = repository.replaceAll(" ", "");
const repodir = `/tmp/build-sources/${repository}/`;
const workdir = `/tmp/build-sources/${repository}/${buildId}`;
let workdirFound = false;
try {
workdirFound = !!await import_promises.default.stat(workdir);
} catch (error) {
}
if (workdirFound) {
await (0, import_executeCommand.executeCommand)({ command: `rm -fr ${workdir}` });
}
await (0, import_executeCommand.executeCommand)({ command: `mkdir -p ${workdir}` });
return {
workdir,
repodir
};
};
async function saveDockerRegistryCredentials({ url, username, password, workdir }) {
if (!username || !password) {
return null;
}
let decryptedPassword = decrypt(password);
const location = `${workdir}/.docker`;
try {
await import_promises.default.mkdir(`${workdir}/.docker`);
} catch (error) {
console.log(error);
}
const payload = JSON.stringify({
auths: {
[url]: {
auth: Buffer.from(`${username}:${decryptedPassword}`).toString("base64")
}
}
});
await import_promises.default.writeFile(`${location}/config.json`, payload);
return location;
}
function getDomain(domain) {
if (domain) {
return domain?.replace("https://", "").replace("http://", "");
} else {
return "";
}
}
async function isDomainConfigured({
id,
fqdn,
checkOwn = false,
remoteIpAddress = void 0
}) {
const domain = getDomain(fqdn);
const nakedDomain = domain.replace("www.", "");
const foundApp = await import_prisma.prisma.application.findFirst({
where: {
OR: [
{ fqdn: { endsWith: `//${nakedDomain}` } },
{ fqdn: { endsWith: `//www.${nakedDomain}` } },
{ dockerComposeConfiguration: { contains: `//${nakedDomain}` } },
{ dockerComposeConfiguration: { contains: `//www.${nakedDomain}` } }
],
id: { not: id },
destinationDocker: {
remoteIpAddress
}
},
select: { fqdn: true }
});
const foundService = await import_prisma.prisma.service.findFirst({
where: {
OR: [
{ fqdn: { endsWith: `//${nakedDomain}` } },
{ fqdn: { endsWith: `//www.${nakedDomain}` } }
],
id: { not: checkOwn ? void 0 : id },
destinationDocker: {
remoteIpAddress
}
},
select: { fqdn: true }
});
const coolifyFqdn = await import_prisma.prisma.setting.findFirst({
where: {
OR: [
{ fqdn: { endsWith: `//${nakedDomain}` } },
{ fqdn: { endsWith: `//www.${nakedDomain}` } }
],
id: { not: id }
},
select: { fqdn: true }
});
return !!(foundApp || foundService || coolifyFqdn);
}
async function checkExposedPort({
id,
configuredPort,
exposePort,
engine,
remoteEngine,
remoteIpAddress
}) {
if (exposePort < 1024 || exposePort > 65535) {
throw { status: 500, message: `Exposed Port needs to be between 1024 and 65535.` };
}
if (configuredPort) {
if (configuredPort !== exposePort) {
const availablePort = await getFreeExposedPort(
id,
exposePort,
engine,
remoteEngine,
remoteIpAddress
);
if (availablePort.toString() !== exposePort.toString()) {
throw { status: 500, message: `Port ${exposePort} is already in use.` };
}
}
} else {
const availablePort = await getFreeExposedPort(
id,
exposePort,
engine,
remoteEngine,
remoteIpAddress
);
if (availablePort.toString() !== exposePort.toString()) {
throw { status: 500, message: `Port ${exposePort} is already in use.` };
}
}
}
async function getFreeExposedPort(id, exposePort, engine, remoteEngine, remoteIpAddress) {
const { default: checkPort } = await import("is-port-reachable");
if (remoteEngine) {
const applicationUsed = await (await import_prisma.prisma.application.findMany({
where: {
exposePort: { not: null },
id: { not: id },
destinationDocker: { remoteIpAddress }
},
select: { exposePort: true }
})).map((a) => a.exposePort);
const serviceUsed = await (await import_prisma.prisma.service.findMany({
where: {
exposePort: { not: null },
id: { not: id },
destinationDocker: { remoteIpAddress }
},
select: { exposePort: true }
})).map((a) => a.exposePort);
const usedPorts = [...applicationUsed, ...serviceUsed];
if (usedPorts.includes(exposePort)) {
return false;
}
const found = await checkPort(exposePort, { host: remoteIpAddress });
if (!found) {
return exposePort;
}
return false;
} else {
const applicationUsed = await (await import_prisma.prisma.application.findMany({
where: { exposePort: { not: null }, id: { not: id }, destinationDocker: { engine } },
select: { exposePort: true }
})).map((a) => a.exposePort);
const serviceUsed = await (await import_prisma.prisma.service.findMany({
where: { exposePort: { not: null }, id: { not: id }, destinationDocker: { engine } },
select: { exposePort: true }
})).map((a) => a.exposePort);
const usedPorts = [...applicationUsed, ...serviceUsed];
if (usedPorts.includes(exposePort)) {
return false;
}
const found = await checkPort(exposePort, { host: "localhost" });
if (!found) {
return exposePort;
}
return false;
}
}
async function checkDomainsIsValidInDNS({ hostname, fqdn, dualCerts }) {
const { isIP } = await import("is-ip");
const domain = getDomain(fqdn);
const domainDualCert = domain.includes("www.") ? domain.replace("www.", "") : `www.${domain}`;
const { DNSServers } = await listSettings();
if (DNSServers) {
import_dns.promises.setServers([...DNSServers.split(",")]);
}
let resolves = [];
try {
if (isIP(hostname)) {
resolves = [hostname];
} else {
resolves = await import_dns.promises.resolve4(hostname);
}
} catch (error) {
throw { status: 500, message: `Could not determine IP address for ${hostname}.` };
}
if (dualCerts) {
try {
const ipDomain = await import_dns.promises.resolve4(domain);
const ipDomainDualCert = await import_dns.promises.resolve4(domainDualCert);
let ipDomainFound = false;
let ipDomainDualCertFound = false;
for (const ip of ipDomain) {
if (resolves.includes(ip)) {
ipDomainFound = true;
}
}
for (const ip of ipDomainDualCert) {
if (resolves.includes(ip)) {
ipDomainDualCertFound = true;
}
}
if (ipDomainFound && ipDomainDualCertFound)
return { status: 200 };
throw {
status: 500,
message: `DNS not set correctly or propogated.<br>Please check your DNS settings.`
};
} catch (error) {
throw {
status: 500,
message: `DNS not set correctly or propogated.<br>Please check your DNS settings.`
};
}
} else {
try {
const ipDomain = await import_dns.promises.resolve4(domain);
let ipDomainFound = false;
for (const ip of ipDomain) {
if (resolves.includes(ip)) {
ipDomainFound = true;
}
}
if (ipDomainFound)
return { status: 200 };
throw {
status: 500,
message: `DNS not set correctly or propogated.<br>Please check your DNS settings.`
};
} catch (error) {
throw {
status: 500,
message: `DNS not set correctly or propogated.<br>Please check your DNS settings.`
};
}
}
}
const setDefaultConfiguration = async (data) => {
let {
buildPack,
port,
installCommand,
startCommand,
buildCommand,
publishDirectory,
baseDirectory,
dockerFileLocation,
dockerComposeFileLocation,
denoMainFile
} = data;
const template = scanningTemplates[buildPack];
if (!port) {
port = template?.port || 3e3;
if (buildPack === "static")
port = 80;
else if (buildPack === "node")
port = 3e3;
else if (buildPack === "php")
port = 80;
else if (buildPack === "python")
port = 8e3;
}
if (!installCommand && buildPack !== "static" && buildPack !== "laravel")
installCommand = template?.installCommand || "yarn install";
if (!startCommand && buildPack !== "static" && buildPack !== "laravel")
startCommand = template?.startCommand || "yarn start";
if (!buildCommand && buildPack !== "static" && buildPack !== "laravel")
buildCommand = template?.buildCommand || null;
if (!publishDirectory)
publishDirectory = template?.publishDirectory || null;
if (baseDirectory) {
if (!baseDirectory.startsWith("/"))
baseDirectory = `/${baseDirectory}`;
if (baseDirectory.endsWith("/") && baseDirectory !== "/")
baseDirectory = baseDirectory.slice(0, -1);
}
if (dockerFileLocation) {
if (!dockerFileLocation.startsWith("/"))
dockerFileLocation = `/${dockerFileLocation}`;
if (dockerFileLocation.endsWith("/"))
dockerFileLocation = dockerFileLocation.slice(0, -1);
} else {
dockerFileLocation = "/Dockerfile";
}
if (dockerComposeFileLocation) {
if (!dockerComposeFileLocation.startsWith("/"))
dockerComposeFileLocation = `/${dockerComposeFileLocation}`;
if (dockerComposeFileLocation.endsWith("/"))
dockerComposeFileLocation = dockerComposeFileLocation.slice(0, -1);
} else {
dockerComposeFileLocation = "/Dockerfile";
}
if (!denoMainFile) {
denoMainFile = "main.ts";
}
return {
buildPack,
port,
installCommand,
startCommand,
buildCommand,
publishDirectory,
baseDirectory,
dockerFileLocation,
dockerComposeFileLocation,
denoMainFile
};
};
const scanningTemplates = {
"@sveltejs/kit": {
buildPack: "nodejs"
},
astro: {
buildPack: "astro"
},
"@11ty/eleventy": {
buildPack: "eleventy"
},
svelte: {
buildPack: "svelte"
},
"@nestjs/core": {
buildPack: "nestjs"
},
next: {
buildPack: "nextjs"
},
nuxt: {
buildPack: "nuxtjs"
},
"react-scripts": {
buildPack: "react"
},
"parcel-bundler": {
buildPack: "static"
},
"@vue/cli-service": {
buildPack: "vuejs"
},
vuejs: {
buildPack: "vuejs"
},
gatsby: {
buildPack: "gatsby"
},
"preact-cli": {
buildPack: "react"
}
};
async function cleanupDB(buildId, applicationId) {
const data = await import_prisma.prisma.build.findUnique({ where: { id: buildId } });
if (data?.status === "queued" || data?.status === "running") {
await import_prisma.prisma.build.update({ where: { id: buildId }, data: { status: "canceled" } });
}
await (0, import_logging.saveBuildLog)({ line: "Canceled.", buildId, applicationId });
}
const base64Encode = (text) => {
return Buffer.from(text).toString("base64");
};
const base64Decode = (text) => {
return Buffer.from(text, "base64").toString("ascii");
};
function parseSecret(secret, isBuild) {
if (secret.value.includes("$")) {
secret.value = secret.value.replaceAll("$", "$$$$");
}
if (secret.value.includes("\\n")) {
if (isBuild) {
return `ARG ${secret.name}=${secret.value}`;
} else {
return `${secret.name}=${secret.value}`;
}
} else if (secret.value.includes(" ")) {
if (isBuild) {
return `ARG ${secret.name}='${secret.value}'`;
} else {
return `${secret.name}='${secret.value}'`;
}
} else {
if (isBuild) {
return `ARG ${secret.name}=${secret.value}`;
} else {
return `${secret.name}=${secret.value}`;
}
}
}
function generateSecrets(secrets, pullmergeRequestId, isBuild = false, port = null) {
const envs = [];
const isPRMRSecret = secrets.filter((s) => s.isPRMRSecret);
const normalSecrets = secrets.filter((s) => !s.isPRMRSecret);
if (pullmergeRequestId && isPRMRSecret.length > 0) {
isPRMRSecret.forEach((secret) => {
if (isBuild && !secret.isBuildSecret) {
return;
}
const build = isBuild && secret.isBuildSecret;
envs.push(parseSecret(secret, build));
});
}
if (!pullmergeRequestId && normalSecrets.length > 0) {
normalSecrets.forEach((secret) => {
if (isBuild && !secret.isBuildSecret) {
return;
}
const build = isBuild && secret.isBuildSecret;
envs.push(parseSecret(secret, build));
});
}
const portFound = envs.filter((env2) => env2.startsWith("PORT"));
if (portFound.length === 0 && port && !isBuild) {
envs.push(`PORT=${port}`);
}
const nodeEnv = envs.filter((env2) => env2.startsWith("NODE_ENV"));
if (nodeEnv.length === 0 && !isBuild) {
envs.push(`NODE_ENV=production`);
}
return envs;
}
function decryptApplication(application) {
if (application) {
if (application?.gitSource?.githubApp?.clientSecret) {
application.gitSource.githubApp.clientSecret = decrypt(application.gitSource.githubApp.clientSecret) || null;
}
if (application?.gitSource?.githubApp?.webhookSecret) {
application.gitSource.githubApp.webhookSecret = decrypt(application.gitSource.githubApp.webhookSecret) || null;
}
if (application?.gitSource?.githubApp?.privateKey) {
application.gitSource.githubApp.privateKey = decrypt(application.gitSource.githubApp.privateKey) || null;
}
if (application?.gitSource?.gitlabApp?.appSecret) {
application.gitSource.gitlabApp.appSecret = decrypt(application.gitSource.gitlabApp.appSecret) || null;
}
if (application?.secrets.length > 0) {
application.secrets = application.secrets.map((s) => {
s.value = decrypt(s.value) || null;
return s;
});
}
return application;
}
}
async function pushToRegistry(application, workdir, tag, imageName, customTag) {
const location = `${workdir}/.docker`;
const tagCommand = `docker tag ${application.id}:${tag} ${imageName}:${customTag}`;
const pushCommand = `docker --config ${location} push ${imageName}:${customTag}`;
await (0, import_executeCommand.executeCommand)({
dockerId: application.destinationDockerId,
command: tagCommand
});
await (0, import_executeCommand.executeCommand)({
dockerId: application.destinationDockerId,
command: pushCommand
});
}
async function getContainerUsage(dockerId, container) {
try {
const { stdout } = await (0, import_executeCommand.executeCommand)({
dockerId,
command: `docker container stats ${container} --no-stream --no-trunc --format "{{json .}}"`
});
return JSON.parse(stdout);
} catch (err) {
return {
MemUsage: 0,
CPUPerc: 0,
NetIO: 0
};
}
}
function fixType(type) {
return type?.replaceAll(" ", "").toLowerCase() || null;
}
const compareSemanticVersions = (a, b) => {
const a1 = a.split(".");
const b1 = b.split(".");
const len = Math.min(a1.length, b1.length);
for (let i = 0; i < len; i++) {
const a2 = +a1[i] || 0;
const b2 = +b1[i] || 0;
if (a2 !== b2) {
return a2 > b2 ? 1 : -1;
}
}
return b1.length - a1.length;
};
async function getTags(type) {
try {
if (type) {
const tagsPath = isDev ? "./tags.json" : "/app/tags.json";
const data = await import_promises.default.readFile(tagsPath, "utf8");
let tags = JSON.parse(data);
if (tags) {
tags = tags.find((tag) => tag.name.includes(type));
tags.tags = tags.tags.sort(compareSemanticVersions).reverse();
return tags;
}
}
} catch (error) {
return [];
}
}
function makeLabelForServices(type) {
return [
"coolify.managed=true",
`coolify.version=${version}`,
`coolify.type=service`,
`coolify.service.type=${type}`
];
}
const asyncSleep = (delay) => new Promise((resolve) => setTimeout(resolve, delay));
async function startTraefikTCPProxy(destinationDocker, id, publicPort, privatePort, type) {
const { network, id: dockerId, remoteEngine } = destinationDocker;
const container = `${id}-${publicPort}`;
const { found } = await (0, import_docker.checkContainer)({ dockerId, container, remove: true });
const { ipv4, ipv6 } = await listSettings();
let dependentId = id;
if (type === "wordpressftp")
dependentId = `${id}-ftp`;
const { found: foundDependentContainer } = await (0, import_docker.checkContainer)({
dockerId,
container: dependentId,
remove: true
});
if (foundDependentContainer && !found) {
const { stdout: Config } = await (0, import_executeCommand.executeCommand)({
dockerId,
command: `docker network inspect ${network} --format '{{json .IPAM.Config }}'`
});
const ip = JSON.parse(Config)[0].Gateway;
let traefikUrl = otherTraefikEndpoint;
if (remoteEngine) {
let ip2 = null;
if (isDev) {
ip2 = getAPIUrl();
} else {
ip2 = `http://${ipv4 || ipv6}:3000`;
}
traefikUrl = `${ip2}/webhooks/traefik/other.json`;
}
const tcpProxy = {
version: "3.8",
services: {
[`${id}-${publicPort}`]: {
container_name: container,
image: defaultTraefikImage,
command: [
`--entrypoints.tcp.address=:${publicPort}`,
`--entryPoints.tcp.forwardedHeaders.insecure=true`,
`--providers.http.endpoint=${traefikUrl}?id=${id}&privatePort=${privatePort}&publicPort=${publicPort}&type=tcp&address=${dependentId}`,
"--providers.http.pollTimeout=10s",
"--log.level=error"
],
ports: [`${publicPort}:${publicPort}`],
extra_hosts: ["host.docker.internal:host-gateway", `host.docker.internal: ${ip}`],
volumes: ["/var/run/docker.sock:/var/run/docker.sock"],
networks: ["coolify-infra", network]
}
},
networks: {
[network]: {
external: false,
name: network
},
"coolify-infra": {
external: false,
name: "coolify-infra"
}
}
};
await import_promises.default.writeFile(`/tmp/docker-compose-${id}.yaml`, import_js_yaml.default.dump(tcpProxy));
await (0, import_executeCommand.executeCommand)({
dockerId,
command: `docker compose -f /tmp/docker-compose-${id}.yaml up -d`
});
await import_promises.default.rm(`/tmp/docker-compose-${id}.yaml`);
}
if (!foundDependentContainer && found) {
await (0, import_executeCommand.executeCommand)({
dockerId,
command: `docker stop -t 0 ${container} && docker rm ${container}`,
shell: true
});
}
}
async function startTraefikProxy(id) {
const { engine, network, remoteEngine, remoteIpAddress } = await import_prisma.prisma.destinationDocker.findUnique({ where: { id } });
const { found } = await (0, import_docker.checkContainer)({
dockerId: id,
container: "coolify-proxy",
remove: true
});
const { id: settingsId, ipv4, ipv6 } = await listSettings();
if (!found) {
const { stdout: coolifyNetwork } = await (0, import_executeCommand.executeCommand)({
dockerId: id,
command: `docker network ls --filter 'name=coolify-infra' --no-trunc --format "{{json .}}"`
});
if (!coolifyNetwork) {
await (0, import_executeCommand.executeCommand)({
dockerId: id,
command: `docker network create --attachable coolify-infra`
});
}
const { stdout: Config } = await (0, import_executeCommand.executeCommand)({
dockerId: id,
command: `docker network inspect ${network} --format '{{json .IPAM.Config }}'`
});
const ip = JSON.parse(Config)[0].Gateway;
let traefikUrl = mainTraefikEndpoint;
if (remoteEngine) {
let ip2 = null;
if (isDev) {
ip2 = getAPIUrl();
} else {
ip2 = `http://${ipv4 || ipv6}:3000`;
}
traefikUrl = `${ip2}/webhooks/traefik/remote/${id}`;
}
await (0, import_executeCommand.executeCommand)({
dockerId: id,
command: `docker run --restart always --add-host 'host.docker.internal:host-gateway' ${ip ? `--add-host 'host.docker.internal:${ip}'` : ""} -v coolify-traefik-letsencrypt:/etc/traefik/acme -v /var/run/docker.sock:/var/run/docker.sock --network coolify-infra -p "80:80" -p "443:443" --name coolify-proxy -d ${defaultTraefikImage} --entrypoints.web.address=:80 --entrypoints.web.forwardedHeaders.insecure=true --entrypoints.websecure.address=:443 --entrypoints.websecure.forwardedHeaders.insecure=true --providers.docker=true --providers.docker.exposedbydefault=false --providers.http.endpoint=${traefikUrl} --providers.http.pollTimeout=5s --certificatesresolvers.letsencrypt.acme.httpchallenge=true --certificatesresolvers.letsencrypt.acme.storage=/etc/traefik/acme/acme.json --certificatesresolvers.letsencrypt.acme.httpchallenge.entrypoint=web --log.level=error`
});
await import_prisma.prisma.destinationDocker.update({
where: { id },
data: { isCoolifyProxyUsed: true }
});
}
if (engine) {
const destinations = await import_prisma.prisma.destinationDocker.findMany({ where: { engine } });
for (const destination of destinations) {
await configureNetworkTraefikProxy(destination);
}
}
if (remoteEngine) {
const destinations = await import_prisma.prisma.destinationDocker.findMany({ where: { remoteIpAddress } });
for (const destination of destinations) {
await configureNetworkTraefikProxy(destination);
}
}
}
async function configureNetworkTraefikProxy(destination) {
const { id } = destination;
const { stdout: networks } = await (0, import_executeCommand.executeCommand)({
dockerId: id,
command: `docker ps -a --filter name=coolify-proxy --format '{{json .Networks}}'`
});
const configuredNetworks = networks.replace(/"/g, "").replace("\n", "").split(",");
if (!configuredNetworks.includes(destination.network)) {
await (0, import_executeCommand.executeCommand)({
dockerId: destination.id,
command: `docker network connect ${destination.network} coolify-proxy`
});
}
}
async function stopTraefikProxy(id) {
const { found } = await (0, import_docker.checkContainer)({ dockerId: id, container: "coolify-proxy" });
await import_prisma.prisma.destinationDocker.update({
where: { id },
data: { isCoolifyProxyUsed: false }
});
if (found) {
return await (0, import_executeCommand.executeCommand)({
dockerId: id,
command: `docker stop -t 0 coolify-proxy && docker rm coolify-proxy`,
shell: true
});
}
return { stdout: "", stderr: "" };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
asyncSleep,
base64Decode,
base64Encode,
checkDomainsIsValidInDNS,
checkExposedPort,
cleanupDB,
comparePassword,
configureNetworkTraefikProxy,
createDirectories,
decrypt,
decryptApplication,
defaultTraefikImage,
encrypt,
fixType,
generateRangeArray,
generateSecrets,
generateTimestamp,
getAPIUrl,
getContainerUsage,
getCurrentUser,
getDomain,
getFreeExposedPort,
getTags,
getTeamInvitation,
getTemplates,
getUIUrl,
hashPassword,
isARM,
isDev,
isDomainConfigured,
listSettings,
makeLabelForServices,
pushToRegistry,
removeService,
saveDockerRegistryCredentials,
scanningTemplates,
sentryDSN,
setDefaultConfiguration,
startTraefikProxy,
startTraefikTCPProxy,
stopTraefikProxy,
uniqueName,
version
});

View File

@@ -0,0 +1,38 @@
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var dayjs_exports = {};
__export(dayjs_exports, {
day: () => import_dayjs.default
});
module.exports = __toCommonJS(dayjs_exports);
var import_dayjs = __toESM(require("dayjs"));
var import_utc = __toESM(require("dayjs/plugin/utc.js"));
var import_relativeTime = __toESM(require("dayjs/plugin/relativeTime.js"));
import_dayjs.default.extend(import_utc.default);
import_dayjs.default.extend(import_relativeTime.default);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
day
});

View File

@@ -0,0 +1,168 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var docker_exports = {};
__export(docker_exports, {
checkContainer: () => checkContainer,
defaultComposeConfiguration: () => defaultComposeConfiguration,
formatLabelsOnDocker: () => formatLabelsOnDocker,
removeContainer: () => removeContainer,
stopDatabaseContainer: () => stopDatabaseContainer,
stopTcpHttpProxy: () => stopTcpHttpProxy
});
module.exports = __toCommonJS(docker_exports);
var import_executeCommand = require("./executeCommand");
async function checkContainer({
dockerId,
container,
remove = false
}) {
let containerFound = false;
try {
const { stdout } = await (0, import_executeCommand.executeCommand)({
dockerId,
command: `docker inspect --format '{{json .State}}' ${container}`
});
containerFound = true;
const parsedStdout = JSON.parse(stdout);
const status = parsedStdout.Status;
const isRunning = status === "running";
const isRestarting = status === "restarting";
const isExited = status === "exited";
if (status === "created") {
await (0, import_executeCommand.executeCommand)({
dockerId,
command: `docker rm ${container}`
});
}
if (remove && status === "exited") {
await (0, import_executeCommand.executeCommand)({
dockerId,
command: `docker rm ${container}`
});
}
return {
found: containerFound,
status: {
isRunning,
isRestarting,
isExited
}
};
} catch (err) {
}
return {
found: false
};
}
async function removeContainer({
id,
dockerId
}) {
try {
const { stdout } = await (0, import_executeCommand.executeCommand)({
dockerId,
command: `docker inspect --format '{{json .State}}' ${id}`
});
if (JSON.parse(stdout).Running) {
await (0, import_executeCommand.executeCommand)({ dockerId, command: `docker stop -t 0 ${id}` });
await (0, import_executeCommand.executeCommand)({ dockerId, command: `docker rm ${id}` });
}
if (JSON.parse(stdout).Status === "exited") {
await (0, import_executeCommand.executeCommand)({ dockerId, command: `docker rm ${id}` });
}
} catch (error) {
throw error;
}
}
async function stopDatabaseContainer(database) {
let everStarted = false;
const {
id,
destinationDockerId,
destinationDocker: { engine, id: dockerId }
} = database;
if (destinationDockerId) {
try {
const { stdout } = await (0, import_executeCommand.executeCommand)({
dockerId,
command: `docker inspect --format '{{json .State}}' ${id}`
});
if (stdout) {
everStarted = true;
await removeContainer({ id, dockerId });
}
} catch (error) {
}
}
return everStarted;
}
async function stopTcpHttpProxy(id, destinationDocker, publicPort, forceName = null) {
const { id: dockerId } = destinationDocker;
let container = `${id}-${publicPort}`;
if (forceName)
container = forceName;
const { found } = await checkContainer({ dockerId, container });
try {
if (!found)
return true;
return await (0, import_executeCommand.executeCommand)({
dockerId,
command: `docker stop -t 0 ${container} && docker rm ${container}`,
shell: true
});
} catch (error) {
return error;
}
}
function formatLabelsOnDocker(data) {
return data.trim().split("\n").map((a) => JSON.parse(a)).map((container) => {
const labels = container.Labels.split(",");
let jsonLabels = {};
labels.forEach((l) => {
const name = l.split("=")[0];
const value = l.split("=")[1];
jsonLabels = { ...jsonLabels, ...{ [name]: value } };
});
container.Labels = jsonLabels;
return container;
});
}
function defaultComposeConfiguration(network) {
return {
networks: [network],
restart: "on-failure",
deploy: {
restart_policy: {
condition: "on-failure",
delay: "5s",
max_attempts: 10,
window: "120s"
}
}
};
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
checkContainer,
defaultComposeConfiguration,
formatLabelsOnDocker,
removeContainer,
stopDatabaseContainer,
stopTcpHttpProxy
});

View File

@@ -0,0 +1,207 @@
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var executeCommand_exports = {};
__export(executeCommand_exports, {
createRemoteEngineConfiguration: () => createRemoteEngineConfiguration,
executeCommand: () => executeCommand
});
module.exports = __toCommonJS(executeCommand_exports);
var import_prisma = require("../prisma");
var import_os = __toESM(require("os"));
var import_promises = __toESM(require("fs/promises"));
var import_ssh_config = __toESM(require("ssh-config"));
var import_ssh = require("./ssh");
var import_env = require("../env");
var import_logging = require("./logging");
var import_common = require("./common");
async function executeCommand({
command,
dockerId = null,
sshCommand = false,
shell = false,
stream = false,
buildId,
applicationId,
debug
}) {
const { execa, execaCommand } = await import("execa");
const { parse } = await import("shell-quote");
const parsedCommand = parse(command);
const dockerCommand = parsedCommand[0];
const dockerArgs = parsedCommand.slice(1);
if (dockerId && dockerCommand && dockerArgs) {
const destinationDocker = await import_prisma.prisma.destinationDocker.findUnique({
where: { id: dockerId }
});
if (!destinationDocker) {
throw new Error("Destination docker not found");
}
let { remoteEngine, remoteIpAddress, engine } = destinationDocker;
if (remoteEngine) {
await createRemoteEngineConfiguration(dockerId);
engine = `ssh://${remoteIpAddress}-remote`;
} else {
engine = "unix:///var/run/docker.sock";
}
if (import_env.env.CODESANDBOX_HOST) {
if (command.startsWith("docker compose")) {
command = command.replace(/docker compose/gi, "docker-compose");
}
}
if (sshCommand) {
if (shell) {
return execaCommand(`ssh ${remoteIpAddress}-remote ${command}`);
}
return await execa("ssh", [`${remoteIpAddress}-remote`, dockerCommand, ...dockerArgs]);
}
if (stream) {
return await new Promise(async (resolve, reject) => {
let subprocess = null;
if (shell) {
subprocess = execaCommand(command, {
env: { DOCKER_BUILDKIT: "1", DOCKER_HOST: engine }
});
} else {
subprocess = execa(dockerCommand, dockerArgs, {
env: { DOCKER_BUILDKIT: "1", DOCKER_HOST: engine }
});
}
const logs = [];
if (subprocess && subprocess.stdout && subprocess.stderr) {
subprocess.stdout.on("data", async (data) => {
const stdout = data.toString();
const array = stdout.split("\n");
for (const line of array) {
if (line !== "\n" && line !== "") {
const log = {
line: `${line.replace("\n", "")}`,
buildId,
applicationId
};
logs.push(log);
if (debug) {
await (0, import_logging.saveBuildLog)(log);
}
}
}
});
subprocess.stderr.on("data", async (data) => {
const stderr = data.toString();
const array = stderr.split("\n");
for (const line of array) {
if (line !== "\n" && line !== "") {
const log = {
line: `${line.replace("\n", "")}`,
buildId,
applicationId
};
logs.push(log);
if (debug) {
await (0, import_logging.saveBuildLog)(log);
}
}
}
});
subprocess.on("exit", async (code) => {
if (code === 0) {
resolve(code);
} else {
if (!debug) {
for (const log of logs) {
await (0, import_logging.saveBuildLog)(log);
}
}
reject(code);
}
});
}
});
} else {
if (shell) {
return await execaCommand(command, {
env: { DOCKER_BUILDKIT: "1", DOCKER_HOST: engine }
});
} else {
return await execa(dockerCommand, dockerArgs, {
env: { DOCKER_BUILDKIT: "1", DOCKER_HOST: engine }
});
}
}
} else {
if (shell) {
return execaCommand(command, { shell: true });
}
return await execa(dockerCommand, dockerArgs);
}
}
async function createRemoteEngineConfiguration(id) {
const homedir = import_os.default.homedir();
const sshKeyFile = `/tmp/id_rsa-${id}`;
const localPort = await (0, import_ssh.getFreeSSHLocalPort)(id);
const {
sshKey: { privateKey },
network,
remoteIpAddress,
remotePort,
remoteUser
} = await import_prisma.prisma.destinationDocker.findFirst({ where: { id }, include: { sshKey: true } });
await import_promises.default.writeFile(sshKeyFile, (0, import_common.decrypt)(privateKey) + "\n", { encoding: "utf8", mode: 400 });
const config = import_ssh_config.default.parse("");
const Host = `${remoteIpAddress}-remote`;
try {
await executeCommand({ command: `ssh-keygen -R ${Host}` });
await executeCommand({ command: `ssh-keygen -R ${remoteIpAddress}` });
await executeCommand({ command: `ssh-keygen -R localhost:${localPort}` });
} catch (error) {
}
const found = config.find({ Host });
const foundIp = config.find({ Host: remoteIpAddress });
if (found)
config.remove({ Host });
if (foundIp)
config.remove({ Host: remoteIpAddress });
config.append({
Host,
Hostname: remoteIpAddress,
Port: remotePort.toString(),
User: remoteUser,
StrictHostKeyChecking: "no",
IdentityFile: sshKeyFile,
ControlMaster: "auto",
ControlPath: `${homedir}/.ssh/coolify-${remoteIpAddress}-%r@%h:%p`,
ControlPersist: "10m"
});
try {
await import_promises.default.stat(`${homedir}/.ssh/`);
} catch (error) {
await import_promises.default.mkdir(`${homedir}/.ssh/`);
}
return await import_promises.default.writeFile(`${homedir}/.ssh/config`, import_ssh_config.default.stringify(config));
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
createRemoteEngineConfiguration,
executeCommand
});

View File

@@ -0,0 +1,108 @@
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var github_exports = {};
__export(github_exports, {
default: () => github_default
});
module.exports = __toCommonJS(github_exports);
var import_jsonwebtoken = __toESM(require("jsonwebtoken"));
var import_prisma = require("../../prisma");
var import_common = require("../buildPacks/common");
var import_common2 = require("../common");
var import_executeCommand = require("../executeCommand");
async function github_default({
applicationId,
workdir,
githubAppId,
repository,
apiUrl,
gitCommitHash,
htmlUrl,
branch,
buildId,
customPort,
forPublic
}) {
const { default: got } = await import("got");
const url = htmlUrl.replace("https://", "").replace("http://", "");
if (forPublic) {
await (0, import_common.saveBuildLog)({
line: `Cloning ${repository}:${branch}...`,
buildId,
applicationId
});
if (gitCommitHash) {
await (0, import_common.saveBuildLog)({
line: `Checking out ${gitCommitHash} commit...`,
buildId,
applicationId
});
}
await (0, import_executeCommand.executeCommand)({
command: `git clone -q -b ${branch} https://${url}/${repository}.git ${workdir}/ && cd ${workdir} && git checkout ${gitCommitHash || ""} && git submodule update --init --recursive && git lfs pull && cd .. `,
shell: true
});
} else {
const body = await import_prisma.prisma.githubApp.findUnique({ where: { id: githubAppId } });
if (body.privateKey)
body.privateKey = (0, import_common2.decrypt)(body.privateKey);
const { privateKey, appId, installationId } = body;
const githubPrivateKey = privateKey.replace(/\\n/g, "\n").replace(/"/g, "");
const payload = {
iat: Math.round(new Date().getTime() / 1e3),
exp: Math.round(new Date().getTime() / 1e3 + 60),
iss: appId
};
const jwtToken = import_jsonwebtoken.default.sign(payload, githubPrivateKey, {
algorithm: "RS256"
});
const { token } = await got.post(`${apiUrl}/app/installations/${installationId}/access_tokens`, {
headers: {
Authorization: `Bearer ${jwtToken}`,
Accept: "application/vnd.github.machine-man-preview+json"
}
}).json();
await (0, import_common.saveBuildLog)({
line: `Cloning ${repository}:${branch}...`,
buildId,
applicationId
});
if (gitCommitHash) {
await (0, import_common.saveBuildLog)({
line: `Checking out ${gitCommitHash} commit...`,
buildId,
applicationId
});
}
await (0, import_executeCommand.executeCommand)({
command: `git clone -q -b ${branch} https://x-access-token:${token}@${url}/${repository}.git --config core.sshCommand="ssh -p ${customPort}" ${workdir}/ && cd ${workdir} && git checkout ${gitCommitHash || ""} && git submodule update --init --recursive && git lfs pull && cd .. `,
shell: true
});
}
const { stdout: commit } = await (0, import_executeCommand.executeCommand)({ command: `cd ${workdir}/ && git rev-parse HEAD`, shell: true });
return commit.replace("\n", "");
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {});

View File

@@ -0,0 +1,76 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var gitlab_exports = {};
__export(gitlab_exports, {
default: () => gitlab_default
});
module.exports = __toCommonJS(gitlab_exports);
var import_common = require("../buildPacks/common");
var import_executeCommand = require("../executeCommand");
async function gitlab_default({
applicationId,
workdir,
repodir,
htmlUrl,
gitCommitHash,
repository,
branch,
buildId,
privateSshKey,
customPort,
forPublic,
customUser
}) {
const url = htmlUrl.replace("https://", "").replace("http://", "").replace(/\/$/, "");
if (!forPublic) {
await (0, import_executeCommand.executeCommand)({ command: `echo '${privateSshKey}' > ${repodir}/id.rsa`, shell: true });
await (0, import_executeCommand.executeCommand)({ command: `chmod 600 ${repodir}/id.rsa` });
}
await (0, import_common.saveBuildLog)({
line: `Cloning ${repository}:${branch}...`,
buildId,
applicationId
});
if (gitCommitHash) {
await (0, import_common.saveBuildLog)({
line: `Checking out ${gitCommitHash} commit...`,
buildId,
applicationId
});
}
if (forPublic) {
await (0, import_executeCommand.executeCommand)(
{
command: `git clone -q -b ${branch} https://${url}/${repository}.git ${workdir}/ && cd ${workdir}/ && git checkout ${gitCommitHash || ""} && git submodule update --init --recursive && git lfs pull && cd .. `,
shell: true
}
);
} else {
await (0, import_executeCommand.executeCommand)(
{
command: `git clone -q -b ${branch} ${customUser}@${url}:${repository}.git --config core.sshCommand="ssh -p ${customPort} -q -i ${repodir}id.rsa -o StrictHostKeyChecking=no" ${workdir}/ && cd ${workdir}/ && git checkout ${gitCommitHash || ""} && git submodule update --init --recursive && git lfs pull && cd .. `,
shell: true
}
);
}
const { stdout: commit } = await (0, import_executeCommand.executeCommand)({ command: `cd ${workdir}/ && git rev-parse HEAD`, shell: true });
return commit.replace("\n", "");
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {});

View File

@@ -0,0 +1,37 @@
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var importers_exports = {};
__export(importers_exports, {
github: () => import_github.default,
gitlab: () => import_gitlab.default
});
module.exports = __toCommonJS(importers_exports);
var import_github = __toESM(require("./github"));
var import_gitlab = __toESM(require("./gitlab"));
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
github,
gitlab
});

View File

@@ -0,0 +1,75 @@
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var logging_exports = {};
__export(logging_exports, {
saveBuildLog: () => saveBuildLog
});
module.exports = __toCommonJS(logging_exports);
var import_prisma = require("../prisma");
var import_common = require("./common");
var import_dayjs = require("./dayjs");
const saveBuildLog = async ({ line, buildId, applicationId }) => {
if (buildId === "undefined" || buildId === "null" || !buildId)
return;
if (applicationId === "undefined" || applicationId === "null" || !applicationId)
return;
const { default: got } = await import("got");
if (typeof line === "object" && line) {
if (line.shortMessage) {
line = line.shortMessage + "\n" + line.stderr;
} else {
line = JSON.stringify(line);
}
}
if (line && typeof line === "string" && line.includes("ghs_")) {
const regex = /ghs_.*@/g;
line = line.replace(regex, "<SENSITIVE_DATA_DELETED>@");
}
const addTimestamp = `[${(0, import_common.generateTimestamp)()}] ${line}`;
const fluentBitUrl = import_common.isDev ? "http://localhost:24224" : "http://coolify-fluentbit:24224";
if (import_common.isDev) {
console.debug(`[${applicationId}] ${addTimestamp}`);
}
try {
return await got.post(`${fluentBitUrl}/${applicationId}_buildlog_${buildId}.csv`, {
json: {
line: (0, import_common.encrypt)(line)
}
});
} catch (error) {
return await import_prisma.prisma.buildLog.create({
data: {
line: addTimestamp,
buildId,
time: Number((0, import_dayjs.day)().valueOf()),
applicationId
}
});
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
saveBuildLog
});

View File

@@ -0,0 +1,76 @@
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var ssh_exports = {};
__export(ssh_exports, {
getFreeSSHLocalPort: () => getFreeSSHLocalPort
});
module.exports = __toCommonJS(ssh_exports);
var import_prisma = require("../prisma");
var import_common = require("./common");
async function getFreeSSHLocalPort(id) {
const { default: isReachable } = await import("is-port-reachable");
const { remoteIpAddress, sshLocalPort } = await import_prisma.prisma.destinationDocker.findUnique({
where: { id }
});
if (sshLocalPort) {
return Number(sshLocalPort);
}
const data = await import_prisma.prisma.setting.findFirst();
const { minPort, maxPort } = data;
const ports = await import_prisma.prisma.destinationDocker.findMany({
where: { sshLocalPort: { not: null }, remoteIpAddress: { not: remoteIpAddress } }
});
const alreadyConfigured = await import_prisma.prisma.destinationDocker.findFirst({
where: {
remoteIpAddress,
id: { not: id },
sshLocalPort: { not: null }
}
});
if (alreadyConfigured?.sshLocalPort) {
await import_prisma.prisma.destinationDocker.update({
where: { id },
data: { sshLocalPort: alreadyConfigured.sshLocalPort }
});
return Number(alreadyConfigured.sshLocalPort);
}
const range = (0, import_common.generateRangeArray)(minPort, maxPort);
const availablePorts = range.filter((port) => !ports.map((p) => p.sshLocalPort).includes(port));
for (const port of availablePorts) {
const found = await isReachable(port, { host: "localhost" });
if (!found) {
await import_prisma.prisma.destinationDocker.update({
where: { id },
data: { sshLocalPort: Number(port) }
});
return Number(port);
}
}
return false;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
getFreeSSHLocalPort
});