2.8.3.3. devfile を使用した Java アプリケーションのデプロイ

このセクションでは、devfile を使用して Maven および Java 8 JDK を使用するサンプル Java プロジェクトをデプロイする方法を説明します。

手順

  1. コンポーネントのソースコードを保存するディレクトリーを作成します。

    $ mkdir <directory-name>
  2. myspring という名前の Spring Boot コンポーネントのコンポーネント設定を作成し、そのサンプルプロジェクトをダウンロードします。

    $ odo create java-spring-boot myspring --starter

    直前のコマンドにより、以下の出力が生成されます。

    Experimental mode is enabled, use at your own risk
    
    Validation
    ✓  Checking devfile compatibility [195728ns]
    ✓  Creating a devfile component from registry: DefaultDevfileRegistry [170275ns]
    ✓  Validating devfile component [281940ns]
    
    Please use `odo push` command to create the component with source deployed

    odo create コマンドは、記録された devfile レジストリーから関連付けられた devfile.yaml ファイルをダウンロードします。

  3. ディレクトリーの内容を一覧表示し、devfile およびサンプル Java アプリケーションがダウンロードされていることを確認します。

    $ ls

    直前のコマンドにより、以下の出力が生成されます。

    README.md    devfile.yaml    pom.xml        src
  4. デプロイされたコンポーネントにアクセスするための URL を作成します。

    $ odo url create --host apps-crc.testing

    直前のコマンドにより、以下の出力が生成されます。

    ✓  URL myspring-8080.apps-crc.testing created for component: myspring
    
    To apply the URL configuration changes, please use odo push
    注記

    URL の作成時にクラスターのホストドメイン名を使用する必要があります。

  5. コンポーネントをクラスターにプッシュします。

    $ odo push

    直前のコマンドにより、以下の出力が生成されます。

    Validation
     ✓  Validating the devfile [81808ns]
    
    Creating Kubernetes resources for component myspring
     ✓  Waiting for component to start [5s]
    
    Applying URL changes
     ✓  URL myspring-8080: http://myspring-8080.apps-crc.testing created
    
    Syncing to component myspring
     ✓  Checking files for pushing [2ms]
     ✓  Syncing files to the component [1s]
    
    Executing devfile commands for component myspring
     ✓  Executing devbuild command "/artifacts/bin/build-container-full.sh" [1m]
     ✓  Executing devrun command "/artifacts/bin/start-server.sh" [2s]
    
    Pushing devfile component myspring
     ✓  Changes successfully pushed to component
  6. コンポーネントの URL を一覧表示し、コンポーネントが正常にプッシュされたことを確認します。

    $ odo url list

    直前のコマンドにより、以下の出力が生成されます。

    Found the following URLs for component myspring
    NAME              URL                                       PORT     SECURE
    myspring-8080     http://myspring-8080.apps-crc.testing     8080     false
  7. 生成された URL を使用してデプロイされたアプリケーションを表示します。

    $ curl http://myspring-8080.apps-crc.testing