feat: deploy specific commit for apps

feat: keep number of images locally to revert quickly
This commit is contained in:
Andras Bacsai
2022-11-29 11:47:20 +01:00
parent ec00548f1b
commit 028ee6d7b1
9 changed files with 117 additions and 23 deletions

View File

@@ -65,6 +65,7 @@ import * as buildpacks from '../lib/buildPacks';
baseImage,
baseBuildImage,
deploymentType,
gitCommitHash,
} = application
let {
@@ -169,7 +170,7 @@ import * as buildpacks from '../lib/buildPacks';
githubAppId: gitSource.githubApp?.id,
gitlabAppId: gitSource.gitlabApp?.id,
customPort: gitSource.customPort,
gitCommitHash: gitCommitHash,
gitCommitHash,
configuration,
repository,
branch,

View File

@@ -635,7 +635,6 @@ export async function buildImage({
const cache = `${applicationId}:${tag}${isCache ? '-cache' : ''}`
const { dockerRegistry: { url, username, password } } = await prisma.application.findUnique({ where: { id: applicationId }, select: { dockerRegistry: true } })
const location = await saveDockerRegistryCredentials({ url, username, password, workdir })
console.log(`docker ${location ? `--config ${location}` : ''} build --progress plain -f ${workdir}/${dockerFile} -t ${cache} --build-arg SOURCE_COMMIT=${commit} ${workdir}`)
await executeDockerCmd({ debug, buildId, applicationId, dockerId, command: `docker ${location ? `--config ${location}` : ''} build --progress plain -f ${workdir}/${dockerFile} -t ${cache} --build-arg SOURCE_COMMIT=${commit} ${workdir}` })

View File

@@ -1587,22 +1587,44 @@ export async function cleanupDockerStorage(dockerId, lowDiskSpace, force) {
}
} catch (error) { }
if (lowDiskSpace || force) {
// if (isDev) {
// if (!force) console.log(`[DEV MODE] Low disk space: ${lowDiskSpace}`);
// return;
// }
// Cleanup images that are not used
try {
await executeDockerCmd({ dockerId, command: `docker image prune -f` });
} catch (error) { }
const { numberOfDockerImagesKeptLocally } = await prisma.setting.findUnique({ where: { id: '0' } })
const { stdout: images } = await executeDockerCmd({
dockerId,
command: `docker images | grep -v "<none>" | grep -v REPOSITORY | awk '{print $1, $2}'`
});
const imagesArray = images.trim().replaceAll(' ', ':').split('\n');
const imagesSet = new Set(imagesArray.map((image) => image.split(':')[0]));
let deleteImage = []
for (const image of imagesSet) {
let keepImage = []
for (const image2 of imagesArray) {
if (image2.startsWith(image)) {
if (keepImage.length >= numberOfDockerImagesKeptLocally) {
deleteImage.push(image2)
} else {
keepImage.push(image2)
}
}
}
}
for (const image of deleteImage) {
await executeDockerCmd({ dockerId, command: `docker image rm -f ${image}` });
}
// Prune coolify managed containers
try {
await executeDockerCmd({
dockerId,
command: `docker container prune -f --filter "label=coolify.managed=true"`
});
} catch (error) { }
try {
await executeDockerCmd({ dockerId, command: `docker image prune -f` });
} catch (error) { }
try {
await executeDockerCmd({ dockerId, command: `docker image prune -a -f` });
} catch (error) { }
// Cleanup build caches
try {
await executeDockerCmd({ dockerId, command: `docker builder prune -a -f` });

View File

@@ -53,7 +53,8 @@ export async function listAllSettings(request: FastifyRequest) {
}
export async function saveSettings(request: FastifyRequest<SaveSettings>, reply: FastifyReply) {
try {
const {
let {
numberOfDockerImagesKeptLocally,
doNotTrack,
fqdn,
isAPIDebuggingEnabled,
@@ -67,9 +68,12 @@ export async function saveSettings(request: FastifyRequest<SaveSettings>, reply:
proxyDefaultRedirect
} = request.body
const { id } = await listSettings();
if (numberOfDockerImagesKeptLocally) {
numberOfDockerImagesKeptLocally = Number(numberOfDockerImagesKeptLocally)
}
await prisma.setting.update({
where: { id },
data: { doNotTrack, isRegistrationEnabled, dualCerts, isAutoUpdateEnabled, isDNSCheckEnabled, DNSServers, isAPIDebuggingEnabled, }
data: { numberOfDockerImagesKeptLocally, doNotTrack, isRegistrationEnabled, dualCerts, isAutoUpdateEnabled, isDNSCheckEnabled, DNSServers, isAPIDebuggingEnabled, }
});
if (fqdn) {
await prisma.setting.update({ where: { id }, data: { fqdn } });

View File

@@ -2,6 +2,7 @@ import { OnlyId } from "../../../../types"
export interface SaveSettings {
Body: {
numberOfDockerImagesKeptLocally: number,
doNotTrack: boolean,
fqdn: string,
isAPIDebuggingEnabled: boolean,