-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
289 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ import path, { resolve } from 'node:path'; | |
import os from 'node:os'; | ||
import * as containerUtils from './container-utils'; | ||
import { bootcImageBuilder, bootcImageBuilderCentos, bootcImageBuilderRHEL } from './constants'; | ||
import type { BootcBuildInfo, BuildType } from '/@shared/src/models/bootc'; | ||
import type { BootcBuildInfo, BuildConfig, BuildType } from '/@shared/src/models/bootc'; | ||
import type { History } from './history'; | ||
import * as machineUtils from './machine-utils'; | ||
import { getConfigurationValue, telemetryLogger } from './extension'; | ||
|
@@ -465,6 +465,27 @@ export function createBuilderImageOptions( | |
} | ||
} | ||
|
||
// Check if build.buildConfig has ANYTHING defined, make sure it is not empty. | ||
if (build.buildConfig) { | ||
const buildConfig = createBuildConfigJSON(build.buildConfig); | ||
|
||
// Make sure that cutomizations is exists and is not empty before adding it to the container. | ||
if (buildConfig.customizations && Object.keys(buildConfig.customizations).length > 0) { | ||
// Create a temporary path to store the buildConfig JSON | ||
// with a temporary name | ||
// eslint-disable-next-line sonarjs/pseudo-random | ||
const buildConfigPath = path.join(os.tmpdir(), `${Math.floor(Math.random() * 100000)}.json`); | ||
|
||
// Write the buildConfig JSON to the temporary file with JSON | ||
fs.writeFileSync(buildConfigPath, JSON.stringify(buildConfig, undefined, 2)); | ||
|
||
// Add the mount to the configuration file | ||
if (options.HostConfig?.Binds) { | ||
options.HostConfig.Binds.push(buildConfigPath + ':/config.json:ro'); | ||
} | ||
} | ||
} | ||
|
||
// If there is the chown in build, add the --chown flag to the command with the value in chown | ||
if (build.chown) { | ||
cmd.push('--chown', build.chown); | ||
|
@@ -473,6 +494,45 @@ export function createBuilderImageOptions( | |
return options; | ||
} | ||
|
||
// Function that takes in BuildConfig and creates a JSON object out of the contents. | ||
// for example: | ||
/* | ||
{ | ||
"customizations": { | ||
"user": [ | ||
{ | ||
"name": "alice", | ||
"password": "bob", | ||
"key": "ssh-rsa AAA ... [email protected]", | ||
"groups": [ | ||
"wheel", | ||
"admins" | ||
] | ||
} | ||
] | ||
} | ||
} | ||
*/ | ||
// We will then return it as "cutomizations" which is required by bootc-image-builder | ||
export function createBuildConfigJSON(buildConfig: BuildConfig): Record<string, unknown> { | ||
const config: Record<string, unknown> = {}; | ||
|
||
console.log('This is buldconfig to parse', buildConfig); | ||
if (buildConfig.user && buildConfig.user.length > 0) { | ||
config.user = buildConfig.user; | ||
} | ||
|
||
if (buildConfig.filesystem && buildConfig.filesystem.length > 0) { | ||
config.filesystem = buildConfig.filesystem; | ||
} | ||
|
||
if (buildConfig.kernel?.append) { | ||
config.kernel = buildConfig.kernel; | ||
} | ||
|
||
return { customizations: config }; | ||
} | ||
|
||
// Creates a command that will be used to build the image on Linux. This includes adding the transfer-to-root script as well as the actual build command. | ||
// we also export to the log file during this process too. | ||
export function linuxBuildCommand( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters