3.5.4.2. 非接続クラスターでの devfile を使用した Java アプリケーションの作成

警告

この手順では、Red Hat でメンテナンスされていない quay.io/eclipse/che-java11-maven:nightly やアプリケーションサンプルの springboot-ex などの外部の依存関係を使用します。これらの依存関係についてはドキュメントでは保守対象ではなく、それらの機能は保証されていません。

前提条件

  • 非接続クラスターを作成し、ログインしている。
  • プロキシー設定に quay.ioregistry.access.redhat.comapache.orgquayio-production-s3.s3.amazonaws.com URL を追加している。

手順

  1. devfile で Java アプリケーションを定義します。

    devfile の例

    schemaVersion: 2.0.0
    metadata:
      name: java-maven
      version: 1.1.0
    starterProjects:
      - name: springbootproject
        git:
          remotes:
            origin: "https://github.com/odo-devfiles/springboot-ex.git"
    components:
      - name: tools
        container:
          image: quay.io/eclipse/che-java11-maven:nightly
          memoryLimit: 512Mi
          mountSources: true
          endpoints:
            - name: 'http-8080'
              targetPort: 8080
          volumeMounts:
            - name: m2
              path: /home/user/.m2
      - name: m2
        volume: {}
    commands:
      - id: mvn-package
        exec:
          component: tools
          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"
          group:
            kind: build
            isDefault: true
      - id: run
        exec:
          component: tools
          commandLine: "java -jar target/*.jar"
          group:
            kind: run
            isDefault: true
      - id: debug
        exec:
          component: tools
          commandLine: "java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=${DEBUG_PORT},suspend=n -jar target/*.jar"
          group:
            kind: debug
            isDefault: true

  2. Java アプリケーションを作成します。

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

    出力例

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

  3. 変更をクラスターにプッシュします。

    $ odo push

    出力例

    I0224 14:43:18.802512   34741 util.go:727] HTTPGetRequest: https://raw.githubusercontent.com/openshift/odo/master/build/VERSION
    I0224 14:43:18.833631   34741 context.go:115] absolute devfile path: '/Users/pkumari/go/src/github.com/openshift/odo/testim/devfile.yaml'
    [...]
    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)
    [INFO] Replacing main artifact with repackaged archive
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  19.638 s
    [INFO] Finished at: 2021-02-24T08:59:30Z
    [INFO] ------------------------------------------------------------------------
     ✓  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]
     •  Executing run command "java -jar target/*.jar"  ...
    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
    devrun: started
     ✓  Executing run command "java -jar target/*.jar" [3s]
    
    Pushing devfile component java-maven
     ✓  Changes successfully pushed to component

  4. ログを表示して、アプリケーションが起動していることを確認します。

    $ odo log

    出力例

    time="2021-02-24T08:58:58Z" level=info msg="create process:devrun"
    time="2021-02-24T08:58:58Z" level=info msg="create process:debugrun"
    time="2021-02-24T08:59:32Z" level=debug msg="no auth required"
    time="2021-02-24T08:59:32Z" level=debug msg="succeed to find process:devrun"
    time="2021-02-24T08:59:32Z" level=info msg="try to start program" program=devrun
    time="2021-02-24T08:59:32Z" level=info msg="success to start program" program=devrun
    ODO_COMMAND_RUN is java -jar target/*.jar
    Executing command  java -jar target/*.jar
    [...]

  5. アプリケーションのストレージを作成します。

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

    出力例

    ✓  Added storage storage-name to java-maven
    
    Please use `odo push` command to make the storage accessible to the component

  6. 変更をクラスターにプッシュします。

    $ odo push

    出力。

    ✓  Waiting for component to start [310ms]
    
    Validation
     ✓  Validating the devfile [100798ns]
    
    Creating Kubernetes resources for component java-maven
     ✓  Waiting for component to start [30s]
     ✓  Waiting for component to start [303ms]
    
    Applying URL changes
     ✓  URLs are synced with the cluster, no changes are required.
    
    Syncing to component java-maven
     ✓  Checking file changes for pushing [5ms]
     ✓  Syncing files to the component [4s]
    
    Executing devfile commands for component java-maven
     ✓  Waiting for component to start [526ms]
     ✓  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]
     ✓  Executing run command "java -jar target/*.jar" [3s]
    
    Pushing devfile component java-maven
     ✓  Changes successfully pushed to component