GitHub Action to use 'buildah' to build a container image.
Find a file
Luca Stocchi 0c1d3d77d8
update readme
Signed-off-by: Luca Stocchi <lstocchi@redhat.com>
2020-11-18 09:06:11 +01:00
dist fix issues when building image with dockerfile 2020-11-18 08:24:22 +01:00
src fix issues when building image with dockerfile 2020-11-18 08:24:22 +01:00
.gitignore add language recognizer 2020-11-13 12:38:29 +01:00
action.yml update readme 2020-11-18 09:06:11 +01:00
language-image.json add language recognizer 2020-11-13 12:38:29 +01:00
LICENSE add missing files for the action 2020-11-06 22:48:47 +01:00
package.json readme + cleaning 2020-11-13 15:20:53 +01:00
README.md update readme 2020-11-18 09:06:11 +01:00
tsconfig.json add support for building images with docker files (#4) 2020-11-17 15:54:29 +01:00

buildah-action

tag badge license badge size badge

Buildah is a GitHub Action for building OCI-compatible (Docker- and Kubernetes-compatible) images quickly and easily.

Buildah action works only on Linux distributions, and it is not supported on Windows or Mac platforms at this time.

Note that GitHub's Ubuntu Environments (ubuntu-20.04 and ubuntu-18.04) come with buildah 1.17.0 installed. So, if you are not using those Ubuntu environments you need to make sure to install buildah tool in an early step.

Action Inputs

input Required Description
image Yes Name to give to the image that will be eventually created.
base-name No The base image to use to create the initial container. If not specified, the action will try to pick one automatically. (N.B: At this time the action is only able to auto select Java base image)
dockerfiles No The list of Dockerfile paths to perform a build using docker instructions. This is a multiline input to add multiple values.
context No The path of the directory to use as context (default: .)
content No 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. For example -
content: |
target/spring-petclinic-2.3.0.BUILD-SNAPSHOT.jar
entrypoint No The entry point to set for the container. This is a multiline input to add multiple values. For example -
entrypoint: |
java
-jar
spring-petclinic-2.3.0.BUILD-SNAPSHOT.jar
port No The port to expose when running the container.
working-dir No The working directory to use within the container.
envs No The environment variables to be set when running the container. This is a multiline input to add multiple environment variables.For example -
envs: |
GOPATH=/root/buildah

Build an image using Dockerfile or from scratch

One of the advantages of using the buildah action is that you can decide the way you want to build your image.

If you have been using Docker and have some existing Dockerfiles, buildah is able to build images by using them. In this case the inputs needed are just image, dockerfiles and content.

An example below

name: Build Image using Dockerfile
on: [push]

jobs:
  build:
    name: Build image
    runs-on: ubuntu-latest

    steps:
    - name: Checkout
      uses: actions/checkout@v2
    - name: Buildah Action
      uses: redhat-actions/buildah-action@v1
      with:
        image: awesome-name:v1
        dockerfiles: |
          ./Dockerfile          

On the other hand, a build from scratch may require more inputs as it needs to execute a series of steps that can be summarized in:

  • Create a new container by using the base image (input: base-image)
  • Copy all files/directories inside the newly-created container (input: content)
  • Set up the image configuration values (inputs: entrypoint,port,envs)
  • Build an optimized image

Example of building a Spring Boot Java app image below

name: Build Image
on: [push]

jobs:
  build:
    name: Build image
    runs-on: ubuntu-latest

    steps:
    - name: Checkout
      uses: actions/checkout@v2

    - name: Maven
      run: mvn package
    - name: Build Action
      uses: redhat-actions/buildah-action@v1
      with:
        image: awesome-name:v1
        content: |
          target/spring-petclinic-2.3.0.BUILD-SNAPSHOT.jar          
        entrypoint: |
          java
          -jar
          spring-petclinic-2.3.0.BUILD-SNAPSHOT.jar          
        port: 8080

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 and we will fix it as soon as possible.

License

MIT, See LICENSE for more information.