fixes related to docker-compose
This commit is contained in:
@@ -601,6 +601,7 @@ import * as buildpacks from '../lib/buildPacks';
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (buildPack === 'compose') {
|
if (buildPack === 'compose') {
|
||||||
|
const fileYaml = `${workdir}${baseDirectory}${dockerComposeFileLocation}`;
|
||||||
try {
|
try {
|
||||||
const { stdout: containers } = await executeCommand({
|
const { stdout: containers } = await executeCommand({
|
||||||
dockerId: destinationDockerId,
|
dockerId: destinationDockerId,
|
||||||
@@ -630,7 +631,7 @@ import * as buildpacks from '../lib/buildPacks';
|
|||||||
buildId,
|
buildId,
|
||||||
applicationId,
|
applicationId,
|
||||||
dockerId: destinationDocker.id,
|
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 saveBuildLog({ line: 'Deployed 🎉', buildId, applicationId });
|
||||||
await prisma.build.update({
|
await prisma.build.update({
|
||||||
|
@@ -43,7 +43,10 @@ export default async function (data) {
|
|||||||
let networks = {};
|
let networks = {};
|
||||||
for (let [key, value] of Object.entries(dockerComposeYaml.services)) {
|
for (let [key, value] of Object.entries(dockerComposeYaml.services)) {
|
||||||
value['container_name'] = `${applicationId}-${key}`;
|
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['environment'] = [...environment, ...envs];
|
||||||
value['labels'] = labels;
|
value['labels'] = labels;
|
||||||
// TODO: If we support separated volume for each service, we need to add it here
|
// 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,
|
buildId,
|
||||||
applicationId,
|
applicationId,
|
||||||
dockerId,
|
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 saveBuildLog({ line: 'Pulling images from Compose file...', buildId, applicationId });
|
||||||
await executeCommand({
|
await executeCommand({
|
||||||
@@ -103,7 +106,7 @@ export default async function (data) {
|
|||||||
buildId,
|
buildId,
|
||||||
applicationId,
|
applicationId,
|
||||||
dockerId,
|
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 });
|
await saveBuildLog({ line: 'Building images from Compose file...', buildId, applicationId });
|
||||||
}
|
}
|
||||||
|
@@ -351,6 +351,10 @@
|
|||||||
}
|
}
|
||||||
async function reloadCompose() {
|
async function reloadCompose() {
|
||||||
if (loading.reloadCompose) return;
|
if (loading.reloadCompose) return;
|
||||||
|
if (!$appSession.tokens.github) {
|
||||||
|
const { token } = await get(`/applications/${id}/configuration/githubToken`);
|
||||||
|
$appSession.tokens.github = token;
|
||||||
|
}
|
||||||
loading.reloadCompose = true;
|
loading.reloadCompose = true;
|
||||||
try {
|
try {
|
||||||
if (application.gitSource.type === 'github') {
|
if (application.gitSource.type === 'github') {
|
||||||
@@ -391,9 +395,9 @@
|
|||||||
|
|
||||||
// If the file is in a subdirectory, lastIndex will be > 0
|
// If the file is in a subdirectory, lastIndex will be > 0
|
||||||
// Otherwise it will be -1 and path will be an empty string
|
// Otherwise it will be -1 and path will be an empty string
|
||||||
const lastIndex = composeLocation.lastIndexOf('/') + 1
|
const lastIndex = composeLocation.lastIndexOf('/') + 1;
|
||||||
const path = composeLocation.substring(0, lastIndex)
|
const path = composeLocation.substring(0, lastIndex);
|
||||||
const fileName = composeLocation.substring(lastIndex)
|
const fileName = composeLocation.substring(lastIndex);
|
||||||
|
|
||||||
const headers = isPublicRepository
|
const headers = isPublicRepository
|
||||||
? {}
|
? {}
|
||||||
@@ -407,8 +411,7 @@
|
|||||||
...headers
|
...headers
|
||||||
});
|
});
|
||||||
const dockerComposeFileYml = files.find(
|
const dockerComposeFileYml = files.find(
|
||||||
(file: { name: string; type: string }) =>
|
(file: { name: string; type: string }) => file.name === fileName && file.type === 'blob'
|
||||||
file.name === fileName && file.type === 'blob'
|
|
||||||
);
|
);
|
||||||
const id = dockerComposeFileYml.id;
|
const id = dockerComposeFileYml.id;
|
||||||
|
|
||||||
|
@@ -21,7 +21,7 @@
|
|||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
const { data } = await trpc.applications.getApplicationById.query({ id });
|
const { data } = await trpc.applications.getApplicationById.query({ id });
|
||||||
application = data;
|
application = data;
|
||||||
if (data.dockerComposeFile) {
|
if (application.dockerComposeFile && application.buildPack === 'compose') {
|
||||||
services = normalizeDockerServices(JSON.parse(data.dockerComposeFile).services);
|
services = normalizeDockerServices(JSON.parse(data.dockerComposeFile).services);
|
||||||
} else {
|
} else {
|
||||||
services = [
|
services = [
|
||||||
|
@@ -55,7 +55,7 @@
|
|||||||
clearInterval(usageInterval);
|
clearInterval(usageInterval);
|
||||||
});
|
});
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
if (application.dockerComposeFile) {
|
if (application.dockerComposeFile && application.buildPack === 'compose') {
|
||||||
services = normalizeDockerServices(JSON.parse(application.dockerComposeFile).services);
|
services = normalizeDockerServices(JSON.parse(application.dockerComposeFile).services);
|
||||||
} else {
|
} else {
|
||||||
services = [
|
services = [
|
||||||
|
@@ -640,6 +640,7 @@ import { defaultComposeConfiguration } from '../lib/docker';
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (buildPack === 'compose') {
|
if (buildPack === 'compose') {
|
||||||
|
const fileYaml = `${workdir}${baseDirectory}${dockerComposeFileLocation}`;
|
||||||
try {
|
try {
|
||||||
const { stdout: containers } = await executeCommand({
|
const { stdout: containers } = await executeCommand({
|
||||||
dockerId: destinationDockerId,
|
dockerId: destinationDockerId,
|
||||||
@@ -669,7 +670,7 @@ import { defaultComposeConfiguration } from '../lib/docker';
|
|||||||
buildId,
|
buildId,
|
||||||
applicationId,
|
applicationId,
|
||||||
dockerId: destinationDocker.id,
|
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 saveBuildLog({ line: 'Deployed 🎉', buildId, applicationId });
|
||||||
await prisma.build.update({
|
await prisma.build.update({
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import { promises as fs } from 'fs';
|
import { promises as fs } from 'fs';
|
||||||
import { generateSecrets } from '../common';
|
|
||||||
import { saveBuildLog } from './common';
|
import { saveBuildLog } from './common';
|
||||||
import yaml from 'js-yaml';
|
import yaml from 'js-yaml';
|
||||||
|
import { generateSecrets } from '../common';
|
||||||
import { defaultComposeConfiguration } from '../docker';
|
import { defaultComposeConfiguration } from '../docker';
|
||||||
import { executeCommand } from '../executeCommand';
|
import { executeCommand } from '../executeCommand';
|
||||||
|
|
||||||
@@ -45,7 +45,10 @@ export default async function (data) {
|
|||||||
let networks = {};
|
let networks = {};
|
||||||
for (let [key, value] of Object.entries(dockerComposeYaml.services)) {
|
for (let [key, value] of Object.entries(dockerComposeYaml.services)) {
|
||||||
value['container_name'] = `${applicationId}-${key}`;
|
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['environment'] = [...environment, ...envs];
|
||||||
value['labels'] = labels;
|
value['labels'] = labels;
|
||||||
// TODO: If we support separated volume for each service, we need to add it here
|
// 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,
|
buildId,
|
||||||
applicationId,
|
applicationId,
|
||||||
dockerId,
|
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 saveBuildLog({ line: 'Pulling images from Compose file...', buildId, applicationId });
|
||||||
await executeCommand({
|
await executeCommand({
|
||||||
@@ -105,7 +108,7 @@ export default async function (data) {
|
|||||||
buildId,
|
buildId,
|
||||||
applicationId,
|
applicationId,
|
||||||
dockerId,
|
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 });
|
await saveBuildLog({ line: 'Building images from Compose file...', buildId, applicationId });
|
||||||
}
|
}
|
||||||
|
@@ -28,12 +28,15 @@
|
|||||||
delete tempBuildPack.fancyName;
|
delete tempBuildPack.fancyName;
|
||||||
delete tempBuildPack.color;
|
delete tempBuildPack.color;
|
||||||
delete tempBuildPack.hoverColor;
|
delete tempBuildPack.hoverColor;
|
||||||
let composeConfiguration: any = {}
|
let composeConfiguration: any = {};
|
||||||
if (!dockerComposeConfiguration && dockerComposeFile) {
|
if (!dockerComposeConfiguration && dockerComposeFile && buildPack.name === 'compose') {
|
||||||
for (const [name, _] of Object.entries(JSON.parse(dockerComposeFile).services)) {
|
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] = {};
|
composeConfiguration[name] = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
await post(`/applications/${id}`, {
|
await post(`/applications/${id}`, {
|
||||||
...tempBuildPack,
|
...tempBuildPack,
|
||||||
|
@@ -366,6 +366,10 @@
|
|||||||
async function reloadCompose() {
|
async function reloadCompose() {
|
||||||
if (loading.reloadCompose) return;
|
if (loading.reloadCompose) return;
|
||||||
loading.reloadCompose = true;
|
loading.reloadCompose = true;
|
||||||
|
if (!$appSession.tokens.github) {
|
||||||
|
const { token } = await get(`/applications/${id}/configuration/githubToken`);
|
||||||
|
$appSession.tokens.github = token;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
if (application.gitSource.type === 'github') {
|
if (application.gitSource.type === 'github') {
|
||||||
const composeLocation = application.dockerComposeFileLocation.startsWith('/')
|
const composeLocation = application.dockerComposeFileLocation.startsWith('/')
|
||||||
|
@@ -21,7 +21,7 @@
|
|||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
const response = await get(`/applications/${id}`);
|
const response = await get(`/applications/${id}`);
|
||||||
application = response.application;
|
application = response.application;
|
||||||
if (response.application.dockerComposeFile) {
|
if (response.application.dockerComposeFile && application.buildPack === 'compose') {
|
||||||
services = normalizeDockerServices(
|
services = normalizeDockerServices(
|
||||||
JSON.parse(response.application.dockerComposeFile).services
|
JSON.parse(response.application.dockerComposeFile).services
|
||||||
);
|
);
|
||||||
|
@@ -55,7 +55,7 @@
|
|||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
const response = await get(`/applications/${id}`);
|
const response = await get(`/applications/${id}`);
|
||||||
application = response.application;
|
application = response.application;
|
||||||
if (response.application.dockerComposeFile) {
|
if (response.application.dockerComposeFile && application.buildPack === 'compose') {
|
||||||
services = normalizeDockerServices(
|
services = normalizeDockerServices(
|
||||||
JSON.parse(response.application.dockerComposeFile).services
|
JSON.parse(response.application.dockerComposeFile).services
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user