yeganx / s2i-dotnetcore-ex

Example application for the OpenShift s2i-dotnetcore builder image

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

.NET Core Sample App for OpenShift

This repository contains an example project that can be built using the s2i-dotnetcore builder image, which can be used to create reproducible Docker images from your .NET Core project’s source code. The resulting images can be run using Docker or deployed to OpenShift.

For more information about using these images with OpenShift, please see the official OpenShift Documentation.

Building and Running

The sample application can be built and run either within OpenShift or standalone by combining the application using s2i tool and running with existing image using Docker. The following sections describes these processes.

OpenShift

After logging into an OpenShift environment and creating or using an existing project, create a new application which combines the s2i-dotnetcore builder and the sample application from this repository:

For .NET Core 1.0 use:

oc new-app registry.access.redhat.com/dotnet/dotnetcore-10-rhel7~https://github.com/redhat-developer/s2i-dotnetcore-ex#dotnetcore-1.0 --name=aspnet-app --context-dir=app

For .NET Core 1.1 use:

oc new-app registry.access.redhat.com/dotnet/dotnetcore-11-rhel7~https://github.com/redhat-developer/s2i-dotnetcore-ex#dotnetcore-1.1 --name=aspnet-app --context-dir=app

Next, create a new route so that the application is accessible outside the OpenShift environment

oc expose service aspnet-app

The application will now be available at http://aspnet-app-<project>.<default_subdomain>;

Use a template to build and deploy a sample application

A template has been provided to simplify the build and deployment of a .NET Core application on OpenShift. The template is located in the templates folder of the s2i-dotnetcore repository. File dotnet-example.json

After logging into an OpenShift environment and creating or using an existing project, add the template to the project

oc create -f https://raw.githubusercontent.com/redhat-developer/s2i-dotnetcore/master/templates/dotnet-example.json
Note

Alternately, the template can be added to the openshift project so that it will be visible by all users. Using a user with permissions to modify resources in the openshift project, execute the following command:

oc create -n openshift -f https://raw.githubusercontent.com/redhat-developer/s2i-dotnetcore/master/templates/dotnet-example.json

You can create the .NET Core sample application using the template with:

oc process dotnet-example NAME=aspnet-app NAMESPACE=<project-name> DOTNET_IMAGE_STREAM_TAG=dotnet:1.1 SOURCE_REPOSITORY_REF=dotnetcore-1.1 | oc create -f -

The template can also be instantiated using the OpenShift web console. Login to the console and navigate to the desired project. Click the Add to Project button. Search and select the one with name dotnet-example.

Click Create to start a build and deploy the sample application. You can choose to modify some some of the template parameters as you like. For example, the above oc process invocation changes relevant parameters so that the .NET Core 1.1 image gets selected and the corresponding dotnetcore-1.1 branch will be being used for building the app. More information about supported environment variables can be found in the s2i-dotnetcore repository in the corresponding image version’s subfolder. For example for 1.0 see: https://github.com/redhat-developer/s2i-dotnetcore/blob/master/1.0/README.md#environment-variables

Once the build has completed and the resulting container started, the application will be available at http://aspnet-app-<project>.<default_subdomain>;

Standalone

To build a new .NET Core application using a previously existing s2i-dotnetcore builder, dotnet/dotnetcore-10-rhel7, execute the following command:

s2i build --ref=dotnetcore-1.0 --context-dir=app https://github.com/redhat-developer/s2i-dotnetcore-ex dotnet/dotnetcore-10-rhel7 aspnet-app

The resulting image can be executed using docker:

docker run -d -p 8080:8080 aspnet-app

Once the container is running, it should be accessible using:

curl http://127.0.0.1:8080

Liveness and Readiness Application Health

The template has been configured with a liveness and readiness probe of which you can read more at https://docs.openshift.com/enterprise/latest/dev_guide/application_health.html. It checks if the container is healthy by doing a HTTP call to the root application. It checks if the application is ready by the same mechanism. If you’d like to see how the probe is working, use: oc log -f <pod>.

Contributing

Contributions to this project (in the form of bug reports, patches, or pull requests) are gratefully accepted by the maintainer. Please see the Contributing.adoc file contained in this package for details.

Copyright 2016-2017 by Red Hat, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this package except in compliance with the License (see the LICENSE file included in this distribution). You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

About

Example application for the OpenShift s2i-dotnetcore builder image

License:Apache License 2.0


Languages

Language:C# 97.8%Language:JavaScript 1.2%Language:CSS 0.8%Language:Shell 0.2%