From f5e7a84fa6241c66dea85e400bfc59bb707d72ab Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 21 Mar 2022 21:25:01 +0100 Subject: [PATCH] Update buildpacks for static sites --- src/lib/buildPacks/common.ts | 28 ++++++++++++++++++---------- src/lib/buildPacks/gatsby.ts | 5 ++--- src/lib/buildPacks/php.ts | 4 ---- src/lib/buildPacks/react.ts | 5 ++--- src/lib/buildPacks/static.ts | 5 ++--- src/lib/buildPacks/svelte.ts | 5 ++--- src/lib/buildPacks/vuejs.ts | 20 ++------------------ src/lib/queues/builder.ts | 5 +---- 8 files changed, 29 insertions(+), 48 deletions(-) diff --git a/src/lib/buildPacks/common.ts b/src/lib/buildPacks/common.ts index b1c02867b..9ded4e0f9 100644 --- a/src/lib/buildPacks/common.ts +++ b/src/lib/buildPacks/common.ts @@ -143,27 +143,35 @@ export async function copyBaseConfigurationFiles(buildPack, workdir, buildId, ap `user nginx; worker_processes auto; - error_log /var/log/nginx/error.log warn; - pid /var/run/nginx.pid; + error_log /docker.stdout; + pid /run/nginx.pid; events { worker_connections 1024; } http { - include /etc/nginx/mime.types; - - access_log off; - sendfile on; - #tcp_nopush on; - keepalive_timeout 65; + 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 /usr/share/nginx/html; + root /app; index index.html; try_files $uri $uri/index.html $uri/ /index.html =404; } @@ -174,7 +182,7 @@ export async function copyBaseConfigurationFiles(buildPack, workdir, buildId, ap # error_page 500 502 503 504 /50x.html; location = /50x.html { - root /usr/share/nginx/html; + root /app; } } diff --git a/src/lib/buildPacks/gatsby.ts b/src/lib/buildPacks/gatsby.ts index a721af128..38989626d 100644 --- a/src/lib/buildPacks/gatsby.ts +++ b/src/lib/buildPacks/gatsby.ts @@ -6,18 +6,17 @@ const createDockerfile = async (data, imageforBuild): Promise => { const Dockerfile: Array = []; Dockerfile.push(`FROM ${imageforBuild}`); - Dockerfile.push('WORKDIR /usr/share/nginx/html'); + Dockerfile.push('WORKDIR /app'); Dockerfile.push(`LABEL coolify.image=true`); Dockerfile.push(`COPY --from=${applicationId}:${tag}-cache /app/${publishDirectory} ./`); Dockerfile.push(`COPY /nginx.conf /etc/nginx/nginx.conf`); Dockerfile.push(`EXPOSE 80`); - Dockerfile.push('CMD ["nginx", "-g", "daemon off;"]'); await fs.writeFile(`${workdir}/Dockerfile`, Dockerfile.join('\n')); }; export default async function (data) { try { - const image = 'nginx:stable-alpine'; + const image = 'webdevops/nginx:alpine'; const imageForBuild = 'node:lts'; await buildCacheImageWithNode(data, imageForBuild); diff --git a/src/lib/buildPacks/php.ts b/src/lib/buildPacks/php.ts index 8b9617845..0db2dd063 100644 --- a/src/lib/buildPacks/php.ts +++ b/src/lib/buildPacks/php.ts @@ -13,10 +13,6 @@ const createDockerfile = async (data, image): Promise => { 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('RUN a2enmod rewrite'); - // Dockerfile.push(`ENV APACHE_DOCUMENT_ROOT /app`); - // Dockerfile.push(`RUN sed -ri -e 's!/var/www/html!/app!g' /etc/apache2/sites-available/*.conf`); - // Dockerfile.push(`RUN sed -ri -e 's!/var/www/!/app!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf`) Dockerfile.push('WORKDIR /app'); Dockerfile.push(`COPY .${baseDirectory || ''} /app`); Dockerfile.push(`COPY /.htaccess .`); diff --git a/src/lib/buildPacks/react.ts b/src/lib/buildPacks/react.ts index 3e372b776..719f782eb 100644 --- a/src/lib/buildPacks/react.ts +++ b/src/lib/buildPacks/react.ts @@ -7,17 +7,16 @@ const createDockerfile = async (data, image): Promise => { Dockerfile.push(`FROM ${image}`); Dockerfile.push(`LABEL coolify.image=true`); - Dockerfile.push('WORKDIR /usr/share/nginx/html'); + Dockerfile.push('WORKDIR /app'); Dockerfile.push(`COPY --from=${applicationId}:${tag}-cache /app/${publishDirectory} ./`); Dockerfile.push(`COPY /nginx.conf /etc/nginx/nginx.conf`); Dockerfile.push(`EXPOSE 80`); - Dockerfile.push('CMD ["nginx", "-g", "daemon off;"]'); await fs.writeFile(`${workdir}/Dockerfile`, Dockerfile.join('\n')); }; export default async function (data) { try { - const image = 'nginx:stable-alpine'; + const image = 'webdevops/nginx:alpine'; const imageForBuild = 'node:lts'; await buildCacheImageWithNode(data, imageForBuild); await createDockerfile(data, image); diff --git a/src/lib/buildPacks/static.ts b/src/lib/buildPacks/static.ts index 20393ac22..17900ced3 100644 --- a/src/lib/buildPacks/static.ts +++ b/src/lib/buildPacks/static.ts @@ -15,7 +15,7 @@ const createDockerfile = async (data, image): Promise => { const Dockerfile: Array = []; Dockerfile.push(`FROM ${image}`); - Dockerfile.push('WORKDIR /usr/share/nginx/html'); + Dockerfile.push('WORKDIR /app'); Dockerfile.push(`LABEL coolify.image=true`); if (secrets.length > 0) { secrets.forEach((secret) => { @@ -39,13 +39,12 @@ const createDockerfile = async (data, image): Promise => { } Dockerfile.push(`COPY /nginx.conf /etc/nginx/nginx.conf`); Dockerfile.push(`EXPOSE 80`); - Dockerfile.push('CMD ["nginx", "-g", "daemon off;"]'); await fs.writeFile(`${workdir}/Dockerfile`, Dockerfile.join('\n')); }; export default async function (data) { try { - const image = 'nginx:stable-alpine'; + const image = 'webdevops/nginx:alpine'; const imageForBuild = 'node:lts'; if (data.buildCommand) await buildCacheImageWithNode(data, imageForBuild); await createDockerfile(data, image); diff --git a/src/lib/buildPacks/svelte.ts b/src/lib/buildPacks/svelte.ts index 181782b89..fbcf36abb 100644 --- a/src/lib/buildPacks/svelte.ts +++ b/src/lib/buildPacks/svelte.ts @@ -6,18 +6,17 @@ const createDockerfile = async (data, image): Promise => { const Dockerfile: Array = []; Dockerfile.push(`FROM ${image}`); - Dockerfile.push('WORKDIR /usr/share/nginx/html'); + Dockerfile.push('WORKDIR /app'); Dockerfile.push(`LABEL coolify.image=true`); Dockerfile.push(`COPY --from=${applicationId}:${tag}-cache /app/${publishDirectory} ./`); Dockerfile.push(`COPY /nginx.conf /etc/nginx/nginx.conf`); Dockerfile.push(`EXPOSE 80`); - Dockerfile.push('CMD ["nginx", "-g", "daemon off;"]'); await fs.writeFile(`${workdir}/Dockerfile`, Dockerfile.join('\n')); }; export default async function (data) { try { - const image = 'nginx:stable-alpine'; + const image = 'webdevops/nginx:alpine'; const imageForBuild = 'node:lts'; await buildCacheImageWithNode(data, imageForBuild); diff --git a/src/lib/buildPacks/vuejs.ts b/src/lib/buildPacks/vuejs.ts index 7953977ce..fa80ac435 100644 --- a/src/lib/buildPacks/vuejs.ts +++ b/src/lib/buildPacks/vuejs.ts @@ -6,35 +6,19 @@ const createDockerfile = async (data, image): Promise => { const Dockerfile: Array = []; Dockerfile.push(`FROM ${image}`); - Dockerfile.push('WORKDIR /usr/share/nginx/html'); + Dockerfile.push('WORKDIR /app'); Dockerfile.push(`LABEL coolify.image=true`); Dockerfile.push(`COPY --from=${applicationId}:${tag}-cache /app/${publishDirectory} ./`); Dockerfile.push(`COPY /nginx.conf /etc/nginx/nginx.conf`); Dockerfile.push(`EXPOSE 80`); - Dockerfile.push('CMD ["nginx", "-g", "daemon off;"]'); await fs.writeFile(`${workdir}/Dockerfile`, Dockerfile.join('\n')); }; export default async function (data) { try { - const image = 'nginx:stable-alpine'; + const image = 'webdevops/nginx:alpine'; const imageForBuild = 'node:lts'; await buildCacheImageWithNode(data, imageForBuild); - // await fs.writeFile(`${data.workdir}/default.conf`, `server { - // listen 80; - // server_name localhost; - - // location / { - // root /usr/share/nginx/html; - // try_files $uri $uri/ /index.html; - // } - - // error_page 500 502 503 504 /50x.html; - // location = /50x.html { - // root /usr/share/nginx/html; - // } - // } - // `); await createDockerfile(data, image); await buildImage(data); } catch (error) { diff --git a/src/lib/queues/builder.ts b/src/lib/queues/builder.ts index 18985a5fb..1cbef0f85 100644 --- a/src/lib/queues/builder.ts +++ b/src/lib/queues/builder.ts @@ -52,7 +52,6 @@ export default async function (job) { settings, persistentStorage } = job.data; - console.log(persistentStorage); const { debug } = settings; await asyncSleep(1000); @@ -68,11 +67,10 @@ export default async function (job) { }); let imageId = applicationId; let domain = getDomain(fqdn); - const isHttps = fqdn.startsWith('https://'); let volumes = persistentStorage?.map((storage) => { - return `${applicationId}-${storage.id}:${storage.path}`; + return `${applicationId}-${storage.id}:${type !== 'docker' ? '/app/' : ''}${storage.path}`; }) || []; // Previews, we need to get the source branch and set subdomain if (pullmergeRequestId) { @@ -267,7 +265,6 @@ export default async function (job) { } } volumes = volumes.map((volume) => `-v ${volume} `).join(); - console.log(volumes); const { stderr } = await asyncExecShell( `DOCKER_HOST=${host} docker run ${envFound && `--env-file=${workdir}/.env`} ${labels.join( ' '