Build push action v2

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2020-08-16 00:36:41 +02:00
parent 3f08c86128
commit 99bea387ee
No known key found for this signature in database
GPG Key ID: 3248E46B6BB8C7F7
22 changed files with 2778 additions and 314 deletions

2
.gitattributes vendored Normal file

@ -0,0 +1,2 @@
/dist/** linguist-generated=true
/lib/** linguist-generated=true

83
.github/workflows/ci.yml vendored Normal file

@ -0,0 +1,83 @@
name: ci
on:
push:
branches:
- master
- v2-working-branch # remove when merged to master
pull_request:
branches:
- master
- v2-working-branch # remove when merged to master
jobs:
main:
runs-on: ubuntu-latest
steps:
-
name: Runner info
run: |
sudo apt-get install -y hwinfo
sudo hwinfo --short
sudo mount
-
name: Run local registry
run: |
docker run -d -p 5000:5000 registry:2
-
name: Checkout
uses: actions/checkout@v2.3.1
-
name: Build
uses: ./
with:
context: ./test
file: ./test/Dockerfile
tags: |
localhost:5000/name/app:latest
localhost:5000/name/app:1.0.0
-
name: Dump context
uses: crazy-max/ghaction-dump-context@v1
buildx:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
dockerfile:
- multi
- multi-golang
- multi-sudo
steps:
-
name: Run local registry
run: |
docker run -d -p 5000:5000 registry:2
-
name: Checkout
uses: actions/checkout@v2.3.1
-
name: Set up QEMU
uses: ./setup-qemu/ # change to docker/setup-qemu-action@master
with:
platforms: all
-
name: Set up Docker Buildx
id: buildx
uses: ./setup-buildx/ # change to docker/setup-buildx-action@master
-
name: Build and push
uses: ./
with:
context: ./test
file: ./test/Dockerfile-${{ matrix.dockerfile }}
builder: ${{ steps.buildx.outputs.builder }}
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/386,linux/ppc64le,linux/s390x
push: true
tags: |
localhost:5000/name/app:latest
localhost:5000/name/app:1.0.0
-
name: Dump context
uses: crazy-max/ghaction-dump-context@v1

@ -1,37 +0,0 @@
name: CI
on:
push:
branches:
- master
tags:
- '*'
pull_request:
jobs:
build:
name: build
runs-on: ubuntu-latest
timeout-minutes: 3
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Run local registry
run: docker run -d -p 5000:5000 registry:2
- name: Build and push image
uses: ./
env:
DOCKER_BUILDKIT: 1
with:
registry: localhost:5000
repository: temp/workflow
tags: foo
- name: Remove local image
run: docker image rm localhost:5000/temp/workflow:foo
- name: Run image from registry
run: docker run localhost:5000/temp/workflow:foo

95
.gitignore vendored Normal file

@ -0,0 +1,95 @@
node_modules
lib
# Jetbrains
/.idea
/*.iml
# Rest of the file pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
jspm_packages/
# TypeScript v1 declaration files
typings/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
# next.js build output
.next
# nuxt.js build output
.nuxt
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/

11
.prettierrc.json Normal file

@ -0,0 +1,11 @@
{
"printWidth": 120,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": false,
"arrowParens": "avoid",
"parser": "typescript"
}

@ -1,3 +0,0 @@
FROM alpine:3
ENTRYPOINT ["echo", "docker github actions"]

322
README.md

@ -1,243 +1,139 @@
# build-push-action
## About
Builds and pushes Docker images and will log in to a Docker registry if required.
GitHub Action to build and push Docker images.
Suggestions and issues can be posted on the repositories [issues page](https://github.com/docker/build-push-action/issues).
___
[Inputs](#Inputs)
* [repository](#repository)
* [username](#username)
* [password](#password)
* [registry](#registry)
* [tags](#tags)
* [tag_with_ref](#tag_with_ref)
* [tag_with_sha](#tag_with_sha)
* [path](#path)
* [dockerfile](#dockerfile)
* [target](#target)
* [always_pull](#always_pull)
* [build_args](#build_args)
* [cache_froms](#cache_froms)
* [labels](#labels)
* [add_git_labels](#add_git_labels)
* [push](#push)
* [Usage](#usage)
* [Quick start](#quick-start)
* [With Buildx](#with-buildx)
* [Customizing](#customizing)
* [inputs](#inputs)
* [outputs](#outputs)
* [Limitation](#limitation)
[Example usage](#Example-usage)
## Usage
## Inputs
### `repository`
**Required** Docker repository to tag the image with.
### `username`
Username used to log in to a Docker registry. If not set then no login will occur.
### `password`
Password or personal access token used to log in to a Docker registry. If not set then no login will occur.
### `registry`
Server address of Docker registry. If not set then will default to Docker Hub.
### `tags`
Comma-delimited list of tags. These will be added to the registry/repository to form the image's tags.
Example:
### Quick start
```yaml
tags: tag1,tag2
```
name: ci
### `tag_with_ref`
on:
pull_request:
branches: master
push:
branches: master
tags:
Boolean value. Defaults to `false`.
Automatically tags the built image with the git reference. The format of the tag depends on the type of git reference with all forward slashes replaced with `-`.
For pushes to a branch the reference will be `refs/heads/{branch-name}` and the tag will be `{branch-name}`. If `{branch-name}` is master then the tag will be `latest`.
For pull requests the reference will be `refs/pull/{pull-request}` and the tag will be `pr-{pull-request}`.
For git tags the reference will be `refs/tags/{git-tag}` and the tag will be `{git-tag}`.
Examples:
|Git Reference|Image tag|
|---|---|
|`refs/heads/master`|`latest`|
|`refs/heads/mybranch`|`mybranch`|
|`refs/heads/my/branch`|`my-branch`|
|`refs/pull/2/merge`|`pr-2-merge`|
|`refs/tags/v1.0.0`|`v1.0.0`|
### `tag_with_sha`
Boolean value. Defaults to `false`.
Automatically tags the built image with the git short SHA prefixed with `sha-`.
Example:
|Git SHA|Image tag|
|---|---|
|`676cae2f85471aeff6776463c72881ebd902dcf9`|`sha-676cae2`|
### `path`
Path to the build context. Defaults to `.`
### `dockerfile`
Path to the Dockerfile. Defaults to `{path}/Dockerfile`
Note when set this path is **not** relative to the `path` input but is instead relative to the current working directory.
### `target`
Sets the target stage to build.
### `always_pull`
Boolean value. Defaults to `false`.
Always attempt to pull a newer version of the image.
### `build_args`
Comma-delimited list of build-time variables.
Example:
```yaml
build_args: arg1=value1,arg2=value2
```
### `cache_froms`
Comma-delimited list of images to consider as cache sources.
Example:
```yaml
cache_froms: myorg/baseimage:latest
```
### `labels`
Comma-delimited list of labels to add to the built image.
Example:
```yaml
labels: label_name_1=label_value_1,label_name_2=label_value_2
```
### `add_git_labels`
Boolean value. Defaults to `false`.
Adds labels with git repository information to the built image based on the standards set out in https://github.com/opencontainers/image-spec/blob/master/annotations.md.
The labels are:
|Label key|Example value|Description|
|---|---|---|
|`org.opencontainers.image.created`|`2020-03-06T23:00:00Z`|Date and time on which the image was built (string, date-time as defined by RFC 3339).|
|`org.opencontainers.image.source`|`https://github.com/myorg/myrepository`|URL to the GitHub repository.|
|`org.opencontainers.image.revision`|`676cae2f85471aeff6776463c72881ebd902dcf9`|The full git SHA of this commit.|
### `push`
Boolean value. Defaults to `true`.
Whether to push the built image.
## Example usage
The following will build the root Dockerfile, tag the image as `myorg/myrepository:latest`, log in to Docker Hub using GitHub secrets, and push the image to the Docker Hub repository `myorg/myrepository`:
```yaml
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
-
name: Checkout
uses: actions/checkout@v2
- name: Build and push Docker images
uses: docker/build-push-action@v1
-
name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: myorg/myrepository
tags: latest
-
name: Build and push
uses: docker/build-push-action@v2
with:
tags: |
user/app:latest
user/app:1.0.0
```
The following will build the root Dockerfile, tag the image with the git reference and SHA as described above, log in to Docker Hub using GitHub secrets, and push the image to the Docker Hub repository `myorg/myrepository`:
### With Buildx
You can also use our [setup-buildx](https://github.com/docker/setup-buildx-action) action that extends the
`docker build` command with the full support of the features provided by
[Moby BuildKit](https://github.com/moby/buildkit) builder toolkit to build multi-platform images.
```yaml
steps:
- name: Checkout code
uses: actions/checkout@v2
name: ci
- name: Build and push Docker images
uses: docker/build-push-action@v1
on:
pull_request:
branches: master
push:
branches: master
tags:
jobs:
buildx:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
with:
platforms: all
-
name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
with:
install: true
-
name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: myorg/myrepository
tag_with_ref: true
tag_with_sha: true
```
The following will only push the image when the event that kicked off the workflow was a push of a git tag:
```yaml
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Build and push Docker images
uses: docker/build-push-action@v1
-
name: Build and push
uses: docker/build-push-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: myorg/myrepository
tag_with_ref: true
push: ${{ startsWith(github.ref, 'refs/tags/') }}
builder: ${{ steps.buildx.outputs.builder }}
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/386,linux/ppc64le,linux/s390x
tags: |
user/app:latest
user/app:1.0.0
```
The following builds the `mytarget` stage and pushes that:
## Customizing
```yaml
steps:
- name: Checkout code
uses: actions/checkout@v2
### inputs
- name: Build and push Docker images
uses: docker/build-push-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: myorg/myrepository
tag_with_ref: true
target: mytarget
```
Following inputs can be used as `step.with` keys
The following will build the root Dockerfile, tag the image as `myorg/myrepository:latest`, log in to Google Container Registry using GitHub secrets (where `DOCKER_PASSWORD` is a [JSON key](https://cloud.google.com/container-registry/docs/advanced-authentication#json-key)), and push the image to the GCR repository `myorg/myrepository`:
| Name | Type | Default | Description |
|---------------------|---------|-----------------------------------|------------------------------------|
| `context` | String | `.` | Build's context is the set of files located in the specified `PATH` or `URL` |
| `file` | String | `./Dockerfile` | Path to the Dockerfile. |
| `build-args` | String | | Newline-delimited list of build-time variables |
| `labels` | String | | Newline-delimited list of metadata for an image |
| `tags` | String | | Newline-delimited list of tags **required** |
| `pull` | Bool | `false` | Always attempt to pull a newer version of the image |
| `target` | String | | Sets the target stage to build |
| `no-cache` | Bool | `false` | Do not use cache when building the image |
| `builder`**¹** | String | | Builder instance |
| `platforms`**¹** | String | | Comma-delimited list of target platforms for build |
| `load`**¹** | Bool | `false` | Shorthand for `--output=type=docker` |
| `push` | Bool | `false` | Whether to push the built image (or shorthand for `--output=type=registry` if buildx used) |
| `outputs`**¹** | String | | Newline-delimited list of output destinations (format: `type=local,dest=path`) |
| `cache-from`**¹** | String | | Newline-delimited list of external cache sources (eg. `user/app:cache`, `type=local,src=path/to/dir`) |
| `cache-to`**¹** | String | | Newline-delimited list of cache export destinations (eg. `user/app:cache`, `type=local,dest=path/to/dir`) |
```yaml
steps:
- name: Checkout code
uses: actions/checkout@v2
> **¹** Only available if [docker buildx](https://github.com/docker/buildx) is enabled.
> See [setup-buildx](https://github.com/docker/setup-buildx-action) action for more info.
- name: Build and push Docker images
uses: docker/build-push-action@v1
with:
username: _json_key
password: ${{ secrets.DOCKER_PASSWORD }}
registry: gcr.io
repository: myorg/myrepository
tags: latest
```
### outputs
Following outputs are available
| Name | Type | Description |
|---------------|---------|---------------------------------------|
| `digest` | String | Image content-addressable identifier also called a digest |
## Limitation
This action is only available for Linux [virtual environments](https://help.github.com/en/articles/virtual-environments-for-github-actions#supported-virtual-environments-and-hardware-resources).

37
__tests__/buildx.test.ts Normal file

@ -0,0 +1,37 @@
import fs = require('fs');
import * as buildx from '../src/buildx';
import * as path from 'path';
import * as os from 'os';
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'setup-buildx-'));
describe('buildx', () => {
it('is available', async () => {
expect(await buildx.isAvailable()).toBe(true);
});
it('count builders', async () => {
const countBuilders = await buildx.countBuilders();
console.log(`countBuilders: ${countBuilders}`);
expect(countBuilders).toBeGreaterThan(0);
});
it('platforms', async () => {
const platforms = await buildx.platforms();
console.log(`platforms: ${platforms}`);
expect(platforms).not.toBeUndefined();
expect(platforms).not.toEqual('');
});
it('acquires v0.2.2 version of buildx', async () => {
const buildxBin = await buildx.install('v0.2.2', tmpDir);
console.log(buildxBin);
expect(fs.existsSync(buildxBin)).toBe(true);
}, 100000);
it('acquires latest version of buildx', async () => {
const buildxBin = await buildx.install('latest', tmpDir);
console.log(buildxBin);
expect(fs.existsSync(buildxBin)).toBe(true);
}, 100000);
});

17
__tests__/github.test.ts Normal file

@ -0,0 +1,17 @@
import * as github from '../src/github';
describe('github', () => {
it('returns latest buildx GitHub release', async () => {
const release = await github.getRelease('latest');
console.log(release);
expect(release).not.toBeNull();
expect(release?.tag_name).not.toEqual('');
});
it('returns v0.2.2 buildx GitHub release', async () => {
const release = await github.getRelease('v0.2.2');
console.log(release);
expect(release).not.toBeNull();
expect(release?.tag_name).toEqual('v0.2.2');
});
});

@ -1,66 +1,68 @@
name: Build and push Docker images
description: Builds and pushes Docker images and will log in to a Docker registry if required
author: Docker
name: Docker Build and Push
description: Build and push Docker images
author: docker
branding:
icon: 'anchor'
color: 'blue'
runs:
using: docker
image: docker://docker/github-actions:v1
args:
- build-push
inputs:
username:
description: Username used to log in to a Docker registry. If not set then no login will occur
context:
description: "Build's context is the set of files located in the specified PATH or URL"
required: false
password:
description: Password or personal access token used to log in to a Docker registry. If not set then no login will occur
default: '.'
file:
description: "Path to the Dockerfile"
required: false
registry:
description: Server address of Docker registry. If not set then will default to Docker Hub
required: false
repository:
description: Docker repository to tag the image with
required: true
tags:
description: Comma-delimited list of tags. These will be added to the registry/repository to form the image's tags
required: false
tag_with_ref:
description: Automatically tags the built image with the git reference as per the readme
required: false
default: false
tag_with_sha:
description: Automatically tags the built image with the git short SHA as per the readme
required: false
default: false
path:
description: Path to the build context
required: false
default: "."
dockerfile:
description: Path to the Dockerfile (Default is '{path}/Dockerfile')
required: false
target:
description: Sets the target stage to build
required: false
always_pull:
description: Always attempt to pull a newer version of the image
required: false
default: false
build_args:
description: Comma-delimited list of build-time variables
required: false
cache_froms:
description: Comma-delimited list of images to consider as cache sources
default: './Dockerfile'
build-args:
description: "Newline-delimited list of build-time variables"
required: false
labels:
description: Comma-delimited list of labels to add to the built image
description: "Newline-delimited list of metadata for an image"
required: false
add_git_labels:
description: Adds labels with git repository information to the built image
tags:
description: "Newline-delimited list of tags"
required: true
pull:
description: "Always attempt to pull a newer version of the image"
required: false
default: false
default: 'false'
target:
description: "Sets the target stage to build"
required: false
no-cache:
description: "Do not use cache when building the image"
required: false
default: 'false'
builder:
description: "Builder instance"
required: false
platforms:
description: "Comma-delimited list of target platforms for build"
required: false
load:
description: "Shorthand for --output=type=docker"
required: false
default: 'false'
push:
description: Whether to push the image
description: "Whether to push the built image (shorthand for --output=type=registry if buildx used)"
required: false
default: true
default: 'false'
outputs:
description: "Newline-delimited list of output destinations (format: type=local,dest=path)"
required: false
cache-from:
description: "Newline-delimited list of external cache sources for buildx (eg. user/app:cache, type=local,src=path/to/dir)"
required: false
cache-to:
description: "Newline-delimited list of cache export destinations for buildx (eg. user/app:cache, type=local,dest=path/to/dir)"
required: false
outputs:
digest:
description: 'Image content-addressable identifier also called a digest'
runs:
using: 'node12'
main: 'dist/index.js'
post: 'dist/index.js'

1911
dist/index.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

39
package.json Normal file

@ -0,0 +1,39 @@
{
"name": "docker-build-push",
"description": "GitHub Action to build and push Docker images",
"main": "lib/main.js",
"scripts": {
"build": "tsc && ncc build",
"format": "prettier --write **/*.ts",
"format-check": "prettier --check **/*.ts",
"pre-checkin": "yarn run format && yarn run build"
},
"repository": {
"type": "git",
"url": "git+https://github.com/docker/build-push-action.git",
"directory": "setup-buildx"
},
"keywords": [
"actions",
"docker",
"build",
"push"
],
"author": "Docker",
"contributors": [
"CrazyMax"
],
"license": "Apache-2.0",
"dependencies": {
"@actions/core": "^1.2.4",
"@actions/exec": "^1.0.4",
"@actions/tool-cache": "^1.5.5"
},
"devDependencies": {
"@types/node": "^14.0.14",
"@zeit/ncc": "^0.22.3",
"prettier": "^2.0.5",
"typescript": "^3.9.5",
"typescript-formatter": "^7.2.2"
}
}

