feat: Use compose instead of normal docker cmd

This commit is contained in:
Andras Bacsai
2022-03-23 10:25:32 +01:00
parent f0ab3750bd
commit 2bf73109b2
13 changed files with 131 additions and 191 deletions

View File

@@ -29,10 +29,10 @@ export function makeLabelForStandaloneApplication({
fqdn = `${protocol}://${pullmergeRequestId}.${domain}`;
}
return [
'--label coolify.managed=true',
`--label coolify.version=${version}`,
`--label coolify.type=standalone-application`,
`--label coolify.configuration=${base64Encode(
'coolify.managed=true',
`coolify.version=${version}`,
`coolify.type=standalone-application`,
`coolify.configuration=${base64Encode(
JSON.stringify({
applicationId,
fqdn,

View File

@@ -6,13 +6,6 @@ const createDockerfile = async (data, image): Promise<void> => {
const Dockerfile: Array<string> = [];
Dockerfile.push(`FROM ${image}`);
Dockerfile.push(`LABEL coolify.image=true`);
if (data.phpModules?.length > 0) {
Dockerfile.push(
`ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/`
);
Dockerfile.push(`RUN chmod +x /usr/local/bin/install-php-extensions`);
Dockerfile.push(`RUN /usr/local/bin/install-php-extensions ${data.phpModules.join(' ')}`);
}
Dockerfile.push('WORKDIR /app');
Dockerfile.push(`COPY .${baseDirectory || ''} /app`);
Dockerfile.push(`COPY /.htaccess .`);

View File

@@ -9,7 +9,16 @@ export const dateOptions: DateTimeFormatOptions = {
hour12: false
};
export const staticDeployments = ['react', 'vuejs', 'static', 'svelte', 'gatsby', 'php'];
export const staticDeployments = [
'react',
'vuejs',
'static',
'svelte',
'gatsby',
'php',
'astro',
'eleventy'
];
export const notNodeDeployments = ['php', 'docker', 'rust'];
export function getDomain(domain) {

View File

@@ -66,6 +66,7 @@ export async function removeApplication({ id, teamId }) {
await prisma.buildLog.deleteMany({ where: { applicationId: id } });
await prisma.build.deleteMany({ where: { applicationId: id } });
await prisma.secret.deleteMany({ where: { applicationId: id } });
await prisma.applicationPersistentStorage.deleteMany({ where: { applicationId: id } });
await prisma.application.deleteMany({ where: { id, teams: { some: { id: teamId } } } });
}
@@ -157,9 +158,6 @@ export async function getApplication({ id, teamId }) {
return s;
});
}
if (body?.phpModules) {
body.phpModules = body.phpModules.split(',');
}
return { ...body };
}
@@ -215,8 +213,7 @@ export async function configureApplication({
buildCommand,
startCommand,
baseDirectory,
publishDirectory,
phpModules
publishDirectory
}) {
return await prisma.application.update({
where: { id },
@@ -229,8 +226,7 @@ export async function configureApplication({
startCommand,
baseDirectory,
publishDirectory,
name,
phpModules
name
}
});
}

View File

@@ -19,6 +19,7 @@ import {
makeLabelForStandaloneApplication,
setDefaultConfiguration
} from '$lib/buildPacks/common';
import yaml from 'js-yaml';
export default async function (job) {
/*
@@ -71,7 +72,7 @@ export default async function (job) {
let volumes =
persistentStorage?.map((storage) => {
return `${applicationId}${storage.path.replace(/\//gi, '-')}:${
type !== 'docker' ? '/app/' : ''
type !== 'docker' ? '/app' : ''
}${storage.path}`;
}) || [];
// Previews, we need to get the source branch and set subdomain
@@ -261,23 +262,53 @@ export default async function (job) {
}
try {
saveBuildLog({ line: 'Deployment started.', buildId, applicationId });
for await (const volume of volumes) {
const id = volume.split(':')[0];
try {
await asyncExecShell(`DOCKER_HOST=${host} docker volume inspect ${id}`);
} catch (error) {
await asyncExecShell(`DOCKER_HOST=${host} docker volume create ${id}`);
}
}
volumes = volumes.map((volume) => `-v ${volume} `).join();
const { stderr } = await asyncExecShell(
`DOCKER_HOST=${host} docker run ${envFound && `--env-file=${workdir}/.env`} ${labels.join(
' '
)} --name ${imageId} --network ${docker.network} --restart always ${
volumes.length > 0 ? volumes : ''
} -d ${applicationId}:${tag}`
// for await (const volume of volumes) {
// const id = volume.split(':')[0];
// try {
// await asyncExecShell(`DOCKER_HOST=${host} docker volume inspect ${id}`);
// } catch (error) {
// await asyncExecShell(`DOCKER_HOST=${host} docker volume create ${id}`);
// }
// }
const composeVolumes = volumes.map((volume) => {
return {
[`${volume.split(':')[0]}`]: {
name: volume.split(':')[0]
}
};
});
const compose = {
version: '3.8',
services: {
[imageId]: {
image: `${applicationId}:${tag}`,
container_name: imageId,
volumes,
env_file: envFound ? [`${workdir}/.env`] : [],
networks: [docker.network],
labels: labels,
depends_on: [],
restart: 'always'
}
},
networks: {
[docker.network]: {
external: true
}
},
volumes: Object.assign({}, ...composeVolumes)
};
await fs.writeFile(`${workdir}/docker-compose.yml`, yaml.dump(compose));
await asyncExecShell(
`DOCKER_HOST=${host} docker compose --project-directory ${workdir} up -d`
);
if (stderr) console.log(stderr);
// const { stderr } = await asyncExecShell(
// `DOCKER_HOST=${host} docker run ${envFound && `--env-file=${workdir}/.env`} ${labels.join(
// ' '
// )} --name ${imageId} --network ${docker.network} --restart always ${volumes.length > 0 ? volumes : ''
// } -d ${applicationId}:${tag}`
// );
saveBuildLog({ line: 'Deployment successful!', buildId, applicationId });
} catch (error) {
saveBuildLog({ line: error, buildId, applicationId });