Skip to content

Commit

Permalink
feat: add support for extraFlag for docker subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Jul 30, 2024
1 parent 3e02705 commit fb3744b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,17 +191,19 @@ export default function getCLI(context) {
.option('-r, --context-ref <ref>', 'Reference to the PR, release, or branch')
.option('-p, --platform <platform...>', 'Platforms (multiple values allowed)')
.option('-f, --force-latest', 'Force the "latest" tag on the release')
.option('-x, --extra-flags <extraFlags>', 'Pass a extra flags to the docker build command')
.option('-v, --verbose', 'Print more info')
.action(async function () {
const opts = context.processOptions(this, ['preset', 'repo']);
opts.platform = opts.platform || ['linux/arm64'];
const github = new Github({ context });
const buildContext = opts.context;
const buildContextRef = opts.contextRef;
const extraFlags = opts.extraFlags;

Check failure on line 202 in src/cli.js

View workflow job for this annotation

GitHub Actions / build

Use object destructuring
const latestRelease = await github.getLatestReleaseTag();
console.log(`Latest release: ${latestRelease}`);
const command = await docker.getDockerCommand({
...opts, buildContext, buildContextRef, latestRelease,
...opts, buildContext, buildContextRef, latestRelease, extraFlags,
});
context.log(command);
if (!opts.dryRun) {
Expand Down
2 changes: 2 additions & 0 deletions src/docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export function getDockerTags({

export async function getDockerCommand({
preset, platform, buildContext, buildContextRef, forceLatest = false, latestRelease = null,
extraFlags = '',
}) {
const platforms = platform;

Expand Down Expand Up @@ -130,6 +131,7 @@ export async function getDockerCommand({
--label base=${pyVer} \\
--label build_actor=${actor} \\
${versionLabel} \\
${extraFlags} \\
${dockerContext}
`;
}
16 changes: 14 additions & 2 deletions src/docker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ describe('getDockerCommand', () => {
SHA,
'push',
'master',
'',
[`-t ${REPO}:master `],
],
[
Expand All @@ -238,20 +239,31 @@ describe('getDockerCommand', () => {
SHA,
'push',
'master',
'',
['--load', `-t ${REPO}:master-dev `],
],
[
'dev',
['linux/amd64'],
SHA,
'push',
'master',
'--cpus 1',
['--cpus 1'],
],
// multi-platform
[
'lean',
['linux/arm64', 'linux/amd64'],
SHA,
'push',
'master',
'',
['--platform linux/arm64,linux/amd64'],
],
])('returns expected docker command', async (preset, platform, sha, buildContext, buildContextRef, contains) => {
])('returns expected docker command', async (preset, platform, sha, buildContext, buildContextRef, extraFlags, contains) => {
const cmd = await dockerUtils.getDockerCommand({
preset, platform, sha, buildContext, buildContextRef, latestRelease: NEW_REL,
preset, platform, sha, buildContext, buildContextRef, extraFlags, latestRelease: NEW_REL,
});
contains.forEach((expectedSubstring) => {
expect(cmd).toContain(expectedSubstring);
Expand Down

0 comments on commit fb3744b

Please sign in to comment.