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)
2021-02-17 13:53:51 +00:00
[](https://github.com/redhat-actions/buildah-build/actions?query=workflow%3ABuild)
2021-09-14 19:03:38 +00:00
[](https://github.com/redhat-actions/buildah-build/actions?query=workflow%3A%22Build+from+containerfile%22)
2021-02-17 13:53:51 +00:00
[](https://github.com/redhat-actions/buildah-build/actions?query=workflow%3A%22Link+checker%22)
2020-11-25 08:35:44 +00:00
< 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
2021-03-30 12:50:32 +00:00
Buildah Build is a GitHub Action for building Docker and Kubernetes-compatible images quickly and easily.
2020-11-13 11:55:02 +00:00
2021-03-30 12:50:32 +00:00
[Buildah ](https://github.com/containers/buildah/tree/master/docs ) 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.
2021-03-09 13:40:14 +00:00
< a id = "action-inputs" > < / a >
2020-11-13 14:20:53 +00:00
## Action Inputs
2021-03-09 13:40:14 +00:00
< a id = "dockerfile-build-inputs" > < / a >
2021-10-04 15:01:29 +00:00
### [Inputs for build from containerfile](https://github.com/containers/buildah/blob/main/docs/buildah-build.1.md)
2021-02-17 13:53:51 +00:00
| Input Name | Description | Default |
| ---------- | ----------- | ------- |
2021-07-09 15:12:48 +00:00
| arch | Label the image with this architecture, instead of defaulting to the host architecture. Refer to [Multi arch builds ](#multi-arch-builds ) for more information. | None (host architecture)
2021-11-11 13:54:40 +00:00
| archs | Same as input `arch` , use this for multiple architectures. Seperate them by a comma | None (host architecture)
2021-10-14 22:09:15 +00:00
| platform | Label the image with this platform, instead of defaulting to the host platform. Refer to [Multi arch builds ](#multi-arch-builds ) for more information. | None (host platform)
2021-11-11 13:54:40 +00:00
| platforms | Same as input `platform` , use this for multiple platforms. Seperate them by a comma | None (host platform)
2021-09-14 19:03:38 +00:00
| build-args | Build arguments to pass to the Docker build using `--build-arg` , if using a Containerfile that requires ARGs. Use the form `arg_name=arg_value` , and separate arguments with newlines. | None
2021-02-17 13:53:51 +00:00
| context | Path to directory to use as the build context. | `.`
2021-10-14 22:39:58 +00:00
| containerfiles\* | The list of Containerfile paths to perform a build using docker instructions. Separate filenames by newline. | **Required**
2021-04-12 17:13:19 +00:00
| extra-args | Extra args to be passed to buildah bud. Separate arguments by newline. Do not use quotes. | None
2021-10-14 22:39:58 +00:00
| image | Name to give to the output image. Refer to the [Image and Tag Inputs ](#image-tag-inputs ) section. | **Required** - unless all `tags` include image name
2021-03-30 12:50:32 +00:00
| layers | Set to true to cache intermediate layers during the build process. | None
2021-10-14 22:39:58 +00:00
| oci | Build the image using the OCI metadata format, instead of the Docker format. | `false`
| tags | One or more tags to give the new image. Separate by whitespace. Refer to the [Image and Tag Inputs ](#image-tag-inputs ) section. | `latest`
2021-10-19 18:41:41 +00:00
| labels | One or more labels to give the new image. Separate by newline. | None
2021-10-14 22:39:58 +00:00
> \* The `containerfiles` input was previously `dockerfiles`. Refer to [this issue](https://github.com/redhat-actions/buildah-build/issues/57).
2021-02-17 13:53:51 +00:00
2021-03-09 13:40:14 +00:00
< a id = "scratch-build-inputs" > < / a >
2021-10-04 15:01:29 +00:00
### [Inputs for build without containerfile](https://github.com/containers/buildah/blob/main/docs/buildah-config.1.md)
2021-02-17 13:53:51 +00:00
| Input Name | Description | Default |
| ---------- | ----------- | ------- |
2021-07-09 15:12:48 +00:00
| arch | Label the image with this architecture, instead of defaulting to the host architecture. Refer to [Multi arch builds ](#multi-arch-builds ) for more information. | None (host architecture)
2021-11-11 13:54:40 +00:00
| archs | Same as input `arch` , use this for multiple architectures. Seperate them by a comma | None (host architecture)
2021-10-14 22:39:58 +00:00
| base-image | The base image to use for the container. | **Required**
2021-02-17 13:53:51 +00:00
| content | Paths to files or directories to copy inside the container to create the file image. This is a multiline input to allow you to copy multiple files/directories.| None
2021-10-14 22:39:58 +00:00
| entrypoint | The entry point to set for the container. Separate arguments by newline. | None
| envs | The environment variables to be set when running the container. Separate key=value pairs by newline. | None
| image | Name to give to the output image. Refer to the [Image and Tag Inputs ](#image-tag-inputs ) section. | **Required** - unless all tags include image name
| oci | Build the image using the OCI metadata format, instead of the Docker format. | `false`
2021-02-17 13:53:51 +00:00
| port | The port to expose when running the container. | None
2021-10-14 22:39:58 +00:00
| tags | One or more tags to give the new image. Separate by whitespace. Refer to the [Image and Tag Inputs ](#image-tag-inputs ) section. | `latest`
2021-10-19 18:41:41 +00:00
| labels | One or more labels to give the new image. Separate by newline. | None
2021-02-17 13:53:51 +00:00
| workdir | The working directory to use within the container. | None
2020-11-13 14:20:53 +00:00
2021-10-14 22:39:58 +00:00
< a id = "image-tag-inputs" > < / a >
### Image and Tags Inputs
The `image` and `tags` inputs can be provided in one of two forms.
At least one tag must always be provided in `tags` . Multiple tags are separated by whitespace.
**Option 1**: Provide both `image` and `tags` inputs. The image will be built, and then tagged in the form `${image}:${tag}` for each tag.
For example:
```yaml
2021-10-27 16:32:53 +00:00
image: quay.io/my-namespace/my-image
2021-10-14 22:39:58 +00:00
tags: v1 v1.0.0
```
2021-10-27 16:32:53 +00:00
will create the image and apply two tags: `quay.io/my-namespace/my-image:v1` and `quay.io/my-namespace/my-image:v1.0.0` .
2021-10-14 22:39:58 +00:00
**Option 2**: Provide only the `tags` input, including the image name in each tag. The image will be built, and then tagged with each `tag` . In this case, the `image` input is ignored.
For example:
```yaml
# 'image' input is not set
2021-10-27 16:32:53 +00:00
tags: quay.io/my-namespace/my-image:v1 quay.io/my-namespace/my-image:v1.0.0
2021-10-14 22:39:58 +00:00
```
2021-10-27 16:32:53 +00:00
will also apply two tags: `quay.io/my-namespace/my-image:v1` and `quay.io/my-namespace/my-image:v1.0.0` .
2021-10-14 22:39:58 +00:00
If the `tags` input does not have image names in the `${name}:${tag}` form, then the `image` input must be set.
2021-10-12 17:21:52 +00:00
2021-03-09 13:40:14 +00:00
< a id = "outputs" > < / a >
2021-02-01 17:54:50 +00:00
## Action Outputs
2021-10-14 22:39:58 +00:00
`image` : The name of the image as it was input.< br >
`tags` : A space-separated list of the tags that were applied to the new image.< br >
`image-with-tag` : The name of the image, tagged with the first tag.< br >
2021-10-12 17:21:52 +00:00
For example:
``` yml
image: "spring-image"
tags: "latest ${{ github.sha }}"
image-with-tag: "spring-image:latest"
```
2021-03-09 13:40:14 +00:00
< a id = "build-types" > < / a >
2020-11-19 18:46:44 +00:00
## Build Types
2020-11-19 08:19:57 +00:00
2021-09-14 19:03:38 +00:00
You can configure the `buildah` action to build your image using one or more Containerfiles, or none at all.
2020-11-19 08:19:57 +00:00
2021-03-09 13:40:14 +00:00
< a id = "build-using-dockerfile" > < / a >
2021-09-14 19:03:38 +00:00
### Building using Containerfiles
2020-11-19 08:19:57 +00:00
2021-09-14 19:03:38 +00:00
If you have been building your images with an existing Containerfile, `buildah` can reuse your Containerfile.
2020-11-19 18:46:44 +00:00
2021-09-14 19:03:38 +00:00
In this case the inputs needed are `image` and `containerfiles` . `tag` is also recommended. If your Containerfile requires ARGs, these can be passed using `build-arg` .
2020-11-19 08:19:57 +00:00
```yaml
2021-09-14 19:03:38 +00:00
name: Build Image using Containerfile
2020-11-19 08:19:57 +00:00
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 }}
2021-09-14 19:03:38 +00:00
containerfiles: |
./Containerfile
2020-11-23 19:03:32 +00:00
build-args: |
some_arg=some_value
2020-11-19 08:19:57 +00:00
```
2021-03-09 13:40:14 +00:00
< a id = "scratch-build" > < / a >
2020-11-19 08:19:57 +00:00
2021-09-14 19:03:38 +00:00
### Building without a Containerfile
2020-11-19 18:46:44 +00:00
2021-09-14 19:03:38 +00:00
Building without a Containerfile requires additional inputs, that would normally be specified in the Containerfile.
2020-11-19 08:19:57 +00:00
2021-09-14 19:03:38 +00:00
Do not set `containerfiles` if you are doing a build from scratch. Otherwise those Containerfiles 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`
2021-09-14 19:03:38 +00:00
- In a Containerfile, this would be the `FROM` directive.
2020-11-19 18:46:44 +00:00
- `content` to copy into the new image
2021-09-14 19:03:38 +00:00
- In a Containerfile, this would be `COPY` directives.
2020-11-19 18:46:44 +00:00
- `entrypoint` so the container knows what command to run.
2021-09-14 19:03:38 +00:00
- In a Containerfile, this would be the `ENTRYPOINT` .
2020-11-19 19:49:47 +00:00
- 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:
2021-09-14 19:03:38 +00:00
name: Build image without Containerfile
2020-11-13 14:20:53 +00:00
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
```
2021-03-03 20:40:40 +00:00
< a id = "multi-arch-builds" > < / a >
2021-03-09 13:40:14 +00:00
2021-03-03 20:40:40 +00:00
## Multi arch builds
2021-07-09 15:12:48 +00:00
Refer to the [multi-arch example ](./.github/workflows/multiarch.yml ).
### Emulating RUN instructions
2021-09-14 19:03:38 +00:00
Cross-architecture builds from containerfiles containing `RUN` instructions require `qemu-user-static` emulation registered in the Linux kernel.
2021-07-09 15:12:48 +00:00
For example, run `sudo apt install qemu-user-static` on Debian hosts, or `sudo dnf install qemu-user-static` on Fedora.
You can run a [containerized version of the registration ](https://hub.docker.com/r/tonistiigi/binfmt ) if the package does not exist for your distribution:
```sh
2021-06-15 09:53:58 +00:00
sudo podman run --rm --privileged docker.io/tonistiigi/binfmt --install all
2021-03-03 20:40:40 +00:00
```
2021-07-09 15:12:48 +00:00
This registration remains active until the host reboots.
2021-10-14 22:09:15 +00:00
### The `arch` and `platform` inputs
The `arch` and `platform` arguments override the Architecture and Platform labels in the output image, respectively. They do not actually affect the architectures and platforms the output image will run on. The image must still be built for the required architecture or platform.
2021-07-09 15:12:48 +00:00
There is a simple example [in this issue ](https://github.com/redhat-actions/buildah-build/issues/60#issuecomment-876552452 ).
### Creating a Multi-Arch Image List
2021-11-11 13:54:40 +00:00
Input `archs` and `platforms` is provided to build the multi architecture images. If one of these input is provided then a manifest is built with the multiple architecture images. Name of the manifest is taken from the inputs `image` and `tags` .
Incase multiple tags are provided then multiple manifest is created based on the provided tags.
2021-07-09 15:12:48 +00:00
2021-11-11 13:54:40 +00:00
[`push-to-registry` ](https://github.com/redhat-actions/push-to-registry ) action can be used to push the generated manifest.
2021-03-03 20:40:40 +00:00
2021-10-12 17:21:52 +00:00
## Build with docker/metadata-action
Refer to the [docker/metadata-action example ](./.github/workflows/docker_metadata_action.yml ).
2020-12-21 17:06:14 +00:00
## Using private images
2021-04-12 14:21:21 +00:00
If your build references a private image, run [**podman-login** ](https://github.com/redhat-actions/podman-login ) in a step before this action so you can pull the image.
2020-12-21 17:06:14 +00:00
For example:
2021-04-12 14:21:21 +00:00
2020-12-21 17:06:14 +00:00
```yaml
- name: Log in to Red Hat Registry
2021-05-12 05:17:33 +00:00
uses: redhat-actions/podman-login@v1
2021-04-12 14:21:21 +00:00
with:
registry: registry.redhat.io
username: ${{ secrets.REGISTRY_REDHAT_IO_USER }}
password: ${{ secrets.REGISTRY_REDHAT_IO_PASSWORD }}
2020-12-21 17:06:14 +00:00
```