From eae1ea21d6d6e33061e76fcc282bdf357eebb9c8 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Sun, 20 Mar 2022 15:03:24 +0100 Subject: [PATCH] fix: Add nginx + htaccess files --- src/lib/buildPacks/gatsby.ts | 1 + src/lib/buildPacks/php.ts | 1 + src/lib/buildPacks/react.ts | 1 + src/lib/buildPacks/static.ts | 1 + src/lib/buildPacks/svelte.ts | 1 + src/lib/buildPacks/vuejs.ts | 16 ++++++++++++++++ src/lib/queues/builder.ts | 7 ++++++- 7 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/lib/buildPacks/gatsby.ts b/src/lib/buildPacks/gatsby.ts index 9f2685ff0..3e9c34a2d 100644 --- a/src/lib/buildPacks/gatsby.ts +++ b/src/lib/buildPacks/gatsby.ts @@ -9,6 +9,7 @@ const createDockerfile = async (data, imageforBuild): Promise => { Dockerfile.push('WORKDIR /usr/share/nginx/html'); Dockerfile.push(`LABEL coolify.image=true`); Dockerfile.push(`COPY --from=${applicationId}:${tag}-cache /usr/src/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')); diff --git a/src/lib/buildPacks/php.ts b/src/lib/buildPacks/php.ts index 3d3bee7b9..4903213c6 100644 --- a/src/lib/buildPacks/php.ts +++ b/src/lib/buildPacks/php.ts @@ -16,6 +16,7 @@ const createDockerfile = async (data, image): Promise => { Dockerfile.push('RUN a2enmod rewrite'); Dockerfile.push('WORKDIR /var/www/html'); Dockerfile.push(`COPY .${baseDirectory || ''} /var/www/html`); + Dockerfile.push(`COPY /.htaccess /var/www/html/.htaccess`); Dockerfile.push(`EXPOSE 80`); Dockerfile.push('CMD ["apache2-foreground"]'); Dockerfile.push('RUN chown -R www-data /var/www/html'); diff --git a/src/lib/buildPacks/react.ts b/src/lib/buildPacks/react.ts index 5db9c33b2..29c462d02 100644 --- a/src/lib/buildPacks/react.ts +++ b/src/lib/buildPacks/react.ts @@ -9,6 +9,7 @@ const createDockerfile = async (data, image): Promise => { Dockerfile.push(`LABEL coolify.image=true`); Dockerfile.push('WORKDIR /usr/share/nginx/html'); Dockerfile.push(`COPY --from=${applicationId}:${tag}-cache /usr/src/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')); diff --git a/src/lib/buildPacks/static.ts b/src/lib/buildPacks/static.ts index 795f00d7b..075fad0aa 100644 --- a/src/lib/buildPacks/static.ts +++ b/src/lib/buildPacks/static.ts @@ -39,6 +39,7 @@ const createDockerfile = async (data, image): Promise => { } else { Dockerfile.push(`COPY .${baseDirectory || ''} ./`); } + 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')); diff --git a/src/lib/buildPacks/svelte.ts b/src/lib/buildPacks/svelte.ts index 3ce957a1b..e6821dafe 100644 --- a/src/lib/buildPacks/svelte.ts +++ b/src/lib/buildPacks/svelte.ts @@ -9,6 +9,7 @@ const createDockerfile = async (data, image): Promise => { Dockerfile.push('WORKDIR /usr/share/nginx/html'); Dockerfile.push(`LABEL coolify.image=true`); Dockerfile.push(`COPY --from=${applicationId}:${tag}-cache /usr/src/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')); diff --git a/src/lib/buildPacks/vuejs.ts b/src/lib/buildPacks/vuejs.ts index f88f4ac2a..4fe90038b 100644 --- a/src/lib/buildPacks/vuejs.ts +++ b/src/lib/buildPacks/vuejs.ts @@ -9,6 +9,7 @@ const createDockerfile = async (data, image): Promise => { Dockerfile.push('WORKDIR /usr/share/nginx/html'); Dockerfile.push(`LABEL coolify.image=true`); Dockerfile.push(`COPY --from=${applicationId}:${tag}-cache /usr/src/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')); @@ -19,6 +20,21 @@ export default async function (data) { const image = 'nginx:stable-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 5f2aa80aa..f0617d328 100644 --- a/src/lib/queues/builder.ts +++ b/src/lib/queues/builder.ts @@ -56,7 +56,12 @@ export default async function (job) { await asyncSleep(1000); await db.prisma.build.updateMany({ - where: { status: 'queued', id: { not: buildId }, applicationId }, + where: { + status: 'queued', + id: { not: buildId }, + applicationId, + createdAt: { lt: new Date(new Date().getTime() - 60 * 60 * 1000) } + }, data: { status: 'failed' } }); let imageId = applicationId;