This lab assumes the following are already configured on your machine
- OpenShift CLI
- git (2.23.0 or later)
- .NET Core SDK (3.1 or later)
- Docker
- Helm
- Download the latest release from https://github.com/openshift/source-to-image/releases
- Extract and copy s2i binary to a directory on your PATH
- Clone the repo https://github.com/redhat-developer/s2i-dotnetcore-ex.git
cd ~/ mkdir git cd git git clone https://github.com/redhat-developer/s2i-dotnetcore-ex.git cd s2i-dotnetcore-ex git checkout dotnetcore-3.1
- Change to the app directory
cd ~/git/s2i-dotnetcore-ex/app
- Run the app
dotnet run
- Note the output of what ports the app is running on it should be listening on https://localhost:5001
- Navigate your web browser to https://localhost:5001 and confirm the application is running. You may have to accept the security warning.
This will build the container image from the local file system, this is useful when you are actively working on code and are not ready to commit to a repository
- Run the build to create the .NET app and stream it into an image
Command Parts Description s2i The actual command build Tells the command to build an image from source . The location of the source files (current directory) registry.redhat.io/ubi8/dotnet-31:3.1 The builder image to use dotnetcore-ex The Image name to create in the local registry cd ~/git/s2i-dotnetcore-ex/app docker pull registry.redhat.io/ubi8/dotnet-31:3.1 s2i build . registry.redhat.io/ubi8/dotnet-31:3.1 dotnetcore-ex
- Run the app locally as a container, while exposing the ports locally. Notice that when running using the built image from the S2I build it defaults to listening to an un-secure port 8080 which differs from when we ran locally in the previous section.
docker run -p 8080:8080 dotnetcore-ex
- Open your web browser and navigate to http://localhost:8080
This lab will walk through first having the S2I build handled by a BuildConfig in OpenShift and then move to using Jenkins to trigger the build
- Clone the lab repo
cd ~/ git clone https://github.com/cloudfirst-dev/openshift-dotnet-labs.git dotnet-labs cd ~/git/dotnet-labs
To be able to build, we need to use the custom builder images we used locally and expose them as ImageStreams inside your namespace. Since we are using version 3.1 of .NET core these are not included by default in OpenShift
- Create the build/runtime ImageStream. This is the ImageStreams which the S2I buildconfig will utilize
cd ~/git/dotnet-labs oc new-project $(oc whoami)-demo oc create -f https://raw.githubusercontent.com/redhat-developer/s2i-dotnetcore/master/dotnet_imagestreams_rhel8.json
- Create Application ImageStream. This ImageStream will be used to host the output of the buildconfig. This utilizes the internal registry in OpenShift.
oc create -f ./build-pipeline/imagestream.yaml
We will now create the build config so that the S2I build runs in the OpenShift Cluster instead of locally
- Create the BuildConfig
oc create -f ./build-pipeline/build.yaml
This will run the build using the local current folder as the source for the builder image. It will upload the contents of the directory to the remote pod in the cluster, at the end it will push the image to the internal quay registry.
- Start the build
cd ~/git/s2i-dotnetcore-ex/app oc start-build dotnet-build --from-dir=. -F
This will be very similar to running locally with the exception we will be using the GIT repo as the source for the build.
- Create the Jenkins instance in the workspace
oc new-app --param=ENABLE_OAUTH=false jenkins-ephemeral
- Create the Jenkins Build Pipeline
cd ~/git/dotnet-labs oc create -f ./build-pipeline/build-git.yaml oc create -f ./build-pipeline/jenkins-build.yaml
- Start a Jenkins build which automates the command we ran in "Run the Build From Local Files"
oc start-build dotnetcore-ex-pipeline
- Watch the progress by going to the link outputted from the command below using username (admin/password) to login to jenkins
echo open $(oc get build dotnetcore-ex-pipeline-1 -o=jsonpath="{ .metadata.annotations['openshift\.io/jenkins-console-log-url'] }") to follow build
This lab will walk through using helm to provision the application deployment to OpenShift using the above build
- Install the helm chart to OpenShift
helm install helm --generate-name
- Watch the application deployment in OpenShift
- Access the application running on OpenShift by executing the following to get the url
echo "http://$(oc get route -l "app.kubernetes.io/name=helm" -o jsonpath="{.items[0].spec.host}")"
This lab will walk through using helm to create both the build items and deployment in a single namespace
- Create a new project to demonstrate this relies on nothing else we have done so far
oc new-project $(oc whoami)-dotnet-helm oc create -f https://raw.githubusercontent.com/redhat-developer/s2i-dotnetcore/master/dotnet_imagestreams_rhel8.json
- Deploy the OpenShift manifests with Helm
helm install demo helm-build
- Access the new app using the link from the following output
echo "http://$(oc get route -l "app.kubernetes.io/name=helm" -o jsonpath="{.items[0].spec.host}")"