18
src/buildx.ts Normal file

@ -0,0 +1,18 @@
import * as exec from './exec';
export async function isAvailable(): Promise<Boolean> {
return await exec.exec(`docker`, ['buildx'], true).then(res => {
if (res.stderr != '' && !res.success) {
return false;
}
return res.success;
});
}
export async function use(builder: string): Promise<void> {
return await exec.exec(`docker`, ['buildx', 'use', '--builder', builder], false).then(res => {
if (res.stderr != '' && !res.success) {
throw new Error(res.stderr);
}
});
}

58
src/context-helper.ts Normal file

@ -0,0 +1,58 @@
import * as core from '@actions/core';
export interface Inputs {
context: string;
file: string;
buildArgs: string[];
labels: string[];
tags: string[];
pull: boolean;
target: string;
noCache: boolean;
builder: string;
platforms: string;
load: boolean;
push: boolean;
outputs: string[];
cacheFrom: string[];
cacheTo: string[];
}
export async function loadInputs(): Promise<Inputs> {
return {
context: core.getInput('context') || '.',
file: core.getInput('file') || './Dockerfile',
buildArgs: await getInputList('build-args'),
labels: await getInputList('labels'),
tags: await getInputList('tags'),
pull: /true/i.test(core.getInput('pull')),
target: core.getInput('target'),
noCache: /true/i.test(core.getInput('no-cache')),
builder: core.getInput('builder'),
platforms: core.getInput('platforms'),
load: /true/i.test(core.getInput('load')),
push: /true/i.test(core.getInput('push')),
outputs: await getInputList('outputs'),
cacheFrom: await getInputList('cache-from'),
cacheTo: await getInputList('cache-to')
};
}
export async function mustBuildx(inputs: Inputs): Promise<boolean> {
return (
inputs.builder.length > 0 ||
inputs.platforms.length > 0 ||
inputs.push ||
inputs.outputs.length > 0 ||
inputs.cacheFrom.length > 0 ||
inputs.cacheTo.length > 0
);
}
async function getInputList(name: string): Promise<string[]> {
const items = core.getInput(name);
if (items == '') {
return [];
}
return items.split(/\r?\n/).reduce<string[]>((acc, line) => acc.concat(line.split(',')).map(pat => pat.trim()), []);
}

