Skip to content

Commit

Permalink
Merge pull request #17 from stenic/any-server-pr
Browse files Browse the repository at this point in the history
Allow pushing to any server
  • Loading branch information
ilteoood committed Nov 29, 2020
2 parents cdfa422 + 1bf01dc commit 6b39b71
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 16 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ The accepted inputs are:
| `buildArg` | String | | No | Build arguments (*comma separated*) used to build the image |
| `publish` | Boolean | `false` | No | Indicate if the builded image should be published on Docker HUB |
| `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` |
| `dockerUser` | String | (value of `dockerHubUser`) | Only if `publish` is true | User that will publish the image |
| `dockerHubUser` | String | | Only if `publish` is true | (DEPRECATED) User that will publish the image |
| `dockerPassword` | String | (value of `dockerHubUser`) | Only if `publish` is true | Password of the `dockerUser` |
| `dockerHubPassword` | String | | Only if `publish` is true | (DEPRECATED) Password of the `dockerHubUser` |
| `dockerServer` | String | | | Registry, empty uses dockerHub |
| `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 |
Expand All @@ -33,6 +36,6 @@ jobs:
with:
publish: true
imageName: YOUR_IMAGE_NAME_HERE
dockerHubUser: YOUR_USER_HERE
dockerHubPassword: YOUR_PASSWORD_HERE
dockerUser: YOUR_USER_HERE
dockerPassword: YOUR_PASSWORD_HERE
```
15 changes: 12 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,24 @@ inputs:
description: "Build arguments (comma separated) used to build the image"
default: "none"
publish:
description: "Indicate if the builded image should be published on Docker HUB"
description: "Indicate if the builded image should be published on a registry"
default: "false"
platform:
description: "Platforms (comma separated) that should be used to build the image"
default: "linux/amd64,linux/arm64,linux/arm/v7"
dockerHubUser:
dockerUser:
description: "User that will publish the image, if indicated"
dockerHubUser:
description: "(DEPRECATED) User that will publish the image, if indicated"
deprecationMessage: 'Use dockerUser instead'
dockerPassword:
description: "Password of the dockerUser"
dockerHubPassword:
description: "Password of the dockerHubUser"
description: "(DEPRECATED) Password of the dockerUser"
deprecationMessage: 'Use dockerPassword instead'
dockerServer:
description: "Server to login against"
default: ""
load:
description: "Indicate if you want to load image into docker"
default: "false"
Expand Down
20 changes: 14 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ async function docker_buildx() {
}

function checkPlatform() {
core.info('Checking platform')
if (os.platform() !== 'linux') {
throw new Error('Only supported on linux platform');
}
}

function extractInput(inputName, required, defaultValue) {
const inputValue = core.getInput(inputName);
if(required) checkRequiredInput(inputName, inputValue);
if (required) checkRequiredInput(inputName, inputValue);
return inputValue ? inputValue : defaultValue;
}

Expand All @@ -45,26 +46,33 @@ function checkRequiredInput(inputName, inputValue) {
async function executeShellScript(scriptName, ...parameters) {
parameters = (parameters || []).join(' ');
const command = `docker_buildx/scripts/${scriptName}.sh ${parameters}`;
child_process.execSync(command, {stdio: 'inherit'});
child_process.execSync(command, { stdio: 'inherit' });
}

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);
core.info('Running buildAndPublish')
const dockerHubUser = extractInput('dockerHubUser', false);
const dockerUser = extractInput('dockerUser', !dockerHubUser, dockerHubUser);
const dockerHubPassword = extractInput('dockerHubPassword', false);
const dockerPassword = extractInput('dockerPassword', !dockerHubPassword, dockerHubPassword);
const dockerServer = extractInput('dockerServer', false, '');

await executeShellScript('docker_login', dockerUser, dockerPassword, dockerServer);
await executeShellScript('docker_build', platform, imageName, imageTag, dockerFile, true, buildArg, load, context, target);
}

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

function cloneMyself() {
core.info('Cloning action')
child_process.execSync(`git clone https://github.com/ilteoood/docker_buildx`);
}

function cleanMyself() {
child_process.execSync(`rm -rf docker_buildx`);
}

docker_buildx();
docker_buildx();
3 changes: 3 additions & 0 deletions scripts/docker_login.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh -l

echo $2 | docker login --username $1 --password-stdin $3
3 changes: 0 additions & 3 deletions scripts/dockerhub_login.sh

This file was deleted.

0 comments on commit 6b39b71

Please sign in to comment.