From 7a2f29f6a39bf64839509b782afbb70ed7e464c3 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 6 Apr 2022 13:35:53 +0200 Subject: [PATCH] feat: PHP Composer support --- src/lib/buildPacks/php.ts | 16 ++++++++++++++-- .../[id]/configuration/buildpack.svelte | 10 ++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/lib/buildPacks/php.ts b/src/lib/buildPacks/php.ts index 14ee5d0cb..cfb39d20a 100644 --- a/src/lib/buildPacks/php.ts +++ b/src/lib/buildPacks/php.ts @@ -4,6 +4,12 @@ import { promises as fs } from 'fs'; const createDockerfile = async (data, image, htaccessFound): Promise => { const { workdir, baseDirectory } = data; const Dockerfile: Array = []; + let composerFound = false; + try { + await fs.readFile(`${workdir}${baseDirectory || ''}/composer.json`); + composerFound = true; + } catch (error) {} + Dockerfile.push(`FROM ${image}`); Dockerfile.push(`LABEL coolify.image=true`); Dockerfile.push('WORKDIR /app'); @@ -11,6 +17,10 @@ const createDockerfile = async (data, image, htaccessFound): Promise => { 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 80`); await fs.writeFile(`${workdir}/Dockerfile`, Dockerfile.join('\n')); @@ -21,12 +31,14 @@ export default async function (data) { try { let htaccessFound = false; try { - const d = await fs.readFile(`${workdir}${baseDirectory || ''}/.htaccess`); + await fs.readFile(`${workdir}${baseDirectory || ''}/.htaccess`); htaccessFound = true; } 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 buildImage(data); } catch (error) { diff --git a/src/routes/applications/[id]/configuration/buildpack.svelte b/src/routes/applications/[id]/configuration/buildpack.svelte index cd005768c..c885f3bf5 100644 --- a/src/routes/applications/[id]/configuration/buildpack.svelte +++ b/src/routes/applications/[id]/configuration/buildpack.svelte @@ -81,6 +81,9 @@ ); 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 composerPHP = files.find( + (file) => file.name === 'composer.json' && file.type === 'blob' + ); if (yarnLock) packageManager = 'yarn'; if (pnpmLock) packageManager = 'pnpm'; @@ -103,7 +106,7 @@ foundConfig = findBuildPack('python'); } else if (indexHtml) { foundConfig = findBuildPack('static', packageManager); - } else if (indexPHP) { + } else if (indexPHP || composerPHP) { foundConfig = findBuildPack('php'); } else { foundConfig = findBuildPack('node', packageManager); @@ -127,6 +130,9 @@ ); 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 composerPHP = files.find( + (file) => file.name === 'composer.json' && file.type === 'file' + ); if (yarnLock) packageManager = 'yarn'; if (pnpmLock) packageManager = 'pnpm'; @@ -146,7 +152,7 @@ foundConfig = findBuildPack('python'); } else if (indexHtml) { foundConfig = findBuildPack('static', packageManager); - } else if (indexPHP) { + } else if (indexPHP || composerPHP) { foundConfig = findBuildPack('php'); } else { foundConfig = findBuildPack('node', packageManager);