34
src/exec.ts Normal file

@ -0,0 +1,34 @@
import * as aexec from '@actions/exec';
import {ExecOptions} from '@actions/exec';
export interface ExecResult {
success: boolean;
stdout: string;
stderr: string;
}
export const exec = async (command: string, args: string[] = [], silent: boolean): Promise<ExecResult> => {
let stdout: string = '';
let stderr: string = '';
const options: ExecOptions = {
silent: silent,
ignoreReturnCode: true
};
options.listeners = {
stdout: (data: Buffer) => {
stdout += data.toString();
},
stderr: (data: Buffer) => {
stderr += data.toString();
}
};
const returnCode: number = await aexec.exec(command, args, options);
return {
success: returnCode === 0,
stdout: stdout.trim(),
stderr: stderr.trim()
};
};

85
src/main.ts Normal file

@ -0,0 +1,85 @@
import * as os from 'os';
import * as buildx from './buildx';
import {Inputs, loadInputs, mustBuildx} from './context-helper';
import * as core from '@actions/core';
import * as exec from '@actions/exec';
async function run(): Promise<void> {
try {
if (os.platform() !== 'linux') {
core.setFailed('Only supported on linux platform');
return;
}
const inputs: Inputs = await loadInputs();
let buildArgs: Array<string> = [];
// Check buildx
if (await mustBuildx(inputs)) {
if (await !buildx.isAvailable()) {
throw new Error(`Buildx is required but not available`);
}
core.info(`🚀 Buildx will be used to build your image`);
buildArgs.push('buildx', 'build');
} else {
buildArgs.push('build');
}
if (inputs.file) {
buildArgs.push('--file', inputs.file);
}
await asyncForEach(inputs.buildArgs, async buildArg => {
buildArgs.push('--build-arg', buildArg);
});
await asyncForEach(inputs.labels, async label => {
buildArgs.push('--label', label);
});
await asyncForEach(inputs.tags, async tag => {
buildArgs.push('--tag', tag);
});
if (inputs.pull) {
buildArgs.push('--pull');
}
if (inputs.target) {
buildArgs.push('--target', inputs.target);
}
if (inputs.noCache) {
buildArgs.push('--no-cache');
}
if (inputs.builder) {
core.info(`📌 Using build instance ${inputs.builder}`);
await buildx.use(inputs.builder);
}
if (inputs.platforms) {
buildArgs.push('--platform', inputs.platforms);
}
if (inputs.load) {
buildArgs.push('--load');
}
if (inputs.push) {
buildArgs.push('--push');
}
await asyncForEach(inputs.outputs, async output => {
buildArgs.push('--output', output);
});
await asyncForEach(inputs.cacheFrom, async cacheFrom => {
buildArgs.push('--cache-from', cacheFrom);
});
await asyncForEach(inputs.cacheTo, async cacheTo => {
buildArgs.push('--cache-from', cacheTo);
});
core.info(`🏃 Starting build...`);
await exec.exec('docker', buildArgs);
} catch (error) {
core.setFailed(error.message);
}
}
const asyncForEach = async (array, callback) => {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array);
}
};
run();

