fixes related to docker-compose

This commit is contained in:
Andras Bacsai 2023-01-16 09:44:08 +01:00
parent 5cb9216add
commit 18064ef6a2
11 changed files with 48 additions and 30 deletions

View File

@ -601,6 +601,7 @@ import * as buildpacks from '../lib/buildPacks';
}
if (buildPack === 'compose') {
const fileYaml = `${workdir}${baseDirectory}${dockerComposeFileLocation}`;
try {
const { stdout: containers } = await executeCommand({
dockerId: destinationDockerId,
@ -630,7 +631,7 @@ import * as buildpacks from '../lib/buildPacks';
buildId,
applicationId,
dockerId: destinationDocker.id,
command: `docker compose --project-directory ${workdir} up -d`
command: `docker compose --project-directory ${workdir} -f ${fileYaml} up -d`
});
await saveBuildLog({ line: 'Deployed 🎉', buildId, applicationId });
await prisma.build.update({

View File

@ -43,7 +43,10 @@ export default async function (data) {
let networks = {};
for (let [key, value] of Object.entries(dockerComposeYaml.services)) {
value['container_name'] = `${applicationId}-${key}`;
let environment = typeof value['environment'] === 'undefined' ? [] : value['environment']
let environment = typeof value['environment'] === 'undefined' ? [] : value['environment'];
if (Object.keys(environment).length > 0) {
environment = Object.entries(environment).map(([key, value]) => `${key}=${value}`);
}
value['environment'] = [...environment, ...envs];
value['labels'] = labels;
// TODO: If we support separated volume for each service, we need to add it here
@ -95,7 +98,7 @@ export default async function (data) {
buildId,
applicationId,
dockerId,
command: `docker compose --project-directory ${workdir} pull`
command: `docker compose --project-directory ${workdir} -f ${fileYaml} pull`
});
await saveBuildLog({ line: 'Pulling images from Compose file...', buildId, applicationId });
await executeCommand({
@ -103,7 +106,7 @@ export default async function (data) {
buildId,
applicationId,
dockerId,
command: `docker compose --project-directory ${workdir} build --progress plain`
command: `docker compose --project-directory ${workdir} -f ${fileYaml} build --progress plain`
});
await saveBuildLog({ line: 'Building images from Compose file...', buildId, applicationId });
}

View File

@ -351,13 +351,17 @@
}
async function reloadCompose() {
if (loading.reloadCompose) return;
if (!$appSession.tokens.github) {
const { token } = await get(`/applications/${id}/configuration/githubToken`);
$appSession.tokens.github = token;
}
loading.reloadCompose = true;
try {
if (application.gitSource.type === 'github') {
const composeLocation = application.dockerComposeFileLocation.startsWith('/')
? application.dockerComposeFileLocation
: `/${application.dockerComposeFileLocation}`;
? application.dockerComposeFileLocation
: `/${application.dockerComposeFileLocation}`;
const headers = isPublicRepository
? {}
: {
@ -384,17 +388,17 @@
if (!$appSession.tokens.gitlab) {
await getGitlabToken();
}
const composeLocation = application.dockerComposeFileLocation.startsWith('/')
? application.dockerComposeFileLocation.substring(1) // Remove the '/' from the start
: application.dockerComposeFileLocation;
? application.dockerComposeFileLocation.substring(1) // Remove the '/' from the start
: application.dockerComposeFileLocation;
// If the file is in a subdirectory, lastIndex will be > 0
// Otherwise it will be -1 and path will be an empty string
const lastIndex = composeLocation.lastIndexOf('/') + 1
const path = composeLocation.substring(0, lastIndex)
const fileName = composeLocation.substring(lastIndex)
const lastIndex = composeLocation.lastIndexOf('/') + 1;
const path = composeLocation.substring(0, lastIndex);
const fileName = composeLocation.substring(lastIndex);
const headers = isPublicRepository
? {}
: {
@ -407,8 +411,7 @@
...headers
});
const dockerComposeFileYml = files.find(
(file: { name: string; type: string }) =>
file.name === fileName && file.type === 'blob'
(file: { name: string; type: string }) => file.name === fileName && file.type === 'blob'
);
const id = dockerComposeFileYml.id;

View File

@ -21,7 +21,7 @@
onMount(async () => {
const { data } = await trpc.applications.getApplicationById.query({ id });
application = data;
if (data.dockerComposeFile) {
if (application.dockerComposeFile && application.buildPack === 'compose') {
services = normalizeDockerServices(JSON.parse(data.dockerComposeFile).services);
} else {
services = [

View File

@ -55,7 +55,7 @@
clearInterval(usageInterval);
});
onMount(async () => {
if (application.dockerComposeFile) {
if (application.dockerComposeFile && application.buildPack === 'compose') {
services = normalizeDockerServices(JSON.parse(application.dockerComposeFile).services);
} else {
services = [

View File

@ -640,6 +640,7 @@ import { defaultComposeConfiguration } from '../lib/docker';
}
if (buildPack === 'compose') {
const fileYaml = `${workdir}${baseDirectory}${dockerComposeFileLocation}`;
try {
const { stdout: containers } = await executeCommand({
dockerId: destinationDockerId,
@ -669,7 +670,7 @@ import { defaultComposeConfiguration } from '../lib/docker';
buildId,
applicationId,
dockerId: destinationDocker.id,
command: `docker compose --project-directory ${workdir} up -d`
command: `docker compose --project-directory ${workdir} -f ${fileYaml} up -d`
});
await saveBuildLog({ line: 'Deployed 🎉', buildId, applicationId });
await prisma.build.update({

View File

@ -1,7 +1,7 @@
import { promises as fs } from 'fs';
import { generateSecrets } from '../common';
import { saveBuildLog } from './common';
import yaml from 'js-yaml';
import { generateSecrets } from '../common';
import { defaultComposeConfiguration } from '../docker';
import { executeCommand } from '../executeCommand';
@ -45,7 +45,10 @@ export default async function (data) {
let networks = {};
for (let [key, value] of Object.entries(dockerComposeYaml.services)) {
value['container_name'] = `${applicationId}-${key}`;
let environment = typeof value['environment'] === 'undefined' ? [] : value['environment']
let environment = typeof value['environment'] === 'undefined' ? [] : value['environment'];
if (Object.keys(environment).length > 0) {
environment = Object.entries(environment).map(([key, value]) => `${key}=${value}`);
}
value['environment'] = [...environment, ...envs];
value['labels'] = labels;
// TODO: If we support separated volume for each service, we need to add it here
@ -97,7 +100,7 @@ export default async function (data) {
buildId,
applicationId,
dockerId,
command: `docker compose --project-directory ${workdir} pull`
command: `docker compose --project-directory ${workdir} -f ${fileYaml} pull`
});
await saveBuildLog({ line: 'Pulling images from Compose file...', buildId, applicationId });
await executeCommand({
@ -105,7 +108,7 @@ export default async function (data) {
buildId,
applicationId,
dockerId,
command: `docker compose --project-directory ${workdir} build --progress plain`
command: `docker compose --project-directory ${workdir} -f ${fileYaml} build --progress plain`
});
await saveBuildLog({ line: 'Building images from Compose file...', buildId, applicationId });
}

View File

@ -28,12 +28,15 @@
delete tempBuildPack.fancyName;
delete tempBuildPack.color;
delete tempBuildPack.hoverColor;
let composeConfiguration: any = {}
if (!dockerComposeConfiguration && dockerComposeFile) {
for (const [name, _] of Object.entries(JSON.parse(dockerComposeFile).services)) {
let composeConfiguration: any = {};
if (!dockerComposeConfiguration && dockerComposeFile && buildPack.name === 'compose') {
const parsed = JSON.parse(dockerComposeFile);
if (!parsed?.services) {
throw new Error('No services found in docker-compose file. <br>Choose a different buildpack.');
}
for (const [name, _] of Object.entries(parsed.services)) {
composeConfiguration[name] = {};
}
}
await post(`/applications/${id}`, {
...tempBuildPack,

View File

@ -366,6 +366,10 @@
async function reloadCompose() {
if (loading.reloadCompose) return;
loading.reloadCompose = true;
if (!$appSession.tokens.github) {
const { token } = await get(`/applications/${id}/configuration/githubToken`);
$appSession.tokens.github = token;
}
try {
if (application.gitSource.type === 'github') {
const composeLocation = application.dockerComposeFileLocation.startsWith('/')

View File

@ -21,7 +21,7 @@
onMount(async () => {
const response = await get(`/applications/${id}`);
application = response.application;
if (response.application.dockerComposeFile) {
if (response.application.dockerComposeFile && application.buildPack === 'compose') {
services = normalizeDockerServices(
JSON.parse(response.application.dockerComposeFile).services
);

View File

@ -55,7 +55,7 @@
onMount(async () => {
const response = await get(`/applications/${id}`);
application = response.application;
if (response.application.dockerComposeFile) {
if (response.application.dockerComposeFile && application.buildPack === 'compose') {
services = normalizeDockerServices(
JSON.parse(response.application.dockerComposeFile).services
);