Remove aliases created by buildx when installing by default

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>
This commit is contained in:
Ashhar Hasan 2022-04-25 12:33:43 +05:30
parent 74283caced
commit fdd372a0be
4 changed files with 23 additions and 3 deletions

4
dist/index.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@ -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();
}
@ -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) {

View File

@ -1,5 +1,6 @@
import * as core from '@actions/core';
export const IsBuildxDefaultBuilder = !!process.env['STATE_isBuildxDefaultBuilder'];
export const IsPost = !!process.env['STATE_isPost'];
export const IsDebug = !!process.env['STATE_isDebug'];
export const builderName = process.env['STATE_builderName'] || '';
@ -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);
}