feat: PHP Composer support
This commit is contained in:
		| @@ -4,6 +4,12 @@ import { promises as fs } from 'fs'; | |||||||
| const createDockerfile = async (data, image, htaccessFound): Promise<void> => { | const createDockerfile = async (data, image, htaccessFound): Promise<void> => { | ||||||
| 	const { workdir, baseDirectory } = data; | 	const { workdir, baseDirectory } = data; | ||||||
| 	const Dockerfile: Array<string> = []; | 	const Dockerfile: Array<string> = []; | ||||||
|  | 	let composerFound = false; | ||||||
|  | 	try { | ||||||
|  | 		await fs.readFile(`${workdir}${baseDirectory || ''}/composer.json`); | ||||||
|  | 		composerFound = true; | ||||||
|  | 	} catch (error) {} | ||||||
|  |  | ||||||
| 	Dockerfile.push(`FROM ${image}`); | 	Dockerfile.push(`FROM ${image}`); | ||||||
| 	Dockerfile.push(`LABEL coolify.image=true`); | 	Dockerfile.push(`LABEL coolify.image=true`); | ||||||
| 	Dockerfile.push('WORKDIR /app'); | 	Dockerfile.push('WORKDIR /app'); | ||||||
| @@ -11,6 +17,10 @@ const createDockerfile = async (data, image, htaccessFound): Promise<void> => { | |||||||
| 	if (htaccessFound) { | 	if (htaccessFound) { | ||||||
| 		Dockerfile.push(`COPY .${baseDirectory || ''}/.htaccess ./`); | 		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(`COPY /entrypoint.sh /opt/docker/provision/entrypoint.d/30-entrypoint.sh`); | ||||||
| 	Dockerfile.push(`EXPOSE 80`); | 	Dockerfile.push(`EXPOSE 80`); | ||||||
| 	await fs.writeFile(`${workdir}/Dockerfile`, Dockerfile.join('\n')); | 	await fs.writeFile(`${workdir}/Dockerfile`, Dockerfile.join('\n')); | ||||||
| @@ -21,12 +31,14 @@ export default async function (data) { | |||||||
| 	try { | 	try { | ||||||
| 		let htaccessFound = false; | 		let htaccessFound = false; | ||||||
| 		try { | 		try { | ||||||
| 			const d = await fs.readFile(`${workdir}${baseDirectory || ''}/.htaccess`); | 			await fs.readFile(`${workdir}${baseDirectory || ''}/.htaccess`); | ||||||
| 			htaccessFound = true; | 			htaccessFound = true; | ||||||
| 		} catch (e) { | 		} catch (e) { | ||||||
| 			// | 			// | ||||||
| 		} | 		} | ||||||
| 		const image = htaccessFound ? 'webdevops/php-apache' : 'webdevops/php-nginx'; | 		const image = htaccessFound | ||||||
|  | 			? 'webdevops/php-apache:8.0-alpine' | ||||||
|  | 			: 'webdevops/php-nginx:8.0-alpine'; | ||||||
| 		await createDockerfile(data, image, htaccessFound); | 		await createDockerfile(data, image, htaccessFound); | ||||||
| 		await buildImage(data); | 		await buildImage(data); | ||||||
| 	} catch (error) { | 	} catch (error) { | ||||||
|   | |||||||
| @@ -81,6 +81,9 @@ | |||||||
| 				); | 				); | ||||||
| 				const indexHtml = files.find((file) => file.name === 'index.html' && file.type === 'blob'); | 				const indexHtml = files.find((file) => file.name === 'index.html' && file.type === 'blob'); | ||||||
| 				const indexPHP = files.find((file) => file.name === 'index.php' && file.type === 'blob'); | 				const indexPHP = files.find((file) => file.name === 'index.php' && file.type === 'blob'); | ||||||
|  | 				const composerPHP = files.find( | ||||||
|  | 					(file) => file.name === 'composer.json' && file.type === 'blob' | ||||||
|  | 				); | ||||||
|  |  | ||||||
| 				if (yarnLock) packageManager = 'yarn'; | 				if (yarnLock) packageManager = 'yarn'; | ||||||
| 				if (pnpmLock) packageManager = 'pnpm'; | 				if (pnpmLock) packageManager = 'pnpm'; | ||||||
| @@ -103,7 +106,7 @@ | |||||||
| 					foundConfig = findBuildPack('python'); | 					foundConfig = findBuildPack('python'); | ||||||
| 				} else if (indexHtml) { | 				} else if (indexHtml) { | ||||||
| 					foundConfig = findBuildPack('static', packageManager); | 					foundConfig = findBuildPack('static', packageManager); | ||||||
| 				} else if (indexPHP) { | 				} else if (indexPHP || composerPHP) { | ||||||
| 					foundConfig = findBuildPack('php'); | 					foundConfig = findBuildPack('php'); | ||||||
| 				} else { | 				} else { | ||||||
| 					foundConfig = findBuildPack('node', packageManager); | 					foundConfig = findBuildPack('node', packageManager); | ||||||
| @@ -127,6 +130,9 @@ | |||||||
| 				); | 				); | ||||||
| 				const indexHtml = files.find((file) => file.name === 'index.html' && file.type === 'file'); | 				const indexHtml = files.find((file) => file.name === 'index.html' && file.type === 'file'); | ||||||
| 				const indexPHP = files.find((file) => file.name === 'index.php' && file.type === 'file'); | 				const indexPHP = files.find((file) => file.name === 'index.php' && file.type === 'file'); | ||||||
|  | 				const composerPHP = files.find( | ||||||
|  | 					(file) => file.name === 'composer.json' && file.type === 'file' | ||||||
|  | 				); | ||||||
|  |  | ||||||
| 				if (yarnLock) packageManager = 'yarn'; | 				if (yarnLock) packageManager = 'yarn'; | ||||||
| 				if (pnpmLock) packageManager = 'pnpm'; | 				if (pnpmLock) packageManager = 'pnpm'; | ||||||
| @@ -146,7 +152,7 @@ | |||||||
| 					foundConfig = findBuildPack('python'); | 					foundConfig = findBuildPack('python'); | ||||||
| 				} else if (indexHtml) { | 				} else if (indexHtml) { | ||||||
| 					foundConfig = findBuildPack('static', packageManager); | 					foundConfig = findBuildPack('static', packageManager); | ||||||
| 				} else if (indexPHP) { | 				} else if (indexPHP || composerPHP) { | ||||||
| 					foundConfig = findBuildPack('php'); | 					foundConfig = findBuildPack('php'); | ||||||
| 				} else { | 				} else { | ||||||
| 					foundConfig = findBuildPack('node', packageManager); | 					foundConfig = findBuildPack('node', packageManager); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Andras Bacsai
					Andras Bacsai