-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6e98909
Showing
17 changed files
with
752 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.