GitHub Action
Source to Image Build
s2i-build
is a Github Action to build OCI-compatible container images from source code.
Source-to-Image (S2I) is a toolkit and workflow for building reproducible container images from source code. S2I produces images by injecting source code into a base S2I container image and letting the container prepare that source code for execution. The base S2I container images contain the language runtime and build tools needed for building and running the source code.
This Action will install the latest version of S2I.
NOTE:
s2i-build
only works on Linux platforms, because it relies on the Docker daemon.
If you are using GitHub's Ubuntu runners, the Docker daemon will already be available.
Otherwise, you can use Docker Setup Buildx to set up and start the Docker daemon.
Also see buildah-build for more configurable method of building images, from scratch or from a Dockerfile.
Once an image has been built, push-to-registry can be used to push it to an image registry.
Input | Required | Default | Description |
---|---|---|---|
builder_image | Yes | - | The location of the S2I builder image. A curated list of builder images can be found here. |
image_name | Yes | - | The name of the image to produce. |
image_tag | No | latest | The tag of the image to produce. |
path_context | No | . |
The location of the path to run S2I from. This should be the path where your source code is stored. |
log_level | No | 1 | Log level when running S2I. Can be 0 (least verbose) to 5 (most verbose). |
env_vars | No | - | List of environment variable key-value pairs to pass to the s2i builder context. (eg. key=value , mysecret=${{ secrets.MY_SECRET }} ). |
Please refer here for a curated list of well maintained builder images to use for S2I.
Below is an example end to end workflow to build and push a Java application image using s2i-build.
# This workflow builds a container image of a java
# application using the source to image build strategy,
# and pushes the image to quay.io.
steps:
env:
IMAGE_NAME: my-java-app
IMAGE_TAG: v1
- name: Checkout
uses: actions/checkout@v2
# Setup S2i and Build container image
- name: Setup and Build
uses: redhat-actions/s2i-build@v1
with:
path_context: '.'
# Builder image for a java project
builder_image: 'registry.access.redhat.com/openjdk/openjdk-11-rhel7'
image_name: ${{ env.IMAGE_NAME }}
image_tag: ${{ env.IMAGE_TAG }}
# Push Image to Quay registry
- name: Push To Quay Action
uses: redhat-actions/push-to-registry@v1
with:
image: ${{ env.IMAGE_NAME }}
tag: ${{ env.IMAGE_TAG }}
registry: quay.io/${{ secrets.QUAY_USERNAME }}
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}