Skip to content

Commit

Permalink
First commit!
Browse files Browse the repository at this point in the history
  • Loading branch information
ilteoood committed Jan 6, 2020
0 parents commit 6e98909
Show file tree
Hide file tree
Showing 17 changed files with 752 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# docker_buildx

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

## Inputs
The accepted inputs are:

| Name | Type | Default | Mandatory | Description |
|---------------|-----------|-----------|-------------|-----------------------------------------------------------------|
| `tag` | String | `latest` | No | Tag to apply to the image |
| `imageName` | String | | Yes | Name of 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` |
22 changes: 22 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: "Docker buildx"
description: "Configure docker to be used with buildx"
inputs:
tag:
description: "Tag to apply to the image"
default: "latest"
imageName:
description: "Name of the image"
required: true
publish:
description: "Indicate if the builded image should be published on Docker HUB"
default: "false"
platform:
description: "Platforms (comma separated) that should be used to build the image"
default: "linux/amd64,linux/arm64,linux/arm/v7"
dockerHubUser:
description: "User that will publish the image, if indicated"
dockerHubPassword:
description: "Password of the dockerHubUser"
runs:
using: 'node12'
main: index.js
57 changes: 57 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const core = require('@actions/core');
const os = require('os');
const child_process = require('child_process');

async function docker_buildx() {
try {
checkPlatform();
const imageName = extractInput('imageName', true);
await executeShellScript('install_buildx');
const imageTag = extractInput('tag', false, 'latest');
const publish = core.getInput('publish');
const platform = extractInput('platform', false, 'linux/amd64,linux/arm64,linux/arm/v7');
const buildFunction = publish ? buildAndPublish : buildOnly;
buildFunction(platform, imageName, imageTag);
} catch (error) {
core.setFailed(error.message);
}
}

function checkPlatform() {
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);
return inputValue ? inputValue : defaultValue;
}

function checkRequiredInput(inputName, inputValue) {
if (!inputValue) {
throw new Error(`The parameter ${inputName} is missing`);
}
}

async function executeShellScript(scriptName, ...parameters) {
parameters = (parameters || []).join(' ');
command = `./scripts/${scriptName}.sh ${parameters}`;
console.log(`Executing: ${command}`);
output = child_process.execSync(`./scripts/${scriptName}.sh ${parameters}`);
console.log(`Output: ${output}`);
}

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

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

docker_buildx();
140 changes: 140 additions & 0 deletions node_modules/@actions/core/README.md

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

16 changes: 16 additions & 0 deletions node_modules/@actions/core/lib/command.d.ts

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

66 changes: 66 additions & 0 deletions node_modules/@actions/core/lib/command.js

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

1 change: 1 addition & 0 deletions node_modules/@actions/core/lib/command.js.map

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

Loading

0 comments on commit 6e98909

Please sign in to comment.