Creating and deploying devfile components to the disconnected cluster

Creating a NodeJS application by using a devfile in a disconnected cluster

This procedure is using external dependencies such as nodejs-ex.git application that are not maintained by Red Hat. These dependencies are not maintained with the documentation and their functionality cannot be guaranteed.

Prerequisites

  • You have created and logged into a disconnected cluster.

  • You have added raw.githubusercontent.com, registry.access.redhat.com, and registry.npmjs.org URLs in your proxy.

Procedure

  1. Define your NodeJS application in a devfile:

    Example of a devfile

    1. schemaVersion: 2.0.0
    2. metadata:
    3. name: nodejs
    4. starterProjects:
    5. - name: nodejs-starter
    6. git:
    7. remotes:
    8. origin: "https://github.com/odo-devfiles/nodejs-ex.git"
    9. components:
    10. - name: runtime
    11. container:
    12. image: registry.access.redhat.com/ubi8/nodejs-12:1-36
    13. memoryLimit: 1024Mi
    14. endpoints:
    15. - name: "3000/tcp"
    16. targetPort: 3000
    17. env:
    18. - name: HTTP_PROXY
    19. value: http://<proxy-host>:<proxy-port>
    20. - name: HTTPS_PROXY
    21. value: http://<proxy-host>:<proxy-port>
    22. mountSources: true
    23. commands:
    24. - id: devbuild
    25. exec:
    26. component: runtime
    27. commandLine: npm install
    28. workingDir: ${PROJECTS_ROOT}
    29. group:
    30. kind: build
    31. isDefault: true
    32. - id: build
    33. exec:
    34. component: runtime
    35. commandLine: npm install
    36. workingDir: ${PROJECTS_ROOT}
    37. group:
    38. kind: build
    39. - id: devrun
    40. exec:
    41. component: runtime
    42. commandLine: npm start
    43. workingDir: ${PROJECTS_ROOT}
    44. group:
    45. kind: run
    46. isDefault: true
    47. - id: run
    48. exec:
    49. component: runtime
    50. commandLine: npm start
    51. workingDir: ${PROJECTS_ROOT}
    52. group:
    53. kind: run
  2. Create the application and push the changes to the cluster:

    1. $ odo create nodejs --devfile <path-to-your-devfile> --starter $$ odo push

    Example output

    1. [...]
    2. Pushing devfile component nodejs
    3. Changes successfully pushed to component
  3. Create a URL to access your application and push it to the cluster:

    1. $ odo url create url1 --port 3000 --host example.com --ingress && odo push

    Example output

    1. Validation
    2. Validating the devfile [145374ns]
    3. Creating Kubernetes resources for component nodejs
    4. Waiting for component to start [14s]
    5. Applying URL changes
    6. URL url1: http://url1.abcdr.com/ created
    7. Syncing to component nodejs
    8. Checking file changes for pushing [2ms]
    9. Syncing files to the component [3s]
    10. Executing devfile commands for component nodejs
    11. Executing devbuild command "npm install" [4s]
    12. Executing devrun command "npm start" [3s]
    13. Pushing devfile component nodejs
    14. Changes successfully pushed to component
  4. Add the storage to your application

    1. $ odo storage create <storage-name> --path /data --size 5Gi

    Example output

    1. Added storage abcde to nodejs
    2. Please use `odo push` command to make the storage accessible to the component
  5. Push the changes to the cluster:

    1. $ odo push

Creating a Java application by using a devfile in a disconnected cluster

This procedure is using external dependencies such as quay.io/eclipse/che-java11-maven:nightly or an example application springboot-ex that are not maintained by Red Hat. These dependencies are not maintained with the documentation and their functionality cannot be guaranteed.

Prerequisites

  • You have created and logged into a disconnected cluster.

  • You have added quay.io, registry.access.redhat.com, apache.org, quayio-production-s3.s3.amazonaws.com URLs in your proxy configuration.

