There are three different types of builds:
- Source-To-Image (s2i)
- Binary Builds
- Container aka. Docker Builds
Let's have a look at the different kinds of builds
Simplest way of getting started from a code base (e.g. Ruby, Python, PHP) to a running application bundled with all the dependencies.
It creates all the necessary build configs, deployment configs and even automatically exposes the application on a route.
First, create a project with the name userXY-s2i
create project command
oc new-project userXY-s2iOur example is based on a very simple PHP application hosted on APPUiO GitHub. Create an app with the name s2i from this repository: https://github.com/appuio/example-php-sti-helloworld.git
Hint for the command help:
oc new-app -h
create app command
oc new-app https://github.com/appuio/example-php-sti-helloworld.git --name=s2iCheck the status of your project.
project status command
oc statusExplore the different resources created by the new-app command.
To see something in the browser, create a route to access the application:
oc create route edge --service=s2i
This example describes how to deploy a web archive (war) in Wildfly using the OpenShift client (oc) in binary mode. The example is inspired by APPUiO blog: http://docs.appuio.ch/en/latest/app/wildflybinarydeployment.html
Create a project with the name userXY-binary-build
create project command
oc new-project userXY-binary-buildPrepare a temporary folder and create the deployment folder structure inside.
One or more war can be placed in the deployments folder. In this example an existing war file is downloaded from a Git repository:
mkdir tmp-bin
cd tmp-bin
mkdir deployments
wget -O deployments/ROOT.war 'https://github.com/appuio/hello-world-war/blob/master/repo/ch/appuio/hello-world-war/1.0.0/hello-world-war-1.0.0.war?raw=true'
Create a build configuration for a binary build with following attributes:
- base Docker image:
openshift/wildfly-160-centos7
- name:
hello-world
- label:
app=hello-world
. - type:
binary
The flag binary=true indicates that this build will use the binary content instead of the url to the source code.
Command:
oc new-build --docker-image=openshift/wildfly-160-centos7 --binary=true --name=hello-world -l app=hello-world
Command with output:
$ oc new-build --docker-image=openshift/wildfly-160-centos7 --binary=true --name=hello-world -l app=hello-world
--> Found Docker image 7ff222e (2 months old) from Docker Hub for "openshift/wildfly-160-centos7"
WildFly 16.0.0.Final
--------------------
Platform for building and running JEE applications on WildFly 16.0.0.Final
Tags: builder, wildfly, wildfly16
* An image stream tag will be created as "wildfly-160-centos7:latest" that will track the source image
* A source build using binary input will be created
* The resulting image will be pushed to image stream tag "hello-world:latest"
* A binary build was created, use 'start-build --from-dir' to trigger a new build
--> Creating resources with label app=hello-world ...
imagestream.image.openshift.io "wildfly-160-centos7" created
imagestream.image.openshift.io "hello-world" created
buildconfig.build.openshift.io "hello-world" created
--> Success
See the command output for the created resources.
Check the created resources with the oc tool and inside the web console. Do you find the created build inside the web console?
To trigger a build issue the command below. In a continuous deployment process this command can be repeated whenever there is a new binary or a new configuration available.
The core feature of the binary build is to provide the files for the build from the local directory. Those files will be loaded into the build container that runs inside OpenShift.
oc start-build hello-world --from-dir=. --follow
The parameter --from-dir=. tells the oc tool which directory to upload.
The --follow flag will show the build log on the console and wait until the build is finished.
Create a new app based on the Docker Image created by the binary build.
oc new-app hello-world -l app=hello-world
See the command output for the created resources.
Check the created resources with the oc tool and inside the web console. Try to find out, if the wildfly has started.
oc create route edge --service=hello-world
Inside the web console click onto the route to see the output of the hello-world application.
We can also create arbitrary containers based on Dockerfiles.
First, create a project with the name userXY-docker-build
create project command
oc new-project userXY-docker-buildCommand to create a Docker build:
oc new-build --strategy=docker --binary=true --name=web -l app=web centos/httpd-24-centos7
Clone the techlab Git repository, if you do not have it already available.
git clone REPO_URL/techlab.git
Navigate to the root directory of the git repository (cd techlab
).
Start the build with the data from labs/data/02_httpd
:
oc start-build web --from-dir=labs/data/02_httpd --follow
Follow how the build goes and if the image will be present in your registry.
Create an app with that image and expose it:
oc new-app web -l app=web
oc create route edge --service=web
Inside the web console click onto the route to see the website of your application.
Now let's try to add an easter egg in /easter-egg.txt with a new build.
Inspect labs/data/02_httpd
for a hint.
solution
add a copy command to the Dockerfile to copy the file easter-egg.txt to /var/www/html/ :...
COPY ./easter-egg.txt /var/www/html/
...
start a new build
Did it work? -> https://web-userXY-docker-build.techlab-apps.puzzle.ch/easter-egg.txt