3.2.2.2. OpenShift でサンプルアプリケーションを設定する方法
OpenShift インスタンスにログインします。
$ oc login <url>必要に応じて新規プロジェクトを作成します。
$ oc new-project jws-bin-demooc get is -n openshiftでアプリケーションに使用する OpenShift イメージストリームの JWS を特定します。$ oc get is -n openshift | grep ^jboss-webserver | cut -f1 -d ' ' jboss-webserver30-tomcat7-openshift jboss-webserver30-tomcat8-openshift jboss-webserver31-tomcat7-openshift jboss-webserver31-tomcat8-openshiftイメージストリームおよびアプリケーション名を指定して、新規ビルド設定を作成します。
$ oc new-build --binary=true \ --image-stream=jboss-webserver31-tomcat8-openshift \ --name=jws-wsch-app --> Found image 8c3b85b (4 weeks old) in image stream "openshift/jboss-webserver31-tomcat8-openshift" under tag "latest" for "jboss-webserver31-tomcat8-openshift" JBoss Web Server 3.1 -------------------- Platform for building and running web applications on JBoss Web Server 3.1 - Tomcat v8 Tags: builder, java, tomcat8 * A source build using binary input will be created * The resulting image will be pushed to image stream "jws-wsch-app:latest" * A binary build was created, use 'start-build --from-dir' to trigger a new build --> Creating resources with label build=jws-wsch-app ... imagestream "jws-wsch-app" created buildconfig "jws-wsch-app" created --> Successバイナリービルドを開始します。OpenShift イメージビルドのバイナリー入力にソースディレクトリーを使用するように OpenShift に指示します。
$ oc start-build jws-wsch-app --from-dir=./ocp --follow Uploading directory "ocp" as binary input for the build ... build "jws-wsch-app-1" started Receiving source from STDIN as archive ... Copying all deployments war artifacts from /home/jboss/source/deployments directory into /opt/webserver/webapps for later deployment... '/home/jboss/source/deployments/websocket-chat.war' -> '/opt/webserver/webapps/websocket-chat.war' Pushing image 172.30.202.111:5000/jws-bin-demo/jws-wsch-app:latest ... Pushed 0/7 layers, 7% complete Pushed 1/7 layers, 14% complete Pushed 2/7 layers, 29% complete Pushed 3/7 layers, 49% complete Pushed 4/7 layers, 62% complete Pushed 5/7 layers, 92% complete Pushed 6/7 layers, 100% complete Pushed 7/7 layers, 100% complete Push successfulイメージに基づいて新しい OpenShift アプリケーションを作成します。
$ oc new-app jws-wsch-app --> Found image e5f3a6b (About a minute old) in image stream "jws-bin-demo/jws-wsch-app" under tag "latest" for "jws-wsch-app" JBoss Web Server 3.1 -------------------- Platform for building and running web applications on JBoss Web Server 3.1 - Tomcat v8 Tags: builder, java, tomcat8 * This image will be deployed in deployment config "jws-wsch-app" * Ports 8080/tcp, 8443/tcp, 8778/tcp will be load balanced by service "jws-wsch-app" * Other containers can access this service through the hostname "jws-wsch-app" --> Creating resources ... deploymentconfig "jws-wsch-app" created service "jws-wsch-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/jws-wsch-app' Run 'oc status' to view your app.サービスを公開して、アプリケーションがユーザーにアクセスできるようにします。
# to check the name of the service to expose $ oc get svc -o name service/jws-wsch-app # to expose the service $ oc expose svc/jws-wsch-app route "jws-wsch-app" exposed公開されたルートのアドレスを取得します。
oc get routes --no-headers -o custom-columns='host:spec.host' jws-wsch-app- ブラウザーでアプリケーションにアクセスします: http://<address_of_exposed_route>/websocket-chat