Skip to content

Commit

Permalink
--load option
Browse files Browse the repository at this point in the history
  • Loading branch information
ilteoood committed May 15, 2020
1 parent 16b391e commit 393f6f8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The accepted inputs are:
| `platform` | String | `linux/amd64,linux/arm64,linux/arm/v7` | No | Platforms (*comma separated*) that should be used to build the image | |
| `dockerHubUser` | String | | Only if `publish` is true | User that will publish the image |
| `dockerHubPassword` | String | | Only if `publish` is true | Password of the `dockerHubUser` |

| `load` | Boolean | `false` | No | Indicate if you want to load image into docker |
## Example of usage

```
Expand Down
11 changes: 6 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ async function docker_buildx() {
const imageTag = extractInput('tag', false, 'latest');
const dockerFile = extractInput('dockerFile', false, 'Dockerfile');
const publish = extractInput('publish', false, 'false').toLowerCase() === 'true';
const load = extractInput('load', false, 'false').toLowerCase() === 'true';
const platform = extractInput('platform', false, 'linux/amd64,linux/arm64,linux/arm/v7');
const buildArg = extractInput('buildArg', false, '');
const buildFunction = publish ? buildAndPublish : buildOnly;
await buildFunction(platform, imageName, imageTag, dockerFile, buildArg);
await buildFunction(platform, imageName, imageTag, dockerFile, buildArg, load);
cleanMyself();
} catch (error) {
core.setFailed(error.message);
Expand Down Expand Up @@ -45,15 +46,15 @@ async function executeShellScript(scriptName, ...parameters) {
child_process.execSync(command, {stdio: 'inherit'});
}

async function buildAndPublish(platform, imageName, imageTag, dockerFile, buildArg) {
async function buildAndPublish(platform, imageName, imageTag, dockerFile, buildArg, load) {
const dockerHubUser = extractInput('dockerHubUser', true);
const dockerHubPassword = extractInput('dockerHubPassword', true);
await executeShellScript('dockerhub_login', dockerHubUser, dockerHubPassword);
await executeShellScript('docker_build', platform, imageName, imageTag, dockerFile, true, buildArg);
await executeShellScript('docker_build', platform, imageName, imageTag, dockerFile, true, buildArg, load);
}

async function buildOnly(platform, imageName, imageTag, dockerFile, buildArg) {
await executeShellScript('docker_build', platform, imageName, imageTag, dockerFile, false, buildArg);
async function buildOnly(platform, imageName, imageTag, dockerFile, buildArg, load) {
await executeShellScript('docker_build', platform, imageName, imageTag, dockerFile, false, buildArg, load);
}

function cloneMyself() {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "docker_buildx",
"version": "1.0.0",
"version": "1.0.3",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
8 changes: 7 additions & 1 deletion scripts/docker_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@ do
BUILD_ARGS="$BUILD_ARGS --build-arg $ARG"
done

docker buildx build --platform $1 $PUSH $TAGS $BUILD_ARGS -f $4 .
LOAD=
if [ $7 = true ];
then
LOAD="--load"
fi

docker buildx build --platform $1 $PUSH $LOAD $TAGS $BUILD_ARGS -f $4 .

0 comments on commit 393f6f8

Please sign in to comment.