3
test/Dockerfile Normal file

@ -0,0 +1,3 @@
FROM alpine
RUN echo "Hello world!"

8
test/Dockerfile-multi Normal file

@ -0,0 +1,8 @@
FROM --platform=$BUILDPLATFORM golang:alpine AS build
ARG TARGETPLATFORM
ARG BUILDPLATFORM
RUN echo "I am running on $BUILDPLATFORM, building for $TARGETPLATFORM" > /log
FROM alpine
COPY --from=build /log /log

@ -0,0 +1,30 @@
FROM --platform=${BUILDPLATFORM:-linux/amd64} tonistiigi/xx:golang AS xgo
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.13-alpine AS builder
ENV CGO_ENABLED 0
ENV GO111MODULE on
ENV GOPROXY https://goproxy.io
COPY --from=xgo / /
ARG TARGETPLATFORM
RUN go env
RUN apk --update --no-cache add \
build-base \
gcc \
git \
&& rm -rf /tmp/* /var/cache/apk/*
WORKDIR /app
ENV DIUN_VERSION="v4.4.0"
RUN git clone --branch ${DIUN_VERSION} https://github.com/crazy-max/diun .
RUN go mod download
RUN go build -ldflags "-w -s -X 'main.version=test'" -v -o diun cmd/main.go
FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:latest
COPY --from=builder /app/diun /usr/local/bin/diun
COPY --from=builder /usr/local/go/lib/time/zoneinfo.zip /usr/local/go/lib/time/zoneinfo.zip
RUN diun --version

@ -0,0 +1,22 @@
FROM --platform=$BUILDPLATFORM golang:alpine AS build
ARG TARGETPLATFORM
ARG BUILDPLATFORM
RUN echo "I am running on $BUILDPLATFORM, building for $TARGETPLATFORM" > /log
RUN apk --update --no-cache add \
shadow \
sudo \
&& addgroup -g 1200 buildx \
&& adduser -u 1200 -G buildx -s /sbin/nologin -D buildx \
&& echo 'buildx ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers \
&& rm -rf /tmp/* /var/cache/apk/*
USER buildx
RUN sudo chown buildx. /log
USER root
FROM alpine
COPY --from=build /log /log
RUN ls -al /log

23
tsconfig.json Normal file

@ -0,0 +1,23 @@
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"newLine": "lf",
"outDir": "./lib",
"rootDir": "./src",
"strict": true,
"noImplicitAny": false,
"esModuleInterop": true,
"sourceMap": true
},
"exclude": [
"node_modules",
"setup-buildx",
"setup-qemu",
"**/*.test.ts"
]
}

130
yarn.lock Normal file

@ -0,0 +1,130 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
"@actions/core@^1.2.3", "@actions/core@^1.2.4":
version "1.2.4"
resolved "https://registry.yarnpkg.com/@actions/core/-/core-1.2.4.tgz#96179dbf9f8d951dd74b40a0dbd5c22555d186ab"
integrity sha512-YJCEq8BE3CdN8+7HPZ/4DxJjk/OkZV2FFIf+DlZTC/4iBlzYCD5yjRR6eiOS5llO11zbRltIRuKAjMKaWTE6cg==
"@actions/exec@^1.0.0", "@actions/exec@^1.0.4":
version "1.0.4"
resolved "https://registry.yarnpkg.com/@actions/exec/-/exec-1.0.4.tgz#99d75310e62e59fc37d2ee6dcff6d4bffadd3a5d"
integrity sha512-4DPChWow9yc9W3WqEbUj8Nr86xkpyE29ZzWjXucHItclLbEW6jr80Zx4nqv18QL6KK65+cifiQZXvnqgTV6oHw==
dependencies:
"@actions/io" "^1.0.1"
"@actions/http-client@^1.0.8":
version "1.0.8"
resolved "https://registry.yarnpkg.com/@actions/http-client/-/http-client-1.0.8.tgz#8bd76e8eca89dc8bcf619aa128eba85f7a39af45"
integrity sha512-G4JjJ6f9Hb3Zvejj+ewLLKLf99ZC+9v+yCxoYf9vSyH+WkzPLB2LuUtRMGNkooMqdugGBFStIKXOuvH1W+EctA==
dependencies:
tunnel "0.0.6"
"@actions/io@^1.0.1":
version "1.0.2"
resolved "https://registry.yarnpkg.com/@actions/io/-/io-1.0.2.tgz#2f614b6e69ce14d191180451eb38e6576a6e6b27"
integrity sha512-J8KuFqVPr3p6U8W93DOXlXW6zFvrQAJANdS+vw0YhusLIq+bszW8zmK2Fh1C2kDPX8FMvwIl1OUcFgvJoXLbAg==
"@actions/tool-cache@^1.5.5":
version "1.6.0"
resolved "https://registry.yarnpkg.com/@actions/tool-cache/-/tool-cache-1.6.0.tgz#5b425db2d642df65dd0d6bcec0d84dcdbca3f80d"
integrity sha512-+fyEBImPD3m5I0o6DflCO0NHY180LPoX8Lo6y4Iez+V17kO8kfkH0VHxb8mUdmD6hn9dWA9Ch1JA20fXoIYUeQ==
dependencies:
"@actions/core" "^1.2.3"
"@actions/exec" "^1.0.0"
"@actions/http-client" "^1.0.8"
"@actions/io" "^1.0.1"
semver "^6.1.0"
uuid "^3.3.2"
"@types/node@^14.0.14":
version "14.0.27"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.0.27.tgz#a151873af5a5e851b51b3b065c9e63390a9e0eb1"
integrity sha512-kVrqXhbclHNHGu9ztnAwSncIgJv/FaxmzXJvGXNdcCpV1b8u1/Mi6z6m0vwy0LzKeXFTPLH0NzwmoJ3fNCIq0g==
"@zeit/ncc@^0.22.3":
version "0.22.3"
resolved "https://registry.yarnpkg.com/@zeit/ncc/-/ncc-0.22.3.tgz#fca6b86b4454ce7a7e1e7e755165ec06457f16cd"
integrity sha512-jnCLpLXWuw/PAiJiVbLjA8WBC0IJQbFeUwF4I9M+23MvIxTxk5pD4Q8byQBSPmHQjz5aBoA7AKAElQxMpjrCLQ==
commander@^2.19.0:
version "2.20.3"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33"
integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==
commandpost@^1.0.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/commandpost/-/commandpost-1.4.0.tgz#89218012089dfc9b67a337ba162f15c88e0f1048"
integrity sha512-aE2Y4MTFJ870NuB/+2z1cXBhSBBzRydVVjzhFC4gtenEhpnj15yu0qptWGJsO9YGrcPZ3ezX8AWb1VA391MKpQ==
editorconfig@^0.15.0:
version "0.15.3"
resolved "https://registry.yarnpkg.com/editorconfig/-/editorconfig-0.15.3.tgz#bef84c4e75fb8dcb0ce5cee8efd51c15999befc5"
integrity sha512-M9wIMFx96vq0R4F+gRpY3o2exzb8hEj/n9S8unZtHSvYjibBp/iMufSzvmOcV/laG0ZtuTVGtiJggPOSW2r93g==
dependencies:
commander "^2.19.0"
lru-cache "^4.1.5"
semver "^5.6.0"
sigmund "^1.0.1"
lru-cache@^4.1.5:
version "4.1.5"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-4.1.5.tgz#8bbe50ea85bed59bc9e33dcab8235ee9bcf443cd"
integrity sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==
dependencies:
pseudomap "^1.0.2"
yallist "^2.1.2"
prettier@^2.0.5:
version "2.0.5"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.0.5.tgz#d6d56282455243f2f92cc1716692c08aa31522d4"
integrity sha512-7PtVymN48hGcO4fGjybyBSIWDsLU4H4XlvOHfq91pz9kkGlonzwTfYkaIEwiRg/dAJF9YlbsduBAgtYLi+8cFg==
pseudomap@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3"
integrity sha1-8FKijacOYYkX7wqKw0wa5aaChrM=
semver@^5.6.0:
version "5.7.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7"
integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==
semver@^6.1.0:
version "6.3.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==
sigmund@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/sigmund/-/sigmund-1.0.1.tgz#3ff21f198cad2175f9f3b781853fd94d0d19b590"
integrity sha1-P/IfGYytIXX587eBhT/ZTQ0ZtZA=
tunnel@0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/tunnel/-/tunnel-0.0.6.tgz#72f1314b34a5b192db012324df2cc587ca47f92c"
integrity sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==
typescript-formatter@^7.2.2:
version "7.2.2"
resolved "https://registry.yarnpkg.com/typescript-formatter/-/typescript-formatter-7.2.2.tgz#a147181839b7bb09c2377b072f20f6336547c00a"
integrity sha512-V7vfI9XArVhriOTYHPzMU2WUnm5IMdu9X/CPxs8mIMGxmTBFpDABlbkBka64PZJ9/xgQeRpK8KzzAG4MPzxBDQ==
dependencies:
commandpost "^1.0.0"
editorconfig "^0.15.0"
typescript@^3.9.5:
version "3.9.7"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.7.tgz#98d600a5ebdc38f40cb277522f12dc800e9e25fa"
integrity sha512-BLbiRkiBzAwsjut4x/dsibSTB6yWpwT5qWmC2OfuCg3GgVQCSgMs4vEctYPhsaGtd0AeuuHMkjZ2h2WG8MSzRw==
uuid@^3.3.2:
version "3.4.0"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee"
integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==
yallist@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/yallist/-/yallist-2.1.2.tgz#1c11f9218f076089a47dd512f93c6699a6a81d52"
integrity sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI=