Skip to content

Commit

Permalink
Remove aliases created by buildx when installing by default
Browse files Browse the repository at this point in the history
If the action is configured to install buildx by default using the
input then docker buildx sets up docker build as an alias for buildx
making all docker build calls use the buildx builder instead of
traditional builders. The action didn't perform cleanup in this case to
uninstall the aliases which meant that any future workflows running on
same GitHub Actions runner would get the buildx builders even if it did
not explicitly request it.

This commit tracks if the aliases were installed and removes them during
post step of the action if so.

Signed-off-by: Ashhar Hasan <hashhar_dev@outlook.com>
  • Loading branch information
hashhar committed Apr 25, 2022
1 parent 74283ca commit 3c6e8ed
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
4 changes: 2 additions & 2 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions src/main.ts
Expand Up @@ -70,6 +70,7 @@ async function run(): Promise<void> {
if (inputs.install) {
core.startGroup(`Setting buildx as default builder`);
await exec.exec('docker', ['buildx', 'install']);
stateHelper.setBuildxIsDefaultBuilder('true');
core.endGroup();
}

Expand Down Expand Up @@ -125,6 +126,20 @@ async function cleanup(): Promise<void> {
});
core.endGroup();
}

if (stateHelper.IsBuildxDefaultBuilder) {
core.startGroup('Uninstalling build aliased to buildx');
await exec
.getExecOutput('docker', ['buildx', 'uninstall'], {
ignoreReturnCode: true
})
.then(res => {
if (res.stderr.length > 0 && res.exitCode != 0) {
core.warning(res.stderr.trim());
}
});
core.endGroup();
}
}

if (!stateHelper.IsPost) {
Expand Down
5 changes: 5 additions & 0 deletions src/state-helper.ts
Expand Up @@ -3,6 +3,7 @@ import * as core from '@actions/core';
export const IsPost = !!process.env['STATE_isPost'];
export const IsDebug = !!process.env['STATE_isDebug'];
export const builderName = process.env['STATE_builderName'] || '';
export const IsBuildxDefaultBuilder = !!process.env['STATE_IsBuildxDefaultBuilder'];
export const containerName = process.env['STATE_containerName'] || '';

export function setDebug(debug: string) {
Expand All @@ -13,6 +14,10 @@ export function setBuilderName(builderName: string) {
core.saveState('builderName', builderName);
}

export function setBuildxIsDefaultBuilder(isBuildxDefaultBuilder: string) {
core.saveState('isBuildxDefaultBuilder', isBuildxDefaultBuilder);
}

export function setContainerName(containerName: string) {
core.saveState('containerName', containerName);
}
Expand Down

0 comments on commit 3c6e8ed

Please sign in to comment.