Build your application containers the right way with Shipwright

Setup

Register to access the lab

  • Get the lab registration URL from instructor. Then register with your email address and password openshift to access the lab.

    register 01

Log in to OpenShift web console

  • Open the OpenShift web console URL from the registration page in a web browser.

    register 02
  • Log in with your username and password provided in the registration page.

    shp 1
  • If it’s the first time you log in to web console, the quick tour dialog will show up, just click Skip tour or close the dialog.

    shp 2
  • Switch to Developer perspective (if it’s not) from the drop-down list near the hamburger menu. Then click on userX-shipwright project where userX is your username such as user1.

    shp 3

Web Terminal Check

  • Click on the command prompt icon at the top right corner of OpenShift web console to open the Web Terminal.

    shp 12
  • If you open the web terminal first time, it’ll ask for the project used to initialize the terminal. Select the userX-shipwright project where userX is your username, and then click Start button.

    shp 13
  • Wait until the terminal is ready and command prompt is shown.

    shp 14
  • Run this command to verify if terminal is working.

    oc whoami

    Sample output.

    user1

[Optional] Set theme color for console

  • Click on your user name at the top right of OpenShift web console, then select User References.

    shp 4
  • In the General section, you can change theme from Dark mode (default) to Light mode.

    shp 5

Deploy Container Image

  • Click +Add menu on the left, the Add page will show up then select Container images tile.

    shp 6
  • Select Image name from external registry option.

  • Enter quay.io/voravitl/frontend-js:latest then wait for OpenShift validates the container image registry.

  • Change Runtime icon to nodejs.

  • Set Application name to frontend-js.

  • Set Name to frontend-js.

    shp 7
  • Set Resource type to Deployment.

  • Leave the Target port as default (8080)

  • Make sure the Create a route checkbox is selected.

  • Finally, click on the Create button. at the bottom.

    shp 8
  • You will be redirected back to the Topology view. Wait until the Pod status change to Running.

    shp 9

Access The Application

  • Click on frontend-js Deployment icon then click on the arrow to open the web application.

    shp 10
  • Make sure you can see the response from the frontend-js application similar to the screenshot.

    shp 11

Now you can see that we can deploy container images via OpenShift console with a few clicks. It’s easy!, right? But what if you don’t have container image?

  • How to build container image if you only have source code?

  • How to build container image from your Dockerfile or Containerfile you’ve written?

  • How to prepare tools, environment, etc. to build container image?

Red Hat OpenShift Builds

shipwright logo

OpenShift Builds is an extensible build framework based on the Shipwright project, which you can use to build container images on an OpenShift Container Platform cluster. You can build container images from source code and Dockerfiles by using image build tools, such as Source-to-Image (S2I) and Buildah. You can create and apply build resources, view logs of build runs, and manage builds in your OpenShift Container Platform.

OpenShift Builds includes the following capabilities:

  • Standard Kubernetes-native API for building container images from source code and Dockerfiles

  • Support for Source-to-Image (S2I), Buildah, Buildpacks, etc.

  • Extensibility with your own custom build strategies

  • Execution of builds from source code in a local directory

  • Shipwright CLI for creating and viewing logs, and managing builds on the cluster

  • Integrated user experience with the Developer perspective of the OpenShift Container Platform web console

OpenShift Builds consists of the following custom resources (CRs):

  • Build

  • BuildStrategy and ClusterBuildStrategy

  • BuildRun

Get More information

Build and Deploy Application using Shipwright and Buildah

In this lab, we are going to build application container from the Go application code hosted on a Git repository. Follow these steps to build and deploy the applcation using OpenShift Builds in combination of Shipwright and Buildah.

Review the Container Image Build Instruction

  • Go to https://gitlab.com/chatapazar/simple-rest-go Git repository.

    shp 15
  • Open the Dockerfile, then review build steps in the Dockerfile file.

    shp 18
  • Back to the main page of repository, click on Code button then copy the repository URL labeled with Clone with HTTPS.

    shp 20

Build and Deploy Container

  • Go to OpenShift web console then click +Add menu on the left. Select Git Repository - Import from Git tile.

    shp 21

