Chapter 1. Developing using containers and the cloud in CodeReady Studio

1.1. Using Red Hat CodeReady Containers tools in CodeReady Studio

Red Hat CodeReady Containers (CRC) brings a minimal OpenShift 4 cluster to your local computer. This cluster provides a minimal environment for development and testing purposes. It is mainly targeted at running on developers' desktops. For other use cases, such as headless, multi-developer or team-based setups, use of the full-fledged OpenShift installer is recommended.

For a more in-depth introduction to OpenShift, see OpenShift documentation.

1.1.1. Downloading and installing Red Hat CodeReady Containers

The following section describes how to set up CodeReady Containers in CodeReady Studio.

Prerequisites

  1. Download the latest release of CodeReady Containers and the pull secret.
  2. Extract the CRC file.

    For more information on how to install and set up CRC, see the Installation chapter of the Getting started with CodeReady Containers Guide.

Procedure

  1. Start CodeReady Studio.
  2. Click WindowShow ViewOther.

    The Show View window appears.

    crs opening servers view
  3. Enter Server in the search field.
  4. Select Servers.
  5. Click Open.

    The Servers view appears.

    crs servers view empty
  6. Right-click any area in the Servers view.

    crs srver view creating new server
  7. Click NewServer.

    The Define a New Server window appears.

    crs creating crc server
  8. Select CodeReady Containers 1.0+.
  9. Click Next.

    The CodeReady Containers window appears.

    crs crc server adapter creation
  10. Click Browse to locate the CRC binary.
  11. Click Browse to locate the CRC Pull Secret File.
  12. Click Finish.

Your newly added CodeReady Containers 1.0+ server adapter is now listed in the Servers view.

crs crc server adapter created
Note

In case you did not set up CRC prior to starting the server adapter, you will see a warning: CRC has not been properly initialized!

crs crc warning

Follow the on-screen instructions to initialize CRC.

1.1.2. Using the OpenShift Container Platform tools

The following section describes how to use OpenShift Containers in CodeReady Studio.

Prerequisites

Procedure

  1. Start CodeReady Studio.
  2. Start the CRC server adapter.

    crs starting crc server adapter
  3. Click WindowShow ViewOther.

    The Show View window appears.

    crs os explorer view
  4. Enter OpenShift in the search field.
  5. Select OpenShift Explorer.
  6. Click Open.

    The OpenShift Explorer view appears.

  7. Press Ctrl+N.

    The Select a wizard window appears.

    crs openshift app creation
  8. Enter OpenShift in the search field.
  9. Select OpenShift Application.
  10. Click Next.

    The Sign in to OpenShift window appears.

    crs crc sing in to os
  11. Provide your credentials and click Next.

    The Create OpenShift Project window appears.

  12. Name your project.
  13. Click Finish.

    The Select template window appears.

    crs crc os selecting template
  14. Select a template.
  15. Click Next.

    The Build Configuration window appears.

    crs buid config example
  16. Ensure that the build configurations are correct.
  17. Click Finish.

Your newly created OpenShift application project is now listed in the OpenShift Explorer view.

crs os project created

Additional resources

1.2. Using Red Hat Container Development Kit tools in CodeReady Studio

Red Hat Container Development Kit (CDK) is a pre-built container development environment based on Red Hat Enterprise Linux (RHEL). CDK helps you get started with developing container-based applications quickly.

1.2.1. Installing Container Development Kit

The following section describes how to install CDK from within CodeReady Studio.

Prerequisites

  • Ensure that the Hypervisor is installed and configured on your system:

    • VirtualBox, Linux KVM/libvirt (Linux)
    • xhyve (macOS)
    • Hyper-V (Windows)
  • Ensure that hardware virtualization is enabled on your system.

    For more information, see Setting Up the Virtualization Environment.

  • Ensure that you have a Red Hat Developer account.

    To create a new account, visit developers.redhat.com.

For more information on CDK, see the Red Hat Container Development Kit Getting Started Guide.

Procedure

  1. Start CodeReady Studio.
  2. Click WindowShow ViewOther.

    The Show View window appears.

    crs opening servers view
  3. Enter Server in the search field.
  4. Select Servers.
  5. Click Open.

    The Servers view appears.

    crs servers view empty
  6. Right-click any area in the Servers view.

    crs srver view creating new server
  7. Click NewServer.

    The Define a New Server window appears.

    crs creating cdk server
  8. Select Red Hat Container Development Kit 3.2+.
  9. Click Next.

    The Red Hat Container Development Environment window appears.

    crs creating cdk server2
  10. Click Download and install runtime.

    The Download Runtimes window appears.

    crs cdk runtimes
  11. Select a Red Hat CDK version.
  12. Click Next.
  13. Ensure that your sign-on credentials for access.redhat.com are correct.
  14. Click Next.
  15. Review and accept the license agreement and click Next.
  16. Select the installation folder and click Finish.

    Note that the process of downloading and installing the runtime might take some time to complete.

  17. Click Finish.

    Your newly created Container Development Environment 3.2+ server is now listed in the Servers view.

    crs cdk server in view
  18. Right-click CDK server adapterStart.

    crs startink cdk server adapter
    Note

    In case you did not set up CDK prior to starting the server adapter, you will see a warning: CDK has not been properly initialized!

    crs cdk warning

    Follow the on-screen instructions to initialize CDK.

1.2.2. Using Docker tools

1.2.2.1. Creating a Dockerfile

Prerequisites

  • The CDK server adapter is set up and configured.

    For more information, see Installing CDK.

Procedure

  1. Start CodeReady Studio.
  2. Start the CDK server adapter.

    crs startink cdk server adapter
  3. Press Ctrl+N.

    The Select a wizard window appears.

    crs java project wizard
  4. Enter Java Project in the search field.
  5. Select Java Project.
  6. Click Next.

    The New Java Project window appears.

    crs java project creation
  7. Name your project.
  8. Select the location for your project.
  9. Click Finish.

    Your newly created Java project is now listed in the CodeReady Studio view.

  10. Right-click your Java projectNewFile.

    crs java project new file

    The Create New File window appears.

    crs creating docker file
  11. Select the parent folder.
  12. Name your file.
  13. Click Finish.

    Your newly created file is now displayed in the CodeReady Studio editor.

  14. Paste the following content into your newly created file:

        # Use latest jboss/base-jdk:8 image as the base
    FROM jboss/base-jdk:8
    
    # Set the WILDFLY_VERSION env variable
    ENV WILDFLY_VERSION 10.1.0.Final
    ENV WILDFLY_SHA1 9ee3c0255e2e6007d502223916cefad2a1a5e333
    ENV JBOSS_HOME /opt/jboss/wildfly
    
    USER root
    
    # Add the WildFly distribution to /opt, and make wildfly the owner of the extracted tar content
    # Make sure the distribution is available from a well-known place
    RUN cd $HOME \
        && curl -O https://download.jboss.org/wildfly/$WILDFLY_VERSION/wildfly-$WILDFLY_VERSION.tar.gz \
        && sha1sum wildfly-$WILDFLY_VERSION.tar.gz | grep $WILDFLY_SHA1 \
        && tar xf wildfly-$WILDFLY_VERSION.tar.gz \
        && mv $HOME/wildfly-$WILDFLY_VERSION $JBOSS_HOME \
        && rm wildfly-$WILDFLY_VERSION.tar.gz \
        && chown -R jboss:0 ${JBOSS_HOME} \
        && chmod -R g+rw ${JBOSS_HOME}
    
        # Ensure signals are forwarded to the JVM process correctly for graceful shutdown
        ENV LAUNCH_JBOSS_IN_BACKGROUND true
    
        USER jboss
    
        # Expose the ports we're interested in
        EXPOSE 8080
    
        # Set the default command to run on boot
        # This will boot WildFly in the standalone mode and bind to all interface
        CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0"]
  15. Press Ctrl+S to save the changes.

Your Dockerfile has been created.

Additional resources

1.2.2.2. Building a Docker image Using Red Hat Container Development Kit

Prerequisites

Procedure

  1. Start CodeReady Studio.
  2. Start the CDK server adapter.

    crs startink cdk server adapter
  3. Expand your Java project.
  4. Right-click DockerfileRun asDocker Image Build.

    crs run as docker image build

    The Docker Image Build Configuration window appears.

    crs creating docker image
  5. Select your Container Development Environment server adapter as your connection.
  6. Name your image.
  7. Click OK.

The Console view appears displaying the docker image building process.

1.2.2.3. Additional resources

1.2.3. Additional resources