Procedure

  1. Define your Java application in a devfile:

    Example of a devfile

    1. schemaVersion: 2.0.0
    2. metadata:
    3. name: java-maven
    4. version: 1.1.0
    5. starterProjects:
    6. - name: springbootproject
    7. git:
    8. remotes:
    9. origin: "https://github.com/odo-devfiles/springboot-ex.git"
    10. components:
    11. - name: tools
    12. container:
    13. image: quay.io/eclipse/che-java11-maven:nightly
    14. memoryLimit: 512Mi
    15. mountSources: true
    16. endpoints:
    17. - name: 'http-8080'
    18. targetPort: 8080
    19. volumeMounts:
    20. - name: m2
    21. path: /home/user/.m2
    22. - name: m2
    23. volume: {}
    24. commands:
    25. - id: mvn-package
    26. exec:
    27. component: tools
    28. commandLine: "mvn -Dmaven.repo.local=/home/user/.m2/repository -Dhttp.proxyHost=<proxy-host> -Dhttp.proxyPort=<proxy-port> -Dhttps.proxyHost=<proxy-host> -Dhttps.proxyPort=<proxy-port> package"
    29. group:
    30. kind: build
    31. isDefault: true
    32. - id: run
    33. exec:
    34. component: tools
    35. commandLine: "java -jar target/*.jar"
    36. group:
    37. kind: run
    38. isDefault: true
    39. - id: debug
    40. exec:
    41. component: tools
    42. commandLine: "java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=${DEBUG_PORT},suspend=n -jar target/*.jar"
    43. group:
    44. kind: debug
    45. isDefault: true
  2. Create a Java application:

    1. $ odo create java-maven --devfile <path-to-your-devfile> --starter

    Example output

    1. Validation
    2. Checking devfile existence [87716ns]
    3. Creating a devfile component from registry: DefaultDevfileRegistry [107247ns]
    4. Validating devfile component [396971ns]
    5. Starter Project
    6. Downloading starter project springbootproject from https://github.com/odo-devfiles/springboot-ex.git [2s]
    7. Please use `odo push` command to create the component with source deployed
  3. Push the changes to the cluster:

    1. $ odo push

    Example output

    1. I0224 14:43:18.802512 34741 util.go:727] HTTPGetRequest: https://raw.githubusercontent.com/openshift/odo/master/build/VERSION
    2. I0224 14:43:18.833631 34741 context.go:115] absolute devfile path: '/Users/pkumari/go/src/github.com/openshift/odo/testim/devfile.yaml'
    3. [...]
    4. Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.2.1/plexus-utils-3.2.1.jar (262 kB at 813 kB/s)
    5. [INFO] Replacing main artifact with repackaged archive
    6. [INFO] ------------------------------------------------------------------------
    7. [INFO] BUILD SUCCESS
    8. [INFO] ------------------------------------------------------------------------
    9. [INFO] Total time: 19.638 s
    10. [INFO] Finished at: 2021-02-24T08:59:30Z
    11. [INFO] ------------------------------------------------------------------------
    12. Executing mvn-package command "mvn -Dmaven.repo.local=/home/user/.m2/repository -Dhttp.proxyHost=<proxy-host> -Dhttp.proxyPort=<proxy-port> -Dhttps.proxyHost=<proxy-host> -Dhttps.proxyPort=<proxy-port> package" [23s]
    13. Executing run command "java -jar target/*.jar" ...
    14. I0224 14:29:30.557676 34426 exec.go:27] Executing command [/opt/odo/bin/supervisord ctl start devrun] for pod: java-maven-5b8f99fcdb-9dnk6 in container: tools
    15. devrun: started
    16. Executing run command "java -jar target/*.jar" [3s]
    17. Pushing devfile component java-maven
    18. Changes successfully pushed to component
  4. Display the logs to verify that the application has started:

    1. $ odo log

    Example output

    1. time="2021-02-24T08:58:58Z" level=info msg="create process:devrun"
    2. time="2021-02-24T08:58:58Z" level=info msg="create process:debugrun"
    3. time="2021-02-24T08:59:32Z" level=debug msg="no auth required"
    4. time="2021-02-24T08:59:32Z" level=debug msg="succeed to find process:devrun"
    5. time="2021-02-24T08:59:32Z" level=info msg="try to start program" program=devrun
    6. time="2021-02-24T08:59:32Z" level=info msg="success to start program" program=devrun
    7. ODO_COMMAND_RUN is java -jar target/*.jar
    8. Executing command java -jar target/*.jar
    9. [...]
  5. Create storage for your application:

    1. $ odo storage create storage-name --path /data --size 5Gi

    Example output

    1. Added storage storage-name to java-maven
    2. Please use `odo push` command to make the storage accessible to the component
  6. Push the changes to the cluster:

    1. $ odo push

    Output

    1. Waiting for component to start [310ms]
    2. Validation
    3. Validating the devfile [100798ns]
    4. Creating Kubernetes resources for component java-maven
    5. Waiting for component to start [30s]
    6. Waiting for component to start [303ms]
    7. Applying URL changes
    8. URLs are synced with the cluster, no changes are required.
    9. Syncing to component java-maven
    10. Checking file changes for pushing [5ms]
    11. Syncing files to the component [4s]
    12. Executing devfile commands for component java-maven
    13. Waiting for component to start [526ms]
    14. Executing mvn-package command "mvn -Dmaven.repo.local=/home/user/.m2/repository -Dhttp.proxyHost=<proxy-host> -Dhttp.proxyPort=<proxy-port> -Dhttps.proxyHost=<proxy-host> -Dhttps.proxyPort=<proxy-port> package" [10s]
    15. Executing run command "java -jar target/*.jar" [3s]
    16. Pushing devfile component java-maven
    17. Changes successfully pushed to component