On the Import from Git form, follow these steps:

  • Paste the Git repository URL you’ve copied earlier to Git Repo URL input.

  • The wizard will detect the Dockerfile in the repository automatically.

  • Select Create Application for the Application drop-down list.

  • Set Application name to simple-rest-go.

  • Set Name to simple-rest-go.

    shp 22
  • Select Builds for OpenShift (Shipwright) for Build option.

  • Select Buildah for Cluster Build Strategy.

  • Leave other configurations as default, then click Create button.

    shp 23

View Build Configuration and Build Logs

  • In the Topology view, select simple-rest-go Deployment, click Resources tab in the right panel, then in BuildRuns section, click View logs link.

    shp 24
  • You should be able to see container image builds logs similar to the screenshot.

    shp 25
  • Wait until the build status changes from Running to Succeded.

    shp 26
  • Select Builds menu on the left, then click on Shipwright Builds tab to view Shipwright Build configuration.

    shp 27
  • Select Topology menu on the left, click on simple-rest-go Deployment, click Resources tab in the right panel, in BuildRuns section you’ll see the build status shown as Succeeded. And in the Pods section the Pod status is Running.

    shp 28

Access To Application

  • Click on the arrow icon to open the application URL.

    shp 29
  • Ensure you can see the response from the application.

    shp 30

Build and Deploy Application with Shipwright and Source-to-Image (S2I)

Review Application Source Code.

  • Go to https://gitlab.com/chatapazar/backend_quarkus Git repository.

    shp 32
  • Open the code directory to view the application source code. It’s a Java application based on Quarkus framework. The APIs that application exposes are in src/main/java/com/example/quarkus/BackendResource.java file.

    shp 34
    shp 35

Build and Deploy Container

  • In GitLab, back to the main backend_quarkus repository page, click on Code button then copy the repository URL labeled with Clone with HTTPS.

    shp 33
  • Go to OpenShift console, click +Add menu on the left, then select Git Repository - Import from Git tile.

    shp 21

On the Import from Git form, follow these steps:

  • Paste the backend_quarkus Git repository URL you’ve copied to Git Repo URL input.

  • Enter /code to Context dir input.

    shp 36
  • The wizard will automatically detect Builder image for Java application. Click Edit Import Strategy link to choose Builder Image.

    shp 37
  • Click on Java tile and select openjdk-21-ubi9 for the Builder Image version.

    shp 38
  • Select Create Application for the Application drop-down list.

  • Enter backend-quarkus for Application name.

  • Enter backend-quarkus for Name.

  • Select Builds for OpenShift (Shipwright) for Build Option.

  • Select Source-to-Image for Cluster Build Strategy.

    shp 39
  • Leave other configurations as default, then click Create button.

    shp 40

View Build Configuration and Build Logs

  • On the Topology page, select backend-quarkus Deployment, go to BuildRuns section, then click View logs link.

    shp 41
  • You should be able to see builds logs. Wait for the build status changes to Successed.

    shp 42
    shp 43
  • Select Builds menu on the left, then click on Shipwright Builds tab to view Shipwright Build configuration.

    shp 44
  • Select Topology menu on the left, then select backend-quarkus Deployment, go to BuildRuns section again you’ll see the build status shown as Succeeded.

    shp 45

Access To Application

  • Click on the arrow icon of backend-quarkus Deployment to open the application URL.

    shp 45
  • Ensure you can see response from the application similar to the screenshot.

    shp 46

Re-Build and Re-Deploy Application when Code Changes

  • Go back to OpenShift console. Select Builds menu on the left then click on Shipwright Builds tab. Click on action menu of backend-quarkus build configuration then select Start.

    shp 51
  • The build process should be started. Click on Logs tab to view build logs.

    shp 52
    shp 53

Summary

With Shipwright, developers get a simplified approach for building container images, by defining a minimal YAML that does not require any previous knowledge of containers or container tooling. All you need is your source code in git and access to a container registry.

Shipwright supports any tool that can build container images in Kubernetes clusters, such as: