Chapter 2. Creating a Python S2I application for OpenShift Data Science

2.1. Creating a Python S2I application for OpenShift Data Science from a GitHub template

You can create an application suitable for Red Hat OpenShift Data Science quickly by using Red Hat’s Python S2I application repository as a template in GitHub. Use the template to generate a new repository with the same format, directory structure and files as an existing Red Hat OpenShift Data Science repository.

Prerequisites

  • You have a GitHub account.
  • You have credentials to access the GitHub repository containing the relevant template that you want to use.

Procedure

  1. On GitHub, navigate to the main page of the template repository.
  2. Click Use this template.
  3. Optional: From the Owner list, select the account that you want to own the repository.
  4. In the Repository name field, enter a name for the new repository.
  5. Optional: In the Description field, enter a description for the new repository.
  6. Set the repository’s visibility level.

    1. To ensure that the repository is visible to anyone, leave Public selected. By default, the repository’s visibility is set to Public.
    2. Click Private to restrict who can see and commit to the repository.
  7. Optional: Select the Include all branches check box to copy the template repository’s branches to your new repository.
  8. Click Create repository from template.

Verification

  • The repository that you created from the template is visible and accessible from your GitHub account.

2.2. Creating a Python S2I application for OpenShift Data Science using Cookiecutter

You can create an application suitable for Red Hat OpenShift Data Science quickly by using Cookiecutter. Cookiecutter is a Python library that creates a flexible, standardized project structure for your data science work. You can use Cookiecutter to further customize your project’s repository. For example, you can modify the repository’s directory structure to suit your project’s requirements.

Prerequisites

  • A launched and running JupyterHub server.
  • You have a GitHub account.
  • You have credentials to access the GitHub repository containing the template that you want to use.

Procedure

  1. In the JupyterLab interface, click FileNewTerminal.
  2. In the terminal, run the pip install command to install Cookiecutter.

    pip install cookiecutter
  3. Run the cookiecutter command to create a project from a Cookiecutter repository template.

    cookiecutter template-repository-url

    Replace template-repository-url with the template repository’s URL. For example, https://github.com/cookiecutter-template/template.

  4. When prompted, provide the following information:

    1. A name for your project.
    2. A name for your repository.
    3. A name for the project’s author.
    4. A description for your project.
    5. Your open source license file type.

      The contents of the Cookiecutter template repository appear in the File Browser in the left sidebar.

  5. Create a repository in GitHub.

    1. In the upper-right corner of the GitHub home page, click +New repository.

      The Create a new repository page opens.

    2. In the Repository template field, select the template that you want to use.
    3. Optional: Select the Include all branches check box to copy the template repository’s branches to your new repository.
    4. In the Owner field, select the repository owner’s user name.
    5. In the Repository name field, enter a name for the repository.
    6. Optional: In the Description field, enter a description of the repository.
  6. Set the repository’s visibility level.

    1. To ensure that the repository is visible to anyone, leave Public selected. By default, the repository’s visibility is set to Public.
    2. Click Private to choose who can see and commit to the repository.
    3. Click Create repository.
  7. Clone the repository on your JupyterHub server.

    1. In the JupyterLab interface, click GitClone a Repository.

      The Clone a repo dialog appears.

    2. Enter the URL of the repository that you want to clone.
    3. Click Clone.

      The cloned repository appears in the File Browser in the left sidebar.

    4. In the File Browser, move the files and directories created by Cookiecutter to the repository that you cloned.
  8. Push your changes to the remote repository.

    1. In the left sidebar, click Git ( The Git icon ).
    2. If you have untracked changes, in the Changes tab, hover the cursor over the Untracked section bar and click jupyter git add or commit .
    3. If you have files that contain changes, in the Changes tab, hover the cursor over the Changed section bar and click jupyter git add or commit .
    4. In the Required field, enter a summary of your changes.
    5. In the Description field, enter a description of your changes.
    6. Click Commit.
    7. In the JupyterLab interface, click GitPush to Remote to push your changes to the remote repository.

      The Git credentials required dialog opens.

    8. Enter your credentials to access the remote repository.
    9. Click OK.

Verification

  • You can access the remote repository that you created from the template.
  • You can see the changes that you pushed in the remote repository.