Skip to content
Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

s2i-build

CI checks Verify Build Link checker

tag badge license badge size badge

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.

To install any specific version of s2i use openshift-tools-installer. 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.

Action Inputs

Input Name Description Default
builder_image The S2I builder image (e.g. centos/go-toolset-7-centos7). A curated list of builder images can be found here. Required
env_vars List of environment variable key-value pairs to pass to the S2I builder context. (eg. key=value, mysecret=${{ secrets.MY_SECRET }}). None
image Name to give to the output image. Required
tags The tags of the image to build. For multiple tags, separate by a space. For example, latest ${{ github.sha }} latest
log_level Log level when running S2I. Can be 0 (least verbose) to 5 (most verbose). 1
path_context The location of the path to run S2I from. This should be the path where your source code is stored. .
include_git Include all files during the S2I build including the .git folder. Set to true to enable. false

Action Outputs

image: The name of the built image.
For example, spring-image.

tags: A list of the tags that were created, separated by spaces.
For example, latest v1.

Builder Images

Please refer to this curated list of well maintained builder images.

Many more images can be found under sclorg.

Examples

Basic: Build and push a Java application

steps:
  env:
    IMAGE_NAME: my-java-app
    TAGS: v1 ${{ github.sha }}

  - name: Checkout
    uses: actions/checkout@v7

  # Setup S2i and Build container image
  - name: Setup and Build
    id: build_image
    uses: redhat-actions/s2i-build@v2
    with:
      path_context: '.'
      # Builder image for a java project
      builder_image: 'registry.access.redhat.com/openjdk/openjdk-11-rhel7'
      image: ${{ env.IMAGE_NAME }}
      tags: ${{ env.TAGS }}

  # Push Image to Quay registry
  - name: Push To Quay Action
    uses: redhat-actions/push-to-registry@v2
    with:
      image: ${{ steps.build_image.outputs.image }}
      tags: ${{ steps.build_image.outputs.tags }}
      registry: quay.io/${{ secrets.QUAY_USERNAME }}
      username: ${{ secrets.QUAY_USERNAME }}
      password: ${{ secrets.QUAY_PASSWORD }}

Build from pre-compiled artifacts (binary build)

If you compile your application in a prior step (e.g. mvn package), you can use S2I's binary build mode to inject the compiled artifacts directly into the builder image. This produces smaller images by skipping the build tools.

Point path_context at the directory containing your build output:

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

  - name: Build application
    run: mvn package -DskipTests

  - name: Build image from artifacts
    uses: redhat-actions/s2i-build@v2
    with:
      path_context: './target'
      builder_image: 'registry.access.redhat.com/openjdk/openjdk-11-rhel7'
      image: my-app

Pass environment variables (e.g. Maven settings)

Use env_vars to pass configuration to the S2I builder at build time. This is useful for setting Maven mirrors, proxies, or injecting credentials:

  - name: Build with custom Maven settings
    uses: redhat-actions/s2i-build@v2
    with:
      path_context: '.'
      builder_image: 'registry.access.redhat.com/openjdk/openjdk-11-rhel7'
      image: my-app
      env_vars: |
        MAVEN_MIRROR_URL=https://my-nexus.example.com/repository/maven-public/
        MAVEN_ARGS_APPEND=-DskipTests

For private Maven repositories requiring authentication, write a settings.xml before the build and reference it via environment variables:

  - name: Write Maven settings
    run: |
      mkdir -p $HOME/.m2
      cat > $HOME/.m2/settings.xml << 'XML'
      <settings>
        <servers>
          <server>
            <id>my-repo</id>
            <username>${{ secrets.MAVEN_USERNAME }}</username>
            <password>${{ secrets.MAVEN_PASSWORD }}</password>
          </server>
        </servers>
      </settings>
      XML

  - name: Build with private repo access
    uses: redhat-actions/s2i-build@v2
    with:
      path_context: '.'
      builder_image: 'registry.access.redhat.com/openjdk/openjdk-11-rhel7'
      image: my-app
      include_git: 'true'

About

Github Action to build an OCI-compatible container image from source code.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

38 stars

Watchers

2 watching

Forks

Releases

Used by

Contributors

Languages