Skip to content

Commit

Permalink
Context path
Browse files Browse the repository at this point in the history
  • Loading branch information
ilteoood committed Oct 28, 2020
1 parent 75b2e82 commit cdfa422
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ The accepted inputs are:
| `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 |
| `context` | String | `.` | No | Set the context path |
## Example of usage

```
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ inputs:
target:
description: "Set the target build stage to build"
default: ""
context:
description: "Set the context path"
default: "."
runs:
using: 'node12'
main: index.js
11 changes: 6 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ async function docker_buildx() {
const platform = extractInput('platform', false, 'linux/amd64,linux/arm64,linux/arm/v7');
const buildArg = extractInput('buildArg', false, '');
const target = extractInput('target', false, '');
const context = extractInput('context', false, '.');
const buildFunction = publish ? buildAndPublish : buildOnly;
await buildFunction(platform, imageName, imageTag, dockerFile, buildArg, load, target);
await buildFunction(platform, imageName, imageTag, dockerFile, buildArg, load, context, target);
cleanMyself();
} catch (error) {
core.setFailed(error.message);
Expand Down Expand Up @@ -47,15 +48,15 @@ async function executeShellScript(scriptName, ...parameters) {
child_process.execSync(command, {stdio: 'inherit'});
}

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

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

function cloneMyself() {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.3",
"version": "1.0.5",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions scripts/docker_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ then
fi

TARGET=
if [ ! -z "$8" ];
if [ ! -z "$9" ];
then
TARGET="--target $8"
TARGET="--target $9"
fi

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

0 comments on commit cdfa422

Please sign in to comment.