検索

3.2. バイナリーアーティファクトからの Java アプリケーションのビルドおよびデプロイ

download PDF

バイナリーソース機能を使用して、既存の Java アプリケーションを OpenShift にデプロイできます。

この手順では、undertow-servlet クイックスタートを使用してローカルマシンで Java アプリケーションを構築します。クイックスタートは、S2I バイナリーソース機能を使用して、作成されたバイナリーアーティファクトを OpenShift にコピーします。

前提条件

  • ローカルマシンで Red Hat JBoss Enterprise Maven リポジトリーを有効にします。
  • JAR アプリケーションアーカイブを取得し、アプリケーションをローカルにビルドします。

    • undertow-servlet ソースコードのクローンを作成します。

      $ git clone https://github.com/jboss-openshift/openshift-quickstarts.git
    • アプリケーションをビルドします。

      $ cd openshift-quickstarts/undertow-servlet/
      $ mvn clean package
      [INFO] Scanning for projects...
      ...
      [INFO]
      [INFO] ------------------------------------------------------------------------
      [INFO] Building Undertow Servlet Example 1.0.0.Final
      [INFO] ------------------------------------------------------------------------
      ...
      [INFO] ------------------------------------------------------------------------
      [INFO] BUILD SUCCESS
      [INFO] ------------------------------------------------------------------------
      [INFO] Total time: 1.986 s
      [INFO] Finished at: 2017-06-27T16:43:07+02:00
      [INFO] Final Memory: 19M/281M
      [INFO] ------------------------------------------------------------------------
  • ローカルファイルシステムでディレクトリー構造を準備します。

    deployments/ サブディレクトリー (メインのバイナリービルドディレクトリー) のアプリケーションアーカイブを標準のデプロイメントフォルダー (イメージが OpenShift 上にビルドされる場所) にコピーします。デプロイするアプリケーションの Web アプリケーションデータを含むディレクトリー階層を作成します。

    ローカルファイルシステム上にバイナリービルド用のメインディレクトリーと、そのディレクトリー内に deployments/ サブディレクトリーを作成します。ビルド JAR アーカイブを deployments/ サブディレクトリーにコピーします。

    undertow-servlet]$ ls
    dependency-reduced-pom.xml  pom.xml  README  src  target
    $ mkdir -p ocp/deployments
    $ cp target/undertow-servlet.jar ocp/deployments/

手順

  1. 以下のコマンドを実行して OpenShift インスタンスにログインし、認証情報を指定します。

    $ oc login
  2. 新しいプロジェクトを作成します。

    $ oc new-project jdk-bin-demo
  3. 新しいバイナリービルドを作成し、イメージストリームとアプリケーションの名前を指定します。

    $ oc new-build --binary=true \
    --name=jdk-us-app \
    --image-stream=java:11
    --> Found image c1f5b31 (2 months old) in image stream "openshift/java:11" under tag "latest" for "java:11"
    
        Java Applications
        -----------------
        Platform for building and running plain Java applications (fat-jar and flat classpath)
    
    --> Creating resources with label build=jdk-us-app ...
        imagestream "jdk-us-app" created
        buildconfig "jdk-us-app" created
    --> Success
    Application is not exposed. You can expose services to the outside world by executing one or more of the commands below:
     'oc expose svc/jdk-us-app'
  4. バイナリービルドを開始します。

    直前の手順で作成したバイナリービルドのメインディレクトリーを OpenShift ビルドのバイナリー入力が含まれるディレクトリーとして使用するよう oc 実行ファイルに指示します。

    $ oc start-build jdk-us-app --from-dir=./ocp --follow
    Uploading directory "ocp" as binary input for the build ...
    build "jdk-us-app-1" started
    Receiving source from STDIN as archive ...
    ==================================================================
    Starting S2I Java Build .....
    S2I source build with plain binaries detected
    Copying binaries from /tmp/src/deployments to /deployments ...
    ... done
    Pushing image 172.30.197.203:5000/jdk-bin-demo/jdk-us-app:latest ...
    Pushed 0/6 layers, 2% complete
    Pushed 1/6 layers, 24% complete
    Pushed 2/6 layers, 36% complete
    Pushed 3/6 layers, 54% complete
    Pushed 4/6 layers, 71% complete
    Pushed 5/6 layers, 95% complete
    Pushed 6/6 layers, 100% complete
    Push successful
  5. ビルドに基づいて新規の OpenShift アプリケーションを作成します。

    $ oc new-app jdk-us-app
    --> Found image 66f4e0b (About a minute old) in image stream "jdk-bin-demo/jdk-us-app" under tag "latest" for "jdk-us-app"
    
        jdk-bin-demo/jdk-us-app-1:c1dbfb7a
        ----------------------------------
        Platform for building and running plain Java applications (fat-jar and flat classpath)
    
        Tags: builder, java
    
        * This image will be deployed in deployment config "jdk-us-app"
        * Ports 8080/tcp, 8443/tcp, 8778/tcp will be load balanced by service "jdk-us-app"
          * Other containers can access this service through the hostname "jdk-us-app"
    
    --> Creating resources ...
        deploymentconfig "jdk-us-app" created
        service "jdk-us-app" created
    --> Success
        Run 'oc status' to view your app.
  6. サービスをルートとして公開します。

    $ oc expose svc/jdk-us-app
    route "jdk-us-app" exposed
  7. ルートを取得します。

    $ oc get route
  8. URL(直前のコマンド出力にある HOST/PORT フィールドの値) を使用して、ブラウザーでアプリケーションにアクセスします。

関連情報

  • バイナリーソース 機能を使用して、既存の Java アプリケーションを OpenShift にデプロイします。
  • Maven リポジトリーの設定方法に関する詳細は、Use the Maven Repository を参照してください。
Red Hat logoGithubRedditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

© 2024 Red Hat, Inc.