Merge pull request #400 from coollabsio/next

v2.6.1
This commit is contained in:
Andras Bacsai 2022-05-03 11:41:51 +02:00 committed by GitHub
commit 030cb124e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 89 additions and 8 deletions

View File

@ -56,6 +56,7 @@ ### Applications
- Gatsby
- Svelte
- PHP
- Laravel
- Rust
- Docker
@ -85,6 +86,8 @@ ### One-click services
- [Uptime Kuma](https://github.com/louislam/uptime-kuma)
- [MeiliSearch](https://github.com/meilisearch/meilisearch)
- [Umami](https://github.com/mikecao/umami)
- [Fider](https://fider.io)
- [Hasura](https://hasura.io)
## Migration from v1

View File

@ -1,7 +1,7 @@
{
"name": "coolify",
"description": "An open-source & self-hostable Heroku / Netlify alternative.",
"version": "2.6.0",
"version": "2.6.1",
"license": "AGPL-3.0",
"scripts": {
"dev": "docker-compose -f docker-compose-dev.yaml up -d && cross-env NODE_ENV=development & svelte-kit dev --host 0.0.0.0",

View File

@ -290,3 +290,28 @@ export async function generateSSLCerts(): Promise<void> {
}
}
}
export async function renewSSLCerts(): Promise<void> {
const host = 'unix:///var/run/docker.sock';
await asyncExecShell(`docker pull alpine:latest`);
const certbotImage =
process.arch === 'x64' ? 'certbot/certbot' : 'certbot/certbot:arm64v8-latest';
const { stdout: certificates } = await asyncExecShell(
`DOCKER_HOST=${host} docker run --rm -v "coolify-letsencrypt:/etc/letsencrypt" -v "coolify-ssl-certs:/app/ssl" alpine:latest sh -c "ls -1 /etc/letsencrypt/live/ | grep -v README"`
);
for (const certificate of certificates.trim().split('\n')) {
try {
await asyncExecShell(
`DOCKER_HOST=${host} docker run --rm --name certbot-renewal -p 9080:9080 -v "coolify-letsencrypt:/etc/letsencrypt" ${certbotImage} --cert-name ${certificate} --logs-dir /etc/letsencrypt/logs renew --standalone --preferred-challenges http --http-01-address 0.0.0.0 --http-01-port 9080`
);
await asyncExecShell(
`DOCKER_HOST=${host} docker run --rm -v "coolify-letsencrypt:/etc/letsencrypt" -v "coolify-ssl-certs:/app/ssl" alpine:latest sh -c "test -d /etc/letsencrypt/live/${certificate}/ && cat /etc/letsencrypt/live/${certificate}/fullchain.pem /etc/letsencrypt/live/${certificate}/privkey.pem > /app/ssl/${certificate}.pem"`
);
} catch (error) {
console.log(error);
}
}
await reloadHaproxy('unix:///var/run/docker.sock');
}

View File

@ -116,7 +116,7 @@ const cron = async (): Promise<void> => {
await queue.proxyTcpHttp.add('proxyTcpHttp', {}, { repeat: { every: 10000 } });
await queue.ssl.add('ssl', {}, { repeat: { every: dev ? 10000 : 60000 } });
if (!dev) await queue.cleanup.add('cleanup', {}, { repeat: { every: 300000 } });
await queue.sslRenew.add('sslRenew', {}, { repeat: { every: 1800000 } });
if (!dev) await queue.sslRenew.add('sslRenew', {}, { repeat: { every: 1800000 } });
await queue.autoUpdater.add('autoUpdater', {}, { repeat: { every: 60000 } });
};
cron().catch((error) => {

View File

@ -1,9 +1,10 @@
import { asyncExecShell } from '$lib/common';
import { reloadHaproxy } from '$lib/haproxy';
import { renewSSLCerts } from '$lib/letsencrypt';
export default async function (): Promise<void> {
await asyncExecShell(
`docker run --rm --name certbot-renewal -v "coolify-letsencrypt:/etc/letsencrypt" certbot/certbot --logs-dir /etc/letsencrypt/logs renew`
);
await reloadHaproxy('unix:///var/run/docker.sock');
try {
return await renewSSLCerts();
} catch (error) {
console.log(error);
throw error;
}
}

View File

@ -111,6 +111,14 @@
loading.save = false;
}
}
async function renewCerts() {
try {
toast.push('Renewing certificates...');
return await post(`/settings/renew.json`, {});
} catch ({ error }) {
return errorNotification(error);
}
}
</script>
<div class="flex space-x-1 p-6 font-bold">
@ -219,6 +227,19 @@
on:click={() => changeSettings('isAutoUpdateEnabled')}
/>
</div>
<div class="grid grid-cols-2 items-center">
<div class="flex flex-col">
<div class="pt-2 text-base font-bold text-stone-100">
Renew SSL Certificates manually
</div>
<Explainer text="It will check and renew certificates manually" />
</div>
<div class="mx-auto ">
<button class="w-32 bg-coollabs hover:bg-coollabs-100" on:click={renewCerts}
>SSL renew manually</button
>
</div>
</div>
{/if}
</div>
</form>

View File

@ -0,0 +1,26 @@
import { getUserDetails } from '$lib/common';
import { ErrorHandler } from '$lib/database';
import { renewSSLCerts } from '$lib/letsencrypt';
import { t } from '$lib/translations';
import type { RequestHandler } from '@sveltejs/kit';
export const post: RequestHandler = async (event) => {
const { teamId, status, body } = await getUserDetails(event);
if (teamId !== '0')
return {
status: 401,
body: {
message: t.get('setting.permission_denied')
}
};
if (status === 401) return { status, body };
try {
renewSSLCerts();
return {
status: 201
};
} catch (error) {
return ErrorHandler(error);
}
};

View File

@ -2,6 +2,7 @@ import { dev } from '$app/env';
import { asyncExecShell, version } from '$lib/common';
import { asyncSleep } from '$lib/components/common';
import { ErrorHandler } from '$lib/database';
import * as db from '$lib/database';
import type { RequestHandler } from '@sveltejs/kit';
import compare from 'compare-versions';
import got from 'got';
@ -36,8 +37,12 @@ export const post: RequestHandler = async (event) => {
if (type === 'update') {
try {
if (!dev) {
const { isAutoUpdateEnabled } = await db.prisma.setting.findFirst();
await asyncExecShell(`docker pull coollabsio/coolify:${latestVersion}`);
await asyncExecShell(`env | grep COOLIFY > .env`);
await asyncExecShell(
`sed -i '/COOLIFY_AUTO_UPDATE=/c\COOLIFY_AUTO_UPDATE=${isAutoUpdateEnabled}' .env`
);
await asyncExecShell(
`docker run --rm -tid --env-file .env -v /var/run/docker.sock:/var/run/docker.sock -v coolify-db coollabsio/coolify:${latestVersion} /bin/sh -c "env | grep COOLIFY > .env && echo 'TAG=${latestVersion}' >> .env && docker stop -t 0 coolify coolify-redis && docker rm coolify coolify-redis && docker compose up -d --force-recreate"`
);