Skip to content

Commit

Permalink
Support for target
Browse files Browse the repository at this point in the history
  • Loading branch information
Matteo Pietro Dazzi committed May 19, 2020
1 parent 393f6f8 commit 1dd606d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The accepted inputs are:
| `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 |
| `target` | String | `` | No | Set the target build stage to build |
## Example of usage

```
Expand Down
6 changes: 5 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ inputs:
description: "User that will publish the image, if indicated"
dockerHubPassword:
description: "Password of the dockerHubUser"
load:
description: "Indicate if you want to load image into docker"
target:
description: "Set the target build stage to build"
runs:
using: 'node12'
main: index.js
main: index.js
11 changes: 6 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ async function docker_buildx() {
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 target = extractInput('target', false, '');
const buildFunction = publish ? buildAndPublish : buildOnly;
await buildFunction(platform, imageName, imageTag, dockerFile, buildArg, load);
await buildFunction(platform, imageName, imageTag, dockerFile, buildArg, load, target);
cleanMyself();
} catch (error) {
core.setFailed(error.message);
Expand Down Expand Up @@ -46,15 +47,15 @@ async function executeShellScript(scriptName, ...parameters) {
child_process.execSync(command, {stdio: 'inherit'});
}

async function buildAndPublish(platform, imageName, imageTag, dockerFile, buildArg, load) {
async function buildAndPublish(platform, imageName, imageTag, dockerFile, buildArg, load, target) {
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, load);
await executeShellScript('docker_build', platform, imageName, imageTag, dockerFile, true, buildArg, load, target);
}

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

function cloneMyself() {
Expand Down
8 changes: 7 additions & 1 deletion scripts/docker_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,10 @@ then
LOAD="--load"
fi

docker buildx build --platform $1 $PUSH $LOAD $TAGS $BUILD_ARGS -f $4 .
TARGET=
if [ -z "$8" ];
then
TARGET="--target $8"
fi

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

0 comments on commit 1dd606d

Please sign in to comment.