Creating New Applications

    The command allows you to create applications from source code in a local or remote Git repository.

    To create an application using a Git repository in a local directory:

    To create an application using a remote Git repository:

    1. $ oc new-app https://github.com/sclorg/cakephp-ex

    To create an application using a private remote Git repository:

    1. $ oc new-app https://github.com/youruser/yourprivaterepo --source-secret=yoursecret

    If using a private remote Git repository, you can use the —source-secret flag to specify an existing source clone secret that will get injected into your BuildConfig to access the repository.

    You can use a subdirectory of your source code repository by specifying a --context-dir flag. To create an application using a remote Git repository and a context subdirectory:

    1. $ oc new-app https://github.com/sclorg/s2i-ruby-container.git \
    2. --context-dir=2.0/test/puma-test-app

    Also, when specifying a remote URL, you can specify a Git branch to use by appending #<branch_name> to the end of the URL:

    1. $ oc new-app https://github.com/openshift/ruby-hello-world.git#beta4

    The new-app command creates a , which itself creates a new application image from your source code. The new-app command typically also creates a to deploy the new image, and a service to provide load-balanced access to the deployment running your image.

    OKD automatically whether the **Docker**, **Pipeline** or **Source** build strategy should be used, and in the case of **Source** builds, .

    Build Strategy Detection

    If a Jenkinsfile exists in the root or specified context directory of the source repository when creating a new application, OKD generates a **Pipeline** build strategy. Otherwise, if a Dockerfile is found, OKD generates a . Otherwise, it generates a **Source** build strategy.

    You can override the build strategy by setting the --strategy flag to either docker, pipeline or source.

    1. $ oc new-app /home/user/code/myapp --strategy=docker

    The oc command requires that files containing build sources are available in a remote Git repository. For all source builds, you must use git remote -v.

    Language Detection

    If using the **Source** build strategy, new-app attempts to determine the language builder to use by the presence of certain files in the root or specified context directory of the repository:

    Table 1. Languages Detected by new-app
    LanguageFiles

    jee

    pom.xml

    nodejs

    app.json, package.json

    perl

    cpanfile, index.pl

    php

    composer.json, index.php

    python

    requirements.txt, setup.py

    ruby

    Gemfile, Rakefile, config.ru

    scala

    golang

    Godeps, main.go

    After a language is detected, new-app searches the OKD server for tags that have a **supports** annotation matching the detected language, or an image stream that matches the name of the detected language. If a match is not found, new-app searches the Docker Hub registry for an image that matches the detected language based on name.

    You can override the image the builder uses for a particular source repository by specifying the image (either an image stream or container specification) and the repository, with a ~ as a separator. Note that if this is done, and language detection are not carried out.

    For example, to use the myproject/my-ruby image stream with the source in a remote repository:

    1. $ oc new-app myproject/my-ruby~https://github.com/openshift/ruby-hello-world.git

    To use the openshift/ruby-20-centos7:latest container image stream with the source in a local repository:

    1. $ oc new-app openshift/ruby-20-centos7:latest~/home/user/code/my-ruby-app

    You can deploy an application from an existing image. Images can come from image streams in the OKD server, images in a specific registry or , or images in the local Docker server.

    The new-app command attempts to determine the type of image specified in the arguments passed to it. However, you can explicitly tell new-app whether the image is a container image (using the --docker-image argument) or an image stream (using the -i|--image argument).

    If you specify an image from your local Docker repository, you must ensure that the same image is available to the OKD cluster nodes.

    For example, to create an application from the DockerHub MySQL image:

    1. $ oc new-app mysql

    To create an application using an image in a private registry, specify the full container image specification:

    1. $ oc new-app myregistry:5000/example/myimage

    If the registry containing the image is not secured with SSL, cluster administrators must ensure that the Docker daemon on the OKD node hosts is run with the flag pointing to that registry. You must also tell new-app that the image comes from an insecure registry with the —insecure-registry flag.

    You can create an application from an existing and optional image stream tag:

    You can create an application from a previously stored or from a template file, by specifying the name of the template as an argument. For example, you can store a sample application template and use it to create an application.

    To create an application from a stored template:

    1. $ oc create -f examples/sample-app/application-template-stibuild.json
    2. $ oc new-app ruby-helloworld-sample

    To directly use a template in your local file system, without first storing it in OKD, use the -f|--file argument:

      Template Parameters

      When creating an application based on a , use the -p|--param argument to set parameter values defined by the template:

      1. $ oc new-app ruby-helloworld-sample \
      2. -p ADMIN_USERNAME=admin -p ADMIN_PASSWORD=mypassword

      You can store your parameters in a file, then use that file with --param-file when instantiating a template. If you want to read the parameters from standard input, use --param-file=-:

      1. $ cat helloworld.params
      2. ADMIN_USERNAME=admin
      3. ADMIN_PASSWORD=mypassword
      4. $ oc new-app ruby-helloworld-sample --param-file=helloworld.params
      5. $ cat helloworld.params | oc new-app ruby-helloworld-sample --param-file=-

      The new-app command generates OKD objects that will build, deploy, and run the application being created. Normally, these objects are created in the current project using names derived from the input source repositories or the input images. However, new-app allows you to modify this behavior.

      The set of objects created by new-app depends on the artifacts passed as input: source repositories, images, or templates.

      Table 2. new-app Output Objects
      ObjectDescription

      BuildConfig

      A BuildConfig is created for each source repository specified in the command line. The BuildConfig specifies the strategy to use, the source location, and the build output location.

      ImageStreams

      For BuildConfig, two ImageStreams are usually created. One represents the input image. With Source builds, this is the builder image. With Docker builds, this is the FROM image. The second one represents the output image. If a container image was specified as input to new-app, then an image stream is created for that image as well.

      DeploymentConfig

      Service

      The new-app command attempts to detect exposed ports in input images. It uses the lowest numeric exposed port to generate a service that exposes that port. In order to expose a different port, after new-app has completed, simply use the oc expose command to generate additional services.

      Other

      Other objects may be generated when instantiating templates, according to the template.

      Specifying Environment Variables

      When generating applications from a template, , or an image, you can use the -e|--env argument to pass environment variables to the application container at run time:

      1. $ oc new-app openshift/postgresql-92-centos7 \
      2. -e POSTGRESQL_USER=user \
      3. -e POSTGRESQL_DATABASE=db \
      4. -e POSTGRESQL_PASSWORD=password

      The variables can also be read from file using the --env-file argument:

      1. $ cat postgresql.env
      2. POSTGRESQL_USER=user
      3. POSTGRESQL_DATABASE=db
      4. POSTGRESQL_PASSWORD=password
      5. $ oc new-app openshift/postgresql-92-centos7 --env-file=postgresql.env

      Additionally, environment variables can be given on standard input by using --env-file=-:

      1. $ cat postgresql.env | oc new-app openshift/postgresql-92-centos7 --env-file=-

      See for more information.

      Specifying Build Environment Variables

      When generating applications from a , source, or an , you can use the --build-env argument to pass environment variables to the build container at run time:

      1. $ oc new-app openshift/ruby-23-centos7 \
      2. --build-env GEM_HOME=~/.gem

      The variables can also be read from a file using the --build-env-file argument:

      1. $ cat ruby.env
      2. HTTP_PROXY=http://myproxy.net:1337/
      3. GEM_HOME=~/.gem
      4. $ oc new-app openshift/ruby-23-centos7 --build-env-file=ruby.env

      Additionally, environment variables can be given on standard input by using --build-env-file=-:

      Specifying Labels

      When generating applications from , images, or , you can use the -l|--label argument to add labels to the created objects. Labels make it easy to collectively select, configure, and delete objects associated with the application.

      1. $ oc new-app https://github.com/openshift/ruby-hello-world -l name=hello-world

      Viewing the Output Without Creation

      To see a dry-run of what new-app will create, you can use the -o|--output argument with a yaml or json value. You can then use the output to preview the objects that will be created, or redirect it to a file that you can edit. Once you are satisfied, you can use oc create to create the OKD objects.

      To output new-app artifacts to a file, edit them, then create them:

      1. $ oc new-app https://github.com/openshift/ruby-hello-world \
      2. -o yaml > myapp.yaml
      3. $ vi myapp.yaml

      Creating Objects With Different Names

      Objects created by new-app are normally named after the source repository, or the image used to generate them. You can set the name of the objects produced by adding a --name flag to the command:

      1. $ oc new-app https://github.com/openshift/ruby-hello-world --name=myapp

      Creating Objects in a Different Project

      Normally, new-app creates objects in the current project. However, you can create objects in a different project that you have access to using the -n|--namespace argument:

      1. $ oc new-app https://github.com/openshift/ruby-hello-world -n myproject

      Creating Multiple Objects

      The new-app command allows creating multiple applications specifying multiple parameters to new-app. Labels specified in the command line apply to all objects created by the single command. Environment variables apply to all components created from source or images.

      To create an application from a source repository and a Docker Hub image:

      1. $ oc new-app https://github.com/openshift/ruby-hello-world mysql

      If a source code repository and a builder image are specified as separate arguments, new-app uses the builder image as the builder for the source code repository. If this is not the intent, specify the required builder image for the source using the ~ separator.

      Grouping Images and Source in a Single Pod

      The new-app command allows deploying multiple images together in a single pod. In order to specify which images to group together, use the + separator. The --group command line argument can also be used to specify the images that should be grouped together. To group the image built from a source repository with other images, specify its builder image in the group:

      1. $ oc new-app ruby+mysql

      To deploy an image built from source and an external image together:

      1. $ oc new-app \
      2. ruby~https://github.com/openshift/ruby-hello-world \
      3. mysql \
      4. --group=ruby+mysql

      Searching for Images, Templates, and Other Inputs

      To search for images, templates, and other inputs for the oc new-app command, add the --search and --list flags. For example, to find all of the images or templates that include PHP:

      1. $ oc new-app --search php
      1. While in the desired project, click Add to Project:

      2. Select either a builder image from the list of images in your project, or from the service catalog:

        Browse Catalog

        Only image stream tags that have the builder tag listed in their annotations appear in this list, as demonstrated here:

        1. kind: "ImageStream"
        2. apiVersion: "v1"
        3. metadata:
        4. name: "ruby"
        5. creationTimestamp: null
        6. spec:
        7. dockerImageRepository: "registry.redhat.io/openshift3/ruby-20-rhel7"
        8. tags:
        9. -
        10. name: "2.0"
        11. annotations:
        12. description: "Build and run Ruby 2.0 applications"
        13. iconClass: "icon-ruby"
        14. tags: "builder,ruby" (1)
        15. supports: "ruby:2.0,ruby"
        1Including builder here ensures this ImageStreamTag appears in the web console as a builder.
      3. Modify the settings in the new application screen to configure the objects to support your application: