How to create a Openshift build from a local source code?
Environment
- Red Hat Openshift Container Platform
- 3.x
- 4.x
Issue
- How to create a
build
from a local jar file? - How to create a
build
from a local directory? - How to create a
build
from a local git repository?
Resolution
A build
in OpenShift Container Platform is the process of transforming input parameters into a resulting object. Most often, builds are used to transform source code into a runnable container image.
Below the steps to create a build from a source directory:
As a prerequisite, you must be logged in the Openshift cluster as well as created a project.
-
Check if the
image-streams
is already imported in your repository:$oc get is NAME DOCKER REPO TAGS UPDATED apicurito-ui docker-registry.default.svc:5000/fuse/apicurito-ui 1.4,1.2,1.3 camel-ose-springboot-xml docker-registry.default.svc:5000/fuse/camel-ose-springboot-xml fis-java-openshift docker-registry.default.svc:5000/fuse/fis-java-openshift latest,1.0,2.0 fis-karaf-openshift docker-registry.default.svc:5000/fuse/fis-karaf-openshift 2.0,1.0 fuse docker-registry.default.svc:5000/fuse/fuse latest 40 seconds ago fuse-apicurito-generator docker-registry.default.svc:5000/fuse/fuse-apicurito-generator 1.2,1.3,1.4 fuse-java-openshift docker-registry.default.svc:5000/fuse/fuse-java-openshift latest 32 minutes ago fuse7-console docker-registry.default.svc:5000/fuse/fuse7-console 1.3,1.4,1.0 + 2 more... fuse7-eap-openshift docker-registry.default.svc:5000/fuse/fuse7-eap-openshift 1.2,1.3,1.4 + 2 more... fuse7-java-openshift docker-registry.default.svc:5000/fuse/fuse7-java-openshift 1.5,1.0,1.1 + 3 more... fuse7-karaf-openshift docker-registry.default.svc:5000/fuse/fuse7-karaf-openshift 1.0,1.1,1.2 + 2 more... jboss-fuse70-console docker-registry.default.svc:5000/fuse/jboss-fuse70-console 1.0 jboss-fuse70-eap-openshift docker-registry.default.svc:5000/fuse/jboss-fuse70-eap-openshift 1.0 jboss-fuse70-java-openshift docker-registry.default.svc:5000/fuse/jboss-fuse70-java-openshift 1.0 jboss-fuse70-karaf-openshift docker-registry.default.svc:5000/fuse/jboss-fuse70-karaf-openshift 1.0
-
Create a new build specifying the
image-stream
that best suits to the application project, in this example thefis-java-openshift
:$oc new-build --binary=true --image-stream=fis-java-openshift:2.0 --name=fuse
-
Check the outputs in the terminal:
--> Found image c990278 (12 days old) in image stream "openshift/fis-java-openshift" under tag "2.0" for "fis-java-openshift:2.0" Fuse Integration Services - Java -------------------------------- Platform for building and running plain Java applications (fat-jar and flat classpath) Tags: builder, java * A source build using binary input will be created * The resulting image will be pushed to image stream tag "fuse:latest" * A binary build was created, use 'start-build --from-dir' to trigger a new build --> Creating resources with label build=fuse ... buildconfig.build.openshift.io "fuse" created --> Success
-
Start the build where the
--from-dir
parameter must be pointing to the application project folder. Rather than relying on a project directory, it is possible to create a build from a file--from-file=<file>
or from a Git or SVN working directory,--from-repo=<local_source_repo>
.$oc start-build fuse --from-dir=/home/fuse-user/fuse-rest --follow
-
The previous command will start the build as well as downloading the maven dependencies and pushing the image.
[INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 01:21 min [INFO] Finished at: 2019-12-23T19:00:31Z [INFO] Final Memory: 45M/110M [INFO] ------------------------------------------------------------------------ Copying Maven artifacts from /tmp/src/target to /deployments ... Running: cp *.jar /deployments ... done Pushing image docker-registry.default.svc:5000/fuse/fuse:latest ... Pushed 5/6 layers, 84% complete Pushed 6/6 layers, 100% complete Push successful
-
Afterward, create a
new-app
from the previous build:$oc new-app fuse
-
A
DeploymentConfig
will be created and also aService
exposing the application internally as the output below shows:--> Found image b462947 (4 minutes old) in image stream "fuse/fuse" under tag "latest" for "fuse" temp.builder.openshift.io/fuse/fuse-1:4aeea8e2 ---------------------------------------------- Platform for building and running plain Java applications (fat-jar and flat classpath) Tags: builder, java * This image will be deployed in deployment config "fuse" * Port 8778/tcp will be load balanced by service "fuse" * Other containers can access this service through the hostname "fuse" --> Creating resources ... deploymentconfig.apps.openshift.io "fuse" created service "fuse" created --> Success Application is not exposed. You can expose services to the outside world by executing one or more of the commands below: 'oc expose svc/fuse' Run 'oc status' to view your app.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Comments