Skip to content

Commit 2419fc7

Browse files
committed
initial upload
1 parent 080d037 commit 2419fc7

File tree

8 files changed

+446
-2
lines changed

8 files changed

+446
-2
lines changed

.devcontainer/devcontainer.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// For format details, see https://aka.ms/devcontainer.json.
2+
{
3+
"name": "NodeJS",
4+
"image": "mcr.microsoft.com/devcontainers/javascript-node:20",
5+
"customizations": {
6+
"vscode": {
7+
"extensions": [
8+
"github.vscode-github-actions"
9+
]
10+
}
11+
},
12+
"remoteUser": "node"
13+
}

.github/workflows/tests.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Tests
2+
on:
3+
push
4+
5+
jobs:
6+
least:
7+
runs-on: ubuntu-22.04
8+
container:
9+
image: ghcr.io/omniproc/act-buildkit-runner:1.0.0
10+
steps:
11+
- name: oci metadata
12+
id: meta
13+
uses: docker/metadata-action@v5
14+
with:
15+
images: |
16+
ghcr.io/${{ github.repository }}
17+
tags: |
18+
type=sha,event=branch
19+
type=raw,value=latest
20+
- name: oci build
21+
uses: omniproc/buildkit-build-push-action@main
22+
with:
23+
dryrun: 'true'
24+
tags: ${{ steps.meta.outputs.tags }}
25+
addr: 'tcp://buildkitd:1234'
26+
output: 'type=image,push=true'
27+
cache:
28+
runs-on: ubuntu-22.04
29+
container:
30+
image: ghcr.io/omniproc/act-buildkit-runner:1.0.0
31+
steps:
32+
- name: oci metadata
33+
id: meta
34+
uses: docker/metadata-action@v5
35+
with:
36+
images: |
37+
ghcr.io/${{ github.repository }}
38+
tags: |
39+
type=sha,event=branch
40+
type=raw,value=latest
41+
- name: oci build
42+
uses: omniproc/buildkit-build-push-action@main
43+
with:
44+
dryrun: 'true'
45+
tags: ${{ steps.meta.outputs.tags }}
46+
addr: 'tcp://buildkitd:1234'
47+
output: 'type=image,push=true'
48+
export-cache: 'type=registry,ref=ghcr.io/${{ github.repository }}:buildcache,mode=max,push=true'
49+
import-cache: 'type=registry,ref=ghcr.io/${{ github.repository }}:buildcache'

.vscode/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"git.autofetch": true,
3+
"editor.formatOnSave": true
4+
}

