2022-02-10 15:47:44 +01:00
|
|
|
import { base64Encode } from '$lib/crypto';
|
|
|
|
import { getDomain, saveBuildLog, version } from '$lib/common';
|
|
|
|
import * as db from '$lib/database';
|
|
|
|
import { scanningTemplates } from '$lib/components/templates';
|
|
|
|
import { promises as fs } from 'fs';
|
|
|
|
import { staticDeployments } from '$lib/components/common';
|
|
|
|
|
2022-04-26 14:51:08 +02:00
|
|
|
const staticApps = ['static', 'react', 'vuejs', 'svelte', 'gatsby', 'astro', 'eleventy'];
|
|
|
|
const nodeBased = ['react', 'vuejs', 'svelte', 'gatsby', 'php', 'astro', 'eleventy', 'node'];
|
|
|
|
|
2022-02-10 15:47:44 +01:00
|
|
|
export 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 = getDomain(fqdn);
|
|
|
|
fqdn = `${protocol}://${pullmergeRequestId}.${domain}`;
|
|
|
|
}
|
|
|
|
return [
|
2022-03-23 10:25:32 +01:00
|
|
|
'coolify.managed=true',
|
|
|
|
`coolify.version=${version}`,
|
|
|
|
`coolify.type=standalone-application`,
|
|
|
|
`coolify.configuration=${base64Encode(
|
2022-02-10 15:47:44 +01:00
|
|
|
JSON.stringify({
|
|
|
|
applicationId,
|
|
|
|
fqdn,
|
|
|
|
name,
|
|
|
|
type,
|
|
|
|
pullmergeRequestId,
|
|
|
|
buildPack,
|
|
|
|
repository,
|
|
|
|
branch,
|
|
|
|
projectId,
|
|
|
|
port,
|
|
|
|
commit,
|
|
|
|
installCommand,
|
|
|
|
buildCommand,
|
|
|
|
startCommand,
|
|
|
|
baseDirectory,
|
|
|
|
publishDirectory
|
|
|
|
})
|
|
|
|
)}`
|
|
|
|
];
|
|
|
|
}
|
|
|
|
export async function makeLabelForStandaloneDatabase({ id, image, volume }) {
|
|
|
|
const database = await db.prisma.database.findFirst({ where: { id } });
|
|
|
|
delete database.destinationDockerId;
|
|
|
|
delete database.createdAt;
|
|
|
|
delete database.updatedAt;
|
|
|
|
return [
|
|
|
|
'coolify.managed=true',
|
|
|
|
`coolify.version=${version}`,
|
|
|
|
`coolify.type=standalone-database`,
|
|
|
|
`coolify.configuration=${base64Encode(
|
|
|
|
JSON.stringify({
|
|
|
|
version,
|
|
|
|
image,
|
|
|
|
volume,
|
|
|
|
...database
|
|
|
|
})
|
|
|
|
)}`
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2022-02-15 21:44:36 +01:00
|
|
|
export function makeLabelForServices(type) {
|
2022-02-10 15:47:44 +01:00
|
|
|
return [
|
|
|
|
'coolify.managed=true',
|
|
|
|
`coolify.version=${version}`,
|
2022-02-15 21:44:36 +01:00
|
|
|
`coolify.type=service`,
|
|
|
|
`coolify.service.type=${type}`
|
2022-02-10 15:47:44 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
export const setDefaultConfiguration = async (data) => {
|
2022-03-19 15:04:52 +01:00
|
|
|
let {
|
|
|
|
buildPack,
|
|
|
|
port,
|
|
|
|
installCommand,
|
|
|
|
startCommand,
|
|
|
|
buildCommand,
|
|
|
|
publishDirectory,
|
2022-04-19 22:34:28 +02:00
|
|
|
baseDirectory,
|
2022-04-20 22:23:25 +02:00
|
|
|
dockerFileLocation,
|
|
|
|
denoMainFile
|
2022-03-19 15:04:52 +01:00
|
|
|
} = data;
|
2022-02-10 15:47:44 +01:00
|
|
|
const template = scanningTemplates[buildPack];
|
|
|
|
if (!port) {
|
|
|
|
port = template?.port || 3000;
|
|
|
|
|
|
|
|
if (buildPack === 'static') port = 80;
|
|
|
|
else if (buildPack === 'node') port = 3000;
|
|
|
|
else if (buildPack === 'php') port = 80;
|
2022-04-02 16:22:51 +02:00
|
|
|
else if (buildPack === 'python') port = 8000;
|
2022-02-10 15:47:44 +01:00
|
|
|
}
|
2022-04-20 22:23:25 +02:00
|
|
|
if (!installCommand && buildPack !== 'static')
|
|
|
|
installCommand = template?.installCommand || 'yarn install';
|
|
|
|
if (!startCommand && buildPack !== 'static')
|
|
|
|
startCommand = template?.startCommand || 'yarn start';
|
|
|
|
if (!buildCommand && buildPack !== 'static') buildCommand = template?.buildCommand || null;
|
2022-02-10 15:47:44 +01:00
|
|
|
if (!publishDirectory) publishDirectory = template?.publishDirectory || null;
|
2022-03-19 15:04:52 +01:00
|
|
|
if (baseDirectory) {
|
|
|
|
if (!baseDirectory.startsWith('/')) baseDirectory = `/${baseDirectory}`;
|
|
|
|
if (!baseDirectory.endsWith('/')) baseDirectory = `${baseDirectory}/`;
|
|
|
|
}
|
2022-04-19 22:34:28 +02:00
|
|
|
if (dockerFileLocation) {
|
|
|
|
if (!dockerFileLocation.startsWith('/')) dockerFileLocation = `/${dockerFileLocation}`;
|
|
|
|
if (dockerFileLocation.endsWith('/')) dockerFileLocation = dockerFileLocation.slice(0, -1);
|
|
|
|
} else {
|
|
|
|
dockerFileLocation = '/Dockerfile';
|
|
|
|
}
|
2022-04-20 22:23:25 +02:00
|
|
|
if (!denoMainFile) {
|
|
|
|
denoMainFile = 'main.ts';
|
|
|
|
}
|
2022-02-10 15:47:44 +01:00
|
|
|
|
|
|
|
return {
|
|
|
|
buildPack,
|
|
|
|
port,
|
|
|
|
installCommand,
|
|
|
|
startCommand,
|
|
|
|
buildCommand,
|
2022-03-19 15:04:52 +01:00
|
|
|
publishDirectory,
|
2022-04-19 22:34:28 +02:00
|
|
|
baseDirectory,
|
2022-04-20 22:23:25 +02:00
|
|
|
dockerFileLocation,
|
|
|
|
denoMainFile
|
2022-02-10 15:47:44 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-04-26 14:51:08 +02:00
|
|
|
export async function copyBaseConfigurationFiles(
|
|
|
|
buildPack,
|
|
|
|
workdir,
|
|
|
|
buildId,
|
|
|
|
applicationId,
|
|
|
|
baseImage
|
|
|
|
) {
|
2022-02-10 15:47:44 +01:00
|
|
|
try {
|
|
|
|
if (buildPack === 'php') {
|
2022-03-21 21:46:49 +01:00
|
|
|
await fs.writeFile(`${workdir}/entrypoint.sh`, `chown -R 1000 /app`);
|
2022-04-03 22:53:11 +02:00
|
|
|
await saveBuildLog({
|
|
|
|
line: 'Copied default configuration file for PHP.',
|
|
|
|
buildId,
|
|
|
|
applicationId
|
|
|
|
});
|
2022-04-26 14:51:08 +02:00
|
|
|
} else if (staticDeployments.includes(buildPack) && baseImage.includes('nginx')) {
|
2022-02-10 15:47:44 +01:00
|
|
|
await fs.writeFile(
|
|
|
|
`${workdir}/nginx.conf`,
|
|
|
|
`user nginx;
|
|
|
|
worker_processes auto;
|
|
|
|
|
2022-03-21 21:25:01 +01:00
|
|
|
error_log /docker.stdout;
|
|
|
|
pid /run/nginx.pid;
|
2022-02-10 15:47:44 +01:00
|
|
|
|
|
|
|
events {
|
|
|
|
worker_connections 1024;
|
|
|
|
}
|
|
|
|
|
|
|
|
http {
|
2022-03-21 21:25:01 +01:00
|
|
|
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;
|
2022-02-10 15:47:44 +01:00
|
|
|
|
|
|
|
server {
|
|
|
|
listen 80;
|
|
|
|
server_name localhost;
|
|
|
|
|
|
|
|
location / {
|
2022-03-21 21:25:01 +01:00
|
|
|
root /app;
|
2022-02-10 15:47:44 +01:00
|
|
|
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 {
|
2022-03-21 21:25:01 +01:00
|
|
|
root /app;
|
2022-02-10 15:47:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.log(error);
|
|
|
|
throw new Error(error);
|
|
|
|
}
|
|
|
|
}
|
2022-03-19 15:04:52 +01:00
|
|
|
|
|
|
|
export function checkPnpm(installCommand = null, buildCommand = null, startCommand = null) {
|
|
|
|
return (
|
|
|
|
installCommand?.includes('pnpm') ||
|
|
|
|
buildCommand?.includes('pnpm') ||
|
|
|
|
startCommand?.includes('pnpm')
|
|
|
|
);
|
|
|
|
}
|
2022-04-26 14:51:08 +02:00
|
|
|
|
|
|
|
export function setDefaultBaseImage(buildPack) {
|
|
|
|
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'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
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.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.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: 'webdevops/php-nginx:7.1-alpine',
|
|
|
|
label: 'webdevops/php-nginx:7.1-alpine'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
let payload = {
|
|
|
|
baseImage: null,
|
|
|
|
baseBuildImage: null,
|
|
|
|
baseImages: [],
|
|
|
|
baseBuildImages: []
|
|
|
|
};
|
|
|
|
if (nodeBased.includes(buildPack)) {
|
|
|
|
payload.baseImage = 'node:lts';
|
|
|
|
payload.baseImages = nodeVersions;
|
|
|
|
}
|
|
|
|
if (staticApps.includes(buildPack)) {
|
|
|
|
payload.baseImage = 'webdevops/nginx:alpine';
|
|
|
|
payload.baseImages = staticVersions;
|
|
|
|
payload.baseBuildImage = 'node:lts';
|
|
|
|
payload.baseBuildImages = nodeVersions;
|
|
|
|
}
|
|
|
|
if (buildPack === 'python') {
|
|
|
|
payload.baseImage = 'python:3-alpine';
|
|
|
|
}
|
|
|
|
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 = 'webdevops/php-apache:8.0-alpine';
|
|
|
|
payload.baseImages = phpVersions;
|
|
|
|
}
|
|
|
|
return payload;
|
|
|
|
}
|