Skip to content

Commit

Permalink
fix: building and scanning master image command arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
tada5hi committed Sep 23, 2024
1 parent 2f89027 commit 95041ea
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,15 @@ export async function bundleDockerFile(context: DockerFileBuildContext) : Promis
entryPoint.name,
);

let entrypointCommand = masterImage.command;
let entrypointCommandArguments = masterImage.command_arguments;
let { command } = masterImage;
let commandArguments : string[] = [];

if (
masterImage.command_arguments &&
Array.isArray(masterImage.command_arguments)
) {
commandArguments = masterImage.command_arguments;
}

const { data: masterImageGroups } = await coreClient.masterImageGroup.getMany({
filter: {
Expand All @@ -81,31 +88,38 @@ export async function bundleDockerFile(context: DockerFileBuildContext) : Promis
});

if (masterImageGroups.length > 0) {
const masterImageGroup = masterImageGroups.shift();
if (masterImageGroup) {
entrypointCommand = entrypointCommand || masterImageGroup.command;
entrypointCommandArguments = entrypointCommandArguments || masterImageGroup.command_arguments;
}
}
const masterImageGroup = masterImageGroups[0];

let argumentsString = '';
if (
!command &&
masterImageGroup.command
) {
command = masterImageGroup.command;
}

if (entrypointCommandArguments) {
let parts = Array.isArray(entrypointCommandArguments) ?
entrypointCommandArguments :
[entrypointCommandArguments];
if (
commandArguments.length === 0 &&
masterImageGroup.command_arguments &&
Array.isArray(masterImageGroup.command_arguments)
) {
commandArguments = masterImageGroup.command_arguments;
}
}

parts = parts.map((part) => `"${part}"`);
argumentsString = `${parts.join(', ')} `;
const cmdParts : string[] = [];
cmdParts.push(`"${command}"`);
for (let i = 0; i < commandArguments.length; i++) {
cmdParts.push(`"${commandArguments[i]}"`);
}
cmdParts.push(`"${path.posix.join(AnalysisContainerPath.CODE, entrypointPath)}"`);

const masterImagePath = `${getHostNameFromString(context.hostname)}/master/${masterImage.virtual_path}`;
const content = `
FROM ${masterImagePath}
RUN mkdir -p ${AnalysisContainerPath.CODE}
RUN chmod -R +x ${AnalysisContainerPath.CODE}
CMD ["${entrypointCommand}", ${argumentsString}"${path.posix.join(AnalysisContainerPath.CODE, entrypointPath)}"]
CMD [${cmdParts.join(', ')}]
`;

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export async function syncMasterImages(
data.command = input[i].command;
}

if (typeof input[i].command_arguments !== 'undefined') {
if (typeof input[i].commandArguments !== 'undefined') {
data.command_arguments = input[i].commandArguments;
}

Expand Down Expand Up @@ -110,7 +110,7 @@ export async function syncMasterImageGroups(
data.command = input[i].command;
}

if (typeof input[i].command_arguments !== 'undefined') {
if (typeof input[i].commandArguments !== 'undefined') {
data.command_arguments = input[i].commandArguments;
}

Expand Down
16 changes: 14 additions & 2 deletions packages/server-core/src/domains/master-image-group/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* view the LICENSE file that was distributed with this source code.
*/

import { deserialize, serialize } from '@authup/kit';
import {
Column,
CreateDateColumn,
Expand Down Expand Up @@ -32,8 +33,19 @@ export class MasterImageGroupEntity implements MasterImageGroup {
@Column({ type: 'text', nullable: true })
command: string | null;

@Column({ type: 'json', nullable: true })
command_arguments: any | null;
@Column({
type: 'text',
nullable: true,
transformer: {
to(value: any): any {
return serialize(value);
},
from(value: any): any {
return deserialize(value);
},
},
})
command_arguments: unknown | null;

// ------------------------------------------------------------------

Expand Down
16 changes: 14 additions & 2 deletions packages/server-core/src/domains/master-image/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* view the LICENSE file that was distributed with this source code.
*/

import { deserialize, serialize } from '@authup/kit';
import {
Column,
CreateDateColumn,
Expand Down Expand Up @@ -37,8 +38,19 @@ export class MasterImageEntity implements MasterImage {
@Column({ type: 'text', nullable: true })
command: string | null;

@Column({ type: 'json', nullable: true })
command_arguments: any | null;
@Column({
type: 'text',
nullable: true,
transformer: {
to(value: any): any {
return serialize(value);
},
from(value: any): any {
return deserialize(value);
},
},
})
command_arguments: unknown | null;

// ------------------------------------------------------------------

Expand Down

0 comments on commit 95041ea

Please sign in to comment.