2020-11-27 22:13:23 +00:00
# buildah-build
2021-02-08 16:24:18 +00:00
[](https://github.com/redhat-actions/buildah-build/actions?query=workflow%3A%22CI+checks%22)
2020-11-25 08:35:44 +00:00
[](https://github.com/redhat-actions/buildah-build/actions?query=workflow%3A%22Test+Build%22)
< br >
< br >
2020-11-30 19:45:01 +00:00
[](https://github.com/redhat-actions/buildah-build/tags)
2020-11-23 18:27:19 +00:00
[](./LICENSE)
[](./dist)
2020-11-17 04:29:58 +00:00
2020-11-27 17:30:37 +00:00
Buildah is a GitHub Action for building Docker and Kubernetes-compatible images quickly and easily.
2020-11-13 11:55:02 +00:00
2020-11-23 22:08:21 +00:00
Buildah only works on Linux. GitHub's [Ubuntu Environments ](https://github.com/actions/virtual-environments#available-environments ) (`ubuntu-18.04` and newer) come with buildah installed. If you are not using these environments, or if you want to use a different version, you must first [install buildah ](https://github.com/containers/buildah/blob/master/install.md ).
2020-11-13 11:55:02 +00:00
2020-11-23 18:27:19 +00:00
After building your image, use [push-to-registry ](https://github.com/redhat-actions/push-to-registry ) to push the image and make it pullable.
2020-11-13 14:20:53 +00:00
## Action Inputs
< table >
< thead >
< tr >
2020-11-19 08:19:57 +00:00
< th > Input< / th >
< th > Required< / th >
2020-11-13 14:20:53 +00:00
< th > Description< / th >
< / tr >
< / thead >
< tr >
2020-11-19 08:19:57 +00:00
< td > image< / td >
< td > Yes< / td >
2020-11-19 18:46:44 +00:00
< td > Name to give the output image.< / td >
2020-11-13 14:20:53 +00:00
< / tr >
2020-11-19 09:00:49 +00:00
< tr >
2021-02-01 17:54:50 +00:00
< td > tags< / td >
2020-11-19 09:00:49 +00:00
< td > No< / td >
2020-11-19 18:46:44 +00:00
< td >
2021-02-01 17:54:50 +00:00
The tags of the image to build. For multiple tags, separate by a space. For example, < code > latest ${{ github.sha }}< / code > .< br >
2020-11-19 18:46:44 +00:00
Default: < code > latest< / code >
< / td >
2020-11-19 09:00:49 +00:00
< / tr >
2020-11-13 14:20:53 +00:00
< tr >
2020-11-19 18:46:44 +00:00
< td > base-image< / td >
2020-11-19 08:19:57 +00:00
< td > No< / td >
2021-02-01 17:54:50 +00:00
< td > The base image to use for the container.< / td >
2020-11-19 08:19:57 +00:00
< / tr >
< tr >
< td > dockerfiles< / td >
< td > No< / td >
2020-11-19 19:49:47 +00:00
< td > The list of Dockerfile paths to perform a build using docker instructions. This is a multiline input to allow multiple Dockerfiles.
2020-11-19 18:46:44 +00:00
< / td >
2020-11-19 08:19:57 +00:00
< / tr >
2020-11-26 18:00:17 +00:00
< tr >
< td > oci< / td >
< td > No< / td >
< td >
Build the image using the OCI format, instead of the Docker format.< br >
By default, this is < code > false< / code > , because images built using the OCI format have < a href = "https://github.com/docker/hub-feedback/issues/1871" > issues< / a > when published to Dockerhub.
< / td >
< / tr >
2020-11-19 08:19:57 +00:00
< tr >
< td > context< / td >
< td > No< / td >
2020-11-19 18:46:44 +00:00
< td > Path to directory to use as the build context.< br >
Default: < code > .< / code > < / td >
2020-11-13 14:20:53 +00:00
< / tr >
2020-11-23 19:03:32 +00:00
< tr >
< td > build-args< / td >
< td > No< / td >
< td > Build arguments to pass to the Docker build using < code > --build-arg< / code > , if using a Dockerfile that requires ARGs.< br >
Uses the form < code > arg_name=arg_value< / code > , and separate arguments with newlines.< / td >
< / tr >
2020-11-13 14:20:53 +00:00
< tr >
< td > content< / td >
2020-11-19 08:19:57 +00:00
< td > No< / td >
2020-11-19 18:46:44 +00:00
< td > The content to copy inside the container to create the final image. This is a multiline input to allow you to copy more than one file/directory.< br >
< pre > content: |
target/spring-petclinic-2.3.0.BUILD-SNAPSHOT.jar< / pre >
< / td >
2020-11-13 14:20:53 +00:00
< / tr >
< tr >
< td > entrypoint< / td >
2020-11-19 08:19:57 +00:00
< td > No< / td >
2020-11-19 19:49:47 +00:00
< td > The entry point to set for the container. This is a multiline input; split arguments across lines.
< pre > entrypoint: |
java
-jar
spring-petclinic-2.3.0.BUILD-SNAPSHOT.jar< / pre >
2020-11-19 18:46:44 +00:00
< / td >
2020-11-13 14:20:53 +00:00
< / tr >
< tr >
< td > port< / td >
2020-11-19 08:19:57 +00:00
< td > No< / td >
< td > The port to expose when running the container.< / td >
2020-11-13 14:20:53 +00:00
< / tr >
< tr >
2020-11-19 18:46:44 +00:00
< td > workdir< / td >
2020-11-19 08:19:57 +00:00
< td > No< / td >
< td > The working directory to use within the container.< / td >
2020-11-13 14:20:53 +00:00
< / tr >
< tr >
< td > envs< / td >
2020-11-19 08:19:57 +00:00
< td > No< / td >
2020-11-19 18:46:44 +00:00
< td > The environment variables to be set when running the container. This is a multiline input to add multiple environment variables.< br >
< pre >
envs: |
GOPATH=/root/buildah/go< / pre >
< / td >
2020-11-13 14:20:53 +00:00
< / tr >
< / table >
2021-02-01 17:54:50 +00:00
## Action Outputs
`image` : The name of the built image.< br >
For example, `spring-image` .
`tags` : A list of the tags that were created, separated by spaces.< br >
For example, `latest ${{ github.sha }}` .
2020-11-19 18:46:44 +00:00
## Build Types
2020-11-19 08:19:57 +00:00
2020-12-10 14:09:41 +00:00
You can configure the `buildah` action to build your image using one or more Dockerfiles, or none at all.
2020-11-19 08:19:57 +00:00
2020-12-10 14:09:41 +00:00
### Building using Dockerfiles
2020-11-19 08:19:57 +00:00
2020-12-10 14:09:41 +00:00
If you have been building your images with an existing Dockerfile, `buildah` can reuse your Dockerfile.
2020-11-19 18:46:44 +00:00
2020-11-23 19:03:32 +00:00
In this case the inputs needed are `image` and `dockerfiles` . `tag` is also recommended. If your Dockerfile requires ARGs, these can be passed using `build-arg` .
2020-11-19 08:19:57 +00:00
```yaml
name: Build Image using Dockerfile
on: [push]
jobs:
build:
name: Build image
runs-on: ubuntu-latest
steps:
2020-11-19 18:46:44 +00:00
- uses: actions/checkout@v2
2020-11-19 08:19:57 +00:00
- name: Buildah Action
2021-02-14 21:04:33 +00:00
uses: redhat-actions/buildah-build@v2
2020-11-19 08:19:57 +00:00
with:
2020-11-19 18:46:44 +00:00
image: my-new-image
2021-02-01 17:54:50 +00:00
tags: v1 ${{ github.sha }}
2020-11-19 08:19:57 +00:00
dockerfiles: |
./Dockerfile
2020-11-23 19:03:32 +00:00
build-args: |
some_arg=some_value
2020-11-19 08:19:57 +00:00
```
2020-12-10 14:09:41 +00:00
### Building without a Dockerfile
2020-11-19 18:46:44 +00:00
2020-12-10 14:09:41 +00:00
Building without a Dockerfile requires additional inputs, that would normally be specified in the Dockerfile.
2020-11-19 08:19:57 +00:00
2020-12-10 14:09:41 +00:00
Do not set `dockerfiles` if you are doing a build from scratch. Otherwise those Dockerfiles will be used, and the inputs below will be ignored.
2020-11-13 14:20:53 +00:00
2020-11-19 18:46:44 +00:00
- An output `image` name and usually a `tag` .
- `base-image`
- In a Dockerfile, this would be the `FROM` directive.
- `content` to copy into the new image
- In a Dockerfile, this would be `COPY` directives.
- `entrypoint` so the container knows what command to run.
2020-11-19 19:49:47 +00:00
- In a Dockerfile, this would be the `ENTRYPOINT` .
- All other optional configuration inputs, such as `port` , `envs` , and `workdir` .
2020-11-19 18:46:44 +00:00
Example of building a Spring Boot Java app image:
2020-11-17 04:29:58 +00:00
```yaml
name: Build Image
2020-11-13 14:20:53 +00:00
on: [push]
jobs:
2020-11-19 18:46:44 +00:00
build-image:
2020-11-13 14:20:53 +00:00
name: Build image
runs-on: ubuntu-latest
steps:
2020-11-19 18:46:44 +00:00
- uses: actions/checkout@v2
- run: mvn package
2020-11-13 14:20:53 +00:00
2020-11-19 18:46:44 +00:00
- name: Build Image
2021-02-14 21:04:33 +00:00
uses: redhat-actions/buildah-build@v2
2020-11-13 14:20:53 +00:00
with:
2020-11-19 18:46:44 +00:00
base-image: docker.io/fabric8/java-alpine-openjdk11-jre
image: my-new-image
2021-02-01 17:54:50 +00:00
tags: v1
2020-11-13 14:20:53 +00:00
content: |
target/spring-petclinic-2.3.0.BUILD-SNAPSHOT.jar
2020-11-19 18:46:44 +00:00
entrypoint: java -jar spring-petclinic-2.3.0.BUILD-SNAPSHOT.jar
2020-11-13 14:20:53 +00:00
port: 8080
```
2020-12-21 17:06:14 +00:00
## Using private images
If your build requires a private image, you have to `docker login` in a step before running this action.
For example:
```yaml
- name: Log in to Red Hat Registry
run: echo "${{ secrets.REGISTRY_REDHAT_IO_PASSWORD }}" | docker login registry.redhat.io -u "${{ secrets.REGISTRY_REDHAT_IO_USER }}" --password-stdin
```
2020-11-13 14:20:53 +00:00
## Contributing
This is an open source project open to anyone. This project welcomes contributions and suggestions!
## Feedback & Questions
If you discover an issue please file a bug in [GitHub issues ](https://github.com/redhat-actions/buildah/issues ) and we will fix it as soon as possible.
## License
MIT, See [LICENSE ](https://github.com/redhat-actions/buildah/blob/main/LICENSE.md ) for more information.