Skip to content

Commit 6bb5966

Browse files
committed
Create my fork and and --build-arg support
1 parent f2b0693 commit 6bb5966

File tree

9 files changed

+107
-90
lines changed

9 files changed

+107
-90
lines changed

README.md

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,43 @@
1-
# docker_buildx
1+
# Customizible Docker Buildx Build
22

3-
GitHub Action to build and publish images using [Docker Buildx](https://docs.docker.com/buildx/working-with-buildx/).
3+
GitHub Action for building and publishing Docker images using [Docker Buildx](https://docs.docker.com/buildx/working-with-buildx/).
44

5-
## Inputs
6-
The accepted inputs are:
5+
## Input Parameters
76

8-
| Name | Type | Default | Mandatory | Description |
9-
|---------------|-----------|-----------|-------------|-----------------------------------------------------------------|
10-
| `tag` | String | `latest` | No | Tags (*comma separated*) to apply to the image |
11-
| `imageName` | String | | Yes | Name of the image |
12-
| `dockerFile` | String | `Dockerfile` | No | Name of the Dockerfile |
13-
| `publish` | Boolean | `false` | No | Indicate if the builded image should be published on Docker HUB |
14-
| `platform` | String | `linux/amd64,linux/arm64,linux/arm/v7` | No | Platforms (*comma separated*) that should be used to build the image | |
15-
| `dockerHubUser` | String | | Only if `publish` is true | User that will publish the image |
16-
| `dockerHubPassword` | String | | Only if `publish` is true | Password of the `dockerHubUser` |
7+
| Name | Type | Default | Mandatory | Description |
8+
| ------------------- | ------- | -------------------------------------- | ------------------------- | -------------------------------------------------------------------- |
9+
| `tag` | String | `latest` | No | Tags (*comma separated*) to apply to the image |
10+
| `imageName` | String | | Yes | Name of the image |
11+
| `dockerFile` | String | `Dockerfile` | No | Name of the Dockerfile |
12+
| `buildArg` | String | `none` | No | Docker build `--build-arg` flags (*comma separated*) |
13+
| `publish` | Boolean | `false` | No | Indicate if the builded image should be published on Docker HUB |
14+
| `platform` | String | `linux/amd64,linux/arm64,linux/arm/v7` | No | Platforms (*comma separated*) that should be used to build the image | |
15+
| `dockerHubUser` | String | | Only if `publish` is true | User that will publish the image |
16+
| `dockerHubPassword` | String | | Only if `publish` is true | Password of the `dockerHubUser` |
1717

18-
## Example of usage
18+
## Example
19+
20+
```yaml
21+
name: docker-buildx-push
22+
23+
on:
24+
push:
25+
branches:
26+
- master
1927

20-
```
2128
jobs:
22-
build:
23-
runs-on: ubuntu-latest
24-
name: Build image job
25-
steps:
26-
- name: Checkout master
27-
uses: actions/checkout@master
28-
- name: Build and publish image
29-
uses: ilteoood/docker_buildx@master
30-
with:
31-
publish: true
32-
imageName: YOUR_IMAGE_NAME_HERE
33-
dockerHubUser: YOUR_USER_HERE
34-
dockerHubPassword: YOUR_PASSWORD_HERE
29+
docker-buildx:
30+
runs-on: ubuntu-latest
31+
steps:
32+
-
33+
name: Checkout master
34+
uses: actions/checkout@master
35+
-
36+
name: Build and publish image
37+
uses: zmingxie/docker_buildx@master
38+
with:
39+
publish: true
40+
imageName: YOUR_IMAGE_NAME_HERE
41+
dockerHubUser: YOUR_USER_HERE
42+
dockerHubPassword: YOUR_PASSWORD_HERE
3543
```

action.yml

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
1-
name: "Customizable Docker Buildx"
2-
description: "Configure docker to be used with buildx"
1+
name: "Customizable Docker Buildx Build"
2+
description: "Build and Publish Multi-Arch Docker Images using GitHub Action"
3+
author: "zmingxie"
34
branding:
4-
icon: archive
5-
color: blue
5+
color: 'blue'
6+
icon: 'anchor'
7+
68
inputs:
7-
tag:
8-
description: "Tags (comma separated) to apply to the image"
9-
default: "latest"
10-
imageName:
11-
description: "Name of the image"
12-
required: true
13-
dockerFile:
14-
description: "Name of the Dockerfile"
15-
default: "Dockerfile"
16-
publish:
17-
description: "Indicate if the builded image should be published on Docker HUB"
18-
default: "false"
19-
platform:
20-
description: "Platforms (comma separated) that should be used to build the image"
21-
default: "linux/amd64,linux/arm64,linux/arm/v7"
22-
dockerHubUser:
23-
description: "User that will publish the image, if indicated"
24-
dockerHubPassword:
25-
description: "Password of the dockerHubUser"
9+
tag:
10+
description: "Tags (comma separated) to apply to the image"
11+
default: "latest"
12+
imageName:
13+
description: "Name of the image"
14+
required: true
15+
dockerFile:
16+
description: "Name of the Dockerfile"
17+
default: "Dockerfile"
18+
buildArg:
19+
description: "Docker `--build-arg` flags (*comma separated*)"
20+
default: "none"
21+
publish:
22+
description: "Indicate if the builded image should be published on Docker HUB"
23+
default: "false"
24+
platform:
25+
description: "Platforms (comma separated) that should be used to build the image"
26+
default: "linux/amd64,linux/arm64,linux/arm/v7"
27+
dockerHubUser:
28+
description: "User that will publish the image, if indicated"
29+
dockerHubPassword:
30+
description: "Password of the dockerHubUser"
2631
runs:
27-
using: 'node12'
28-
main: index.js
32+
using: 'node12'
33+
main: 'index.js'

index.js

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,8 @@ async function docker_buildx() {
66
try {
77
checkPlatform();
88
cloneMyself();
9-
const imageName = extractInput('imageName', true);
109
await executeShellScript('install_buildx');
11-
const imageTag = extractInput('tag', false, 'latest');
12-
const dockerFile = extractInput('dockerFile', false, 'Dockerfile');
13-
const publish = extractInput('publish', false, 'false').toLowerCase() === 'true';
14-
const platform = extractInput('platform', false, 'linux/amd64,linux/arm64,linux/arm/v7');
15-
const buildFunction = publish ? buildAndPublish : buildOnly;
16-
await buildFunction(platform, imageName, imageTag, dockerFile);
10+
await buildFunction();
1711
cleanMyself();
1812
} catch (error) {
1913
core.setFailed(error.message);
@@ -22,7 +16,7 @@ async function docker_buildx() {
2216

2317
function checkPlatform() {
2418
if (os.platform() !== 'linux') {
25-
throw new Error('Only supported on linux platform')
19+
throw new Error('Only supported on linux platform');
2620
}
2721
}
2822

@@ -40,24 +34,46 @@ function checkRequiredInput(inputName, inputValue) {
4034

4135
async function executeShellScript(scriptName, ...parameters) {
4236
parameters = (parameters || []).join(' ');
43-
command = `sudo docker_buildx/scripts/${scriptName}.sh ${parameters}`;
37+
command = `docker_buildx/scripts/${scriptName}.sh ${parameters}`;
4438
console.log(`Executing: ${command}`);
4539
child_process.execSync(command, {stdio: 'inherit'});
4640
}
4741

48-
async function buildAndPublish(platform, imageName, imageTag, dockerFile) {
49-
const dockerHubUser = extractInput('dockerHubUser', true);
50-
const dockerHubPassword = extractInput('dockerHubPassword', true);
51-
await executeShellScript('dockerhub_login', dockerHubUser, dockerHubPassword);
52-
await executeShellScript('docker_build_push', platform, imageName, imageTag, dockerFile);
53-
}
42+
async function buildFunction() {
43+
// Parse input parameters
44+
var imageName = extractInput('imageName', true);
45+
var imageTag = extractInput('tag', false, 'latest');
46+
var dockerFile = extractInput('dockerFile', false, 'Dockerfile');
47+
var buildArg = extractInput('buildArg', false, 'none');
48+
var platform = extractInput('platform', false, 'linux/amd64,linux/arm64,linux/arm/v7');
49+
var publish = extractInput('publish', false, 'false').toLowerCase() === 'true';
50+
51+
var dockerArgs = "--platform " + platform;
52+
53+
if (publish) {
54+
const dockerHubUser = extractInput('dockerHubUser', true);
55+
const dockerHubPassword = extractInput('dockerHubPassword', true);
56+
await executeShellScript('docker_login', dockerHubUser, dockerHubPassword);
57+
dockerArgs += " --push";
58+
}
5459

55-
async function buildOnly(platform, imageName, imageTag, dockerFile) {
56-
await executeShellScript('docker_build', platform, imageName, imageTag, dockerFile);
60+
if (buildArg !== 'none') {
61+
var args = buildArg.split(",");
62+
for(var i = 0; i < args.length; i++) {
63+
dockerArgs += " --build-arg " + args[i];
64+
}
65+
}
66+
67+
var tags = imageTag.split(",");
68+
for (var i = 0; i < tags.length; i++) {
69+
dockerArgs += " --tag " + imageName + ":" + tags[i];
70+
}
71+
dockerArgs += " -f " + dockerFile;
72+
await executeShellScript('docker_build', dockerArgs);
5773
}
5874

5975
function cloneMyself() {
60-
child_process.execSync(`git clone https://github.com/ilteoood/docker_buildx`);
76+
child_process.execSync(`git clone https://github.com/zmingxie/docker_buildx`);
6177
}
6278

6379
function cleanMyself() {

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "docker_buildx",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "",
55
"main": "index.js",
66
"scripts": {

scripts/docker_build.sh

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
#!/bin/sh -l
22
export DOCKER_CLI_EXPERIMENTAL=enabled
3-
DOCKER_BUILDX_TAG_OPTS=
4-
for TAG in $(echo "$3" | tr ',' ' ')
5-
do
6-
DOCKER_BUILDX_TAG_OPTS="$DOCKER_BUILDX_TAG_OPTS --tag $2:$TAG"
7-
done
8-
docker buildx build --platform $1 $DOCKER_BUILDX_TAG_OPTS -f $4 .
3+
4+
docker buildx build $@ .

scripts/docker_build_push.sh

Lines changed: 0 additions & 8 deletions
This file was deleted.

scripts/docker_login.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh -l
2+
3+
echo $2 | docker login --username $1 --password-stdin

scripts/dockerhub_login.sh

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)