README.md

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,71 @@
1-
# buildkit-build-push-action
2-
Buildkit - Build & Push Action
1+
# Buildkit - Build & Push Action
2+
3+
A minimally opinionated GitHub action for BuildKit's [`buildctl`](https://github.com/moby/buildkit/blob/master/docs/reference/buildctl.md).
4+
5+
# Requirements
6+
7+
- BuildKit's `buildctl` ~=v0.15.1 has to be available in the path of the action runner, e.g. [act-buildkit-runner](https://github.com/omniproc/act-buildkit-runner).
8+
9+
# Inputs
10+
11+
| Name | Required | Type | Description | Example |
12+
| --------------------------- | -------- | ------- | -------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
13+
| `debug` | No | Boolean | Enable debug output in logs | `false` |
14+
| `addr` | Yes | String | Buildkitd address | `tcp://buildkitd:1234` |
15+
| `log_format` | No | String | Log formatter: json or text | `text` |
16+
| `tlsdir` | No | String | Directory containing CA certificate, client certificate, and client key | `/path/to/tls-data` |
17+
| `output` | Yes | String | Define exports for build result. `name=` may be left out if `tags` are provided. | `type=image,name=ghcr.io/${{ github.repository }}:latest,ghcr.io/${{ github.repository }}:stable,push=true` |
18+
| `progress` | No | String | Set type of progress (auto, plain, tty, rawjson) | `auto` |
19+
| `local` | Yes | List | Allow build access to the local directory | <pre> local: \| <br>&emsp;context=.<br>&emsp;dockerfile=.<br></pre> |
20+
| `frontend` | No | String | Define frontend used for build | `dockerfile.v0` |
21+
| `opt` | No | List | Define custom options for frontend | <pre> opt: \| <br>&emsp;filename=Dockerfile<br>&emsp;platform=linux/amd64<br></pre> |
22+
| `no_cache` | No | Boolean | Disable cache for all the vertices | `true` |
23+
| `export-cache` | No | String | Export build cache | `type=registry,ref=ghcr.io/${{ github.repository }}:buildcache,mode=max,push=true` |
24+
| `import-cache` | No | String | Import build cache | `type=registry,ref=ghcr.io/${{ github.repository }}:buildcache` |
25+
| `secret` | No | List | Secret value exposed to the build | <pre> secret: \| <br>&emsp;id=foo,src=/path/to/foo<br>&emsp;id=bar,src=/path/to/bar<br></pre> |
26+
| `registry-auth-tls-context` | No | String | Overwrite TLS configuration when authenticating with registries | `host=https://myserver:2376,insecure=false,ca=/path/to/my/ca.crt,cert=/path/to/my/cert.crt,key=/path/to/my/key.crt` |
27+
| `tags` | Yes | List | Image tags extending the `name`s used in the `output` input | <pre> tags: \| <br>&emsp;{{ github.repository }}:sha-ca56cb6<br>&emsp;{{ github.repository }}:latest<br></pre> |
28+
| `dryrun` | No | Boolean | Only print the resulting `buildctl` command but do not actually execute it | `false` |
29+
30+
# Example usage
31+
32+
When pushing the built image make sure to have authenticated with the registry using e.g. [docker/login-action](https://github.com/docker/login-action) in a step before.
33+
34+
```yaml
35+
name: Example
36+
on:
37+
push
38+
jobs:
39+
build:
40+
runs-on: ubuntu-22.04
41+
container:
42+
image: ghcr.io/omniproc/act-buildkit-runner:1.0.0
43+
steps:
44+
- name: oci metadata
45+
id: meta
46+
uses: docker/metadata-action@v5
47+
with:
48+
images: |
49+
ghcr.io/${{ github.repository }}
50+
tags: |
51+
type=sha,event=branch
52+
type=raw,value=latest,enable={{is_default_branch}}
53+
- name: oci build
54+
uses: omniproc/buildkit-build-push-action@v1.0.0
55+
with:
56+
tags: ${{ steps.meta.outputs.tags }}
57+
addr: 'tcp://buildkitd:1234'
58+
output: 'type=image,push=false'
59+
```
60+
61+
# Development
62+
63+
```bash
64+
# When a new version of this action is ready, use ncc to bundle it.
65+
ncc build src/index.js --license licenses.txt
66+
# Add everything to Git and tag the commit. The tag will be used as action version.
67+
git add .
68+
git commit -m "Release vX.x"
69+
git tag -a -m "Release vX.x" vX.x
70+
git push --follow-tags
71+
```

action.yml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: 'Buildkit build and push image'
2+
description: 'Build docker image using buildkits buildctl'
3+
author: 'Robert Ruf'
4+
branding:
5+
icon: 'bold'
6+
color: 'yellow'
7+
inputs:
8+
# ----- buildctl global -----
9+
# Boolean: 'true' or 'false'
10+
debug:
11+
description: 'Enable debug output in logs'
12+
required: false
13+
default: 'false'
14+
# String
15+
addr:
16+
description: 'Buildkitd address'
17+
required: true
18+
# String
19+
log-format:
20+
description: 'Log formatter: json or text'
21+
required: false
22+
default: ''
23+
# String
24+
tlsdir:
25+
description: 'Directory containing CA certificate, client certificate, and client key'
26+
required: false
27+
# ----- build command -----
28+
# String
29+
output:
30+
description: 'Define exports for build result, e.g. --output type=image,name=docker.io/username/image,push=true'
31+
required: true
32+
default: ''
33+
# String
34+
progress:
35+
description: 'Set type of progress (auto, plain, tty, rawjson). Use plain to show container output'
36+
required: false
37+
default: ''
38+
# String-Array: YAML multiline string as block scalar (literal) using newline block chomping (clip)
39+
local:
40+
description: "Allow build access to the local directory."
41+
required: false
42+
default: |
43+
context=.
44+
dockerfile=.
45+
# String
46+
frontend:
47+
description: 'Define frontend used for build'
48+
required: false
49+
default: 'dockerfile.v0'
50+
# String-Array: YAML multiline string as block scalar (literal) using newline block chomping (clip)
51+
opt:
52+
description: 'Define custom options for frontend, e.g. --opt target=foo --opt build-arg:foo=bar'
53+
required: false
54+
default: |
55+
filename=Dockerfile
56+
platform=linux/amd64
57+
# Boolean: 'true' or 'false'
58+
no-cache:
59+
description: 'Disable cache for all the vertices'
60+
required: false
61+
default: 'false'
62+
# String
63+
export-cache:
64+
description: 'Export build cache, e.g. --export-cache type=registry,ref=example.com/foo/bar, or --export-cache type=local,dest=path/to/dir'
65+
required: false
66+
default: ''
67+
# String
68+
import-cache:
69+
description: 'Import build cache, e.g. --import-cache type=registry,ref=example.com/foo/bar, or --import-cache type=local,src=path/to/dir'
70+
required: false
71+
default: ''
72+
# String-Array: YAML multiline string as block scalar (literal) using newline block chomping (clip)
73+
secret:
74+
description: 'Secret value exposed to the build. Format id=secretname,src=filepath'
75+
required: false
76+
default: ''
77+
# String
78+
registry-auth-tlscontext:
79+
description: 'Overwrite TLS configuration when authenticating with registries, e.g. --registry-auth-tlscontext host=https://myserver:2376,insecure=false,ca=/path/to/my/ca.crt,cert=/path/to/my/cert.crt,key=/path/to/my/key.crt'
80+
required: false
81+
default: ''
82+
# ----- action ux -----
83+
# String-Array: YAML multiline string as block scalar (literal) using newline block chomping (clip)
84+
tags:
85+
description: 'Image tags extending the tags used with the output command'
86+
required: true
87+
default: ''
88+
# Boolean: 'true' or 'false'
89+
dryrun:
90+
description: 'Only output the buildctl command but do not actually execute it'
91+
required: false
92+
default: 'false'
93+
runs:
94+
using: 'node20'
95+
main: 'dist/index.js'

package-lock.json

Lines changed: 91 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "buildkit-build-push-action",
3+
"version": "1.0.0",
4+
"description": "A opinionated GitHub action for BuildKit's [`buildctl`](https://github.com/moby/buildkit/blob/master/docs/reference/buildctl.md).",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC",
12+
"dependencies": {
13+
"@actions/core": "^1.10.1",
14+
"@actions/exec": "^1.1.1"
15+
}
16+
}

0 commit comments

Comments
 (0)