Red Hat 㧠Solution Architect ã¨ã㦠OpenJDK ãæ å½ãã¦ããä¼è¤ã¡ã²ãï¼@chiroitoï¼ã§ãã
ãã®è¨äºã¯ãRed Hat Developerã®ããã°è¨äºãCreating and deploying a Java 8 runtime container image | Red Hat Developer ã®ç¿»è¨³è¨äºã§ãã
Javaã®å®è¡ç°å¢ã¯ã³ã³ãã¤ã«ãããã½ã¼ã¹ã³ã¼ããå®è¡ã§ãããã®ã§ãªããã°ãªããªãããä¾ãã°OpenJDKã®ãããªéçºãããã«ã¯ãã½ã¼ã¹ã³ã¼ããã³ã³ãã¤ã«ãã¦å®è¡ããããã®ã©ã¤ãã©ãª/ãã¤ããªããã¹ã¦å«ã¾ãã¦ãããåºæ¬çã«ãå¾è ã¯å®è¡ç°å¢ã®ä¸ä½éåã§ããOpenJDKã®ãµãã¼ãã¨ã©ã¤ããµã¤ã¯ã«ã«é¢ãã詳細ã¯ãã¡ããã覧ãã ããã
Red Hat ã¯ãJava 8 㨠11 ã®ä¸¡æ¹ã® OpenJDK ãæè¼ããã³ã³ããã¤ã¡ã¼ã¸ãåºè·ãããµãã¼ããã¦ãã¾ãã詳細ã¯ãã¡ããåç §ãã¦ãã ãããRed Hat Middleware ã使ç¨ãã¦ããå ´åãåºè·ããã s2i ã¤ã¡ã¼ã¸ã¯ãRed Hat Openshift Container Platform ãªã©ã«ãããã¤ããã®ã«ã便å©ã§ãã
Red Hatã¯OpenJDKãã¼ã¹ã®Java 8ã¨11ã®ã¤ã¡ã¼ã¸ããæä¾ãã¦ããªããã¨ã«æ³¨æãã¦ãã ãããã¨ã¯ãããéçºè ãç¬èªã®Javaã©ã³ã¿ã¤ã ã¤ã¡ã¼ã¸ãä½æãããå ´åãããã§ããããä¾ãã°ãã©ã³ã¿ã¤ã ã¤ã¡ã¼ã¸ãå®è¡ããããã«ã¹ãã¬ã¼ã¸ãæå°åããã¨ãã£ãçç±ãèãããã¾ãããã®ä¸æ¹ã§ãJolokioãHawkularãªã©ã®ã©ã¤ãã©ãªããã»ãã¥ãªãã£ãã©ã¡ã¼ã¿ã®è¨å®ãªã©ãå¤ãã®æä½æ¥ãå¿ è¦ã«ãªãã¾ãããããã£ãç´°ããä½æ¥ãããããªãå ´åã¯ãRed Hatãåºè·ãã¦ããOpenJDKç¨ã®ã³ã³ããã¤ã¡ã¼ã¸ã使ããã¨ããå§ããã¾ãã
ãã®è¨äºã§ã¯ã以ä¸ã®ãã¨ãè¡ãã¾ãã
- Dockerã¨Buildahã§ã¤ã¡ã¼ã¸ãæ§ç¯ãã¾ãã
- Dockerã¨Podmanã使ã£ã¦ãã¤ã¡ã¼ã¸ãlocalhostã§å®è¡ãã¾ãã
- ã¤ã¡ã¼ã¸ãQuayã«ããã·ã¥ãã¾ãã
- æå¾ã«ãOpenShiftã«ã¹ããªã¼ã ãã¤ã³ãã¼ããã¦ã¢ããªãå®è¡ãã¾ãã
ãã®è¨äºã¯ãOpenShift 3.11ã¨4.0ã®ãã¼ã¿çã®ä¸¡æ¹ã§æ¸ããã¦ãã¾ããæ©éã§ããããç´¹ä»ãã¾ãã
è¨å®æ¹æ³
ç§ãã¡ã®ã¤ã¡ã¼ã¸ã使ç¨ãããã®åä½ã確èªããããã«ããã³ãã«ã®ä¸é¨ã¨ãã¦Webã¢ããªã使ç¨ãã¾ããæè¿ãMicroprofile.ioã¯ãMicroProfile Starter betaãçºè¡¨ãã¾ãããããã¯ããã¦ã³ãã¼ãå¯è½ãªããã±ã¼ã¸ãä½æãããã¨ã§ãMicroProfileã®ä½¿ç¨ãéå§ããã®ã«å½¹ç«ã¡ã¾ããMicroprofile.ioã«ã¢ã¯ã»ã¹ãã¦ãMicroProfile with Thorntail V2ã®ããã±ã¼ã¸ãå ¥æãã¦ãã ããã
ãã¦ã³ãã¼ããã¿ã³ãã¯ãªãã¯ãã¦ã¢ã¼ã«ã¤ããã¡ã¤ã«ãåå¾ãã¾ãã
Red Hat Enterprise Linuxï¼RHELï¼ã®ãã·ã³ã§ã¯ãã¾ããdemoapp
ãªã©ã®ä¸æãã£ã¬ã¯ããªãä½æãããã¦ã³ãã¼ãããææç©ãããã«è§£åãã¾ãã
tempãã£ã¬ã¯ããªã§ã次ã®ããã«å®è¡ãã¾ãï¼
$ mvn clean compile package
ããã§ããã«ãããããã¢ã¢ããªãã§ãããããfat jarãã§ãã¾ããããã®jarãå¼ã³åºãã¦ãThorntailãå®è¡ã§ãã¾ãã
target/demo-thorntail.jar`ãtempãã£ã¬ã¯ããªã«ã³ãã¼ãã¾ãããã
ããã§ã¯ãåã¬ã¤ã¤ã¼ã«ã³ã¡ã³ããã¤ããDockerfile
ãç´¹ä»ãã¾ãããã®ãã¡ã¤ã«ã®ã½ã¼ã¹ã³ã¼ãã¯ããã¡ãã®GitHubã§ãã覧ããã ãã¾ãã
# Java 8 ã©ã³ã¿ã¤ã ã®ä¾ # Red Hatã®å ¬å¼ã¬ã¸ã¹ããªã¨ãã¼ã¹ã¤ã¡ã¼ã¸ FROM registry.access.redhat.com/rhel7-minimal USER root # Javaã©ã³ã¿ã¤ã ã®ã¤ã³ã¹ãã¼ã« RUN microdnf --enablerepo=rhel-7-server-rpms \ install java-1.8.0-openjdk --nodocs ;\ microdnf clean all # Javaãã©ãã«ããããæ確ã«ããããã«JAVA_HOMEå¤æ°ãè¨å®ãã ENV JAVA_HOME /etc/alternatives/jre # èªåã®ã¢ããªã®ããã®ãã£ã¬ã¯ã㪠RUN mkdir -p /app # ãªãã¹ã³ãããã¼ããå ¬éãã EXPOSE 8080 # MicroProfile starter appãã³ãã¼ãã COPY demo-thorntail.jar /app/ # ã¹ã¯ãªãããã½ã¼ã¹ããã³ãã¼ï¼ run-java.shã¯ãã³ã³ããå ã§ã³ãã³ãã©ã¤ã³ããThorntailã¢ããªãå®è¡ããããã®ç¹å®ã®ãã©ã¡ã¼ã¿ãæã£ã¦ãã¾ããã¹ã¯ãªããã®è©³ç´°ã¯ https://github.com/sshaaf/rhel7-jre-image/blob/master/run-java.sh ã«ããã¾ãã COPY run-java.sh /app/ # ã¹ã¯ãªãããå®è¡ããããã®ãã¼ããã·ã§ã³ã®è¨å® RUN chmod 755 /app/run-java.sh # æå¾ã«ãã¹ã¯ãªãããå®è¡ãã CMD [ "/app/run-java.sh" ]
ãã¦ãDockerfile
ã®è©³ç´°ãããã£ãã¨ããã§ãã¤ã¡ã¼ã¸ã®æ§ç¯ãé²ãã¦ããã¾ãããã
éè¦ãªç¹ã¨ãã¦ãOpenJDKã®Javaã©ã³ã¿ã¤ã ã¯ãjava-1.8.0-openjdkãã¨ãã¦ããã±ã¼ã¸ããã¦ãã¾ããããã«ã¯ã-devel
ããã±ã¼ã¸ã«å«ã¾ãã¦ããã³ã³ãã¤ã©ããã®ä»ã®éçºã©ã¤ãã©ãªã¯å«ã¾ãã¦ãã¾ããã
ä¸è¨ã®Dockerfile
ã¯RHELã§ãã«ãããã¦ãã¾ããã¤ã¾ãããã¹ãã«ã¯ãã§ã«ãµãã¹ã¯ãªãã·ã§ã³ãæ·»ä»ããã¦ããã®ã§ãsubscription-manager
ã«ç»é²ããå¿
è¦ã¯ããã¾ããã
以ä¸ã«ããããæ§ç¯ãã2ã¤ã®æ¹æ³ãç´¹ä»ãã¾ããç§ã®ããã« RHEL ã使ç¨ãã¦ããå ´åã¯ã2 ã¤ã®ãã¤ããªã®ãããããé¸æãã¦ãããã¤ã§ãã¾ãã両æ¹ã¨ã rhel7-server-extras-rpms
ã«ããã¯ãã§ãã
次ã®ããã«ã㦠extras
ãªãã¸ããªãæå¹ã«ãã¾ãã
# subscription-manager repos --enable rhel-7-server-extras-rpms
ãã¼ã«ã«ã§ã¤ã¡ã¼ã¸ããã«ãã¨å®è¡
docker
ã§ã¤ã¡ã¼ã¸ãæ§ç¯ãã¾ãã
$ docker build -t quay.io/sshaaf/rhel7-jre8-mpdemo:latest .
ã¤ã¡ã¼ã¸ã docker
ã§å®è¡ããlocalhost:8080 ãã³ã³ããã®ãã¼ã 8080 ã«æå®ãã¾ãã
$ docker run -d -t -p 8080:8080 -i quay.io/sshaaf/rhel7-jre8-mpdemo:latest
ã¾ããbuildahã³ãã³ãã使ç¨ã§ãã¾ããããã¯ãä½æ¥ä¸ã®ã³ã³ãããããDockerfileãããã¾ãã¯ã¹ã¯ã©ããããã³ã³ããã¤ã¡ã¼ã¸ãä½æããã®ã«å½¹ç«ã¡ã¾ããä½æãããã¤ã¡ã¼ã¸ã¯OCIã«æºæ ãã¦ããã®ã§ãOCIã©ã³ã¿ã¤ã ä»æ§ãæºãããã©ã³ã¿ã¤ã ï¼DockerãCRI-Oãªã©ï¼ã§åä½ãã¾ãã
buildah
ã§ãã«ããã¾ãï¼
$ buildah bud -t rhel7-jre8-mpdemo .
buildah
ã§ã³ã³ãããä½ãã¾ãï¼
$ buildah from rhel7-jre8-mpdemo
ã¾ããPodmanã使ã£ã¦ãã³ã³ãããå®è¡ã§ãã¾ããããã¯BuildahãSkopeoãè£å®ãããã®ã§ãDockerã®ã³ãã³ãã©ã¤ã³ã«ä¼¼ãä½é¨ãæä¾ãããã®ã§ããããã«ãããã¦ã¼ã¶ã¼ã¯ã¹ã¿ã³ãã¢ãã³ã®ï¼ãªã¼ã±ã¹ãã¬ã¼ã·ã§ã³ããã¦ããªãï¼ã³ã³ãããå®è¡ã§ããããã«ãªãã¾ããã¾ããPodmanã¯ã³ã³ãããããããå®è¡ããããã®ãã¼ã¢ã³ãå¿
è¦ã¨ãã¾ãããPodmanã¯extras
ãã£ã³ãã«ã®ä¸é¨ã§ãããã以ä¸ã®ã³ãã³ãã§ã³ã³ãããå®è¡ã§ãã¾ãã
$ podman run -d -t -p 8080:8080 -i quay.io/sshaaf/rhel7-jre8-mpdemo:latest
Podmanã®è©³ç´°ã«ã¤ãã¦ã¯ãContainers without daemons: Podman and Buildah available in RHEL 7.6 and RHEL 8 Betaããã³Podman and Buildah for Docker usersãã覧ãã ããã
ã¤ã¡ã¼ã¸ãã§ããã®ã§ãããã OpenShift ã«ãããã¤ãã¦ã¢ããªããã¹ããããã¨æãã¾ãããã®ããã«ã¯ãoc
ã¯ã©ã¤ã¢ã³ãã©ã¤ãã©ãªãå¿
è¦ã§ããç§ã¯èªåã®ã¯ã©ã¹ã¿ãè¨å®ãã¦ãã¾ãããRed Hat Container Development Kit (CDK)/minishiftãRed Hat OpenShift Onlineãã¾ãã¯èªåã®ã¯ã©ã¹ã¿ã使ç¨ã§ãã¾ããæé ã¯åãã«ãªãã¯ãã§ãã
OpenShiftã«ãããã¤
OpenShiftã«ãããã¤ããããã«ã¯ã以ä¸ã®ãããªæ§æãå¿ è¦ã§ãã
- æ°ããä½æããã³ã³ããã¤ã¡ã¼ã¸ã®ã¤ã¡ã¼ã¸ã¹ããªã¼ã
- OpenShiftç¨ã®ãããã¤ã¡ã³ãæ§æ
- ãµã¼ãã¹ã¨ã«ã¼ãã£ã³ã°ã®è¨å®
ã¤ã¡ã¼ã¸ã¹ããªã¼ã
ã¤ã¡ã¼ã¸ã¹ããªã¼ã ãä½æããããã«ãç§ã®OpenShiftã¯ã©ã¹ã¿ã¯ã©ããããã³ã³ããã¤ã¡ã¼ã¸ãå¼ãåºããããã«ããªããã°ãªãã¾ãããããã¾ã§ãã¤ã¡ã¼ã¸ã¯ç§èªèº«ã®ãã·ã³ã«åå¨ãã¦ãã¾ãããããã Quay ã«ããã·ã¥ãã¦ã¿ã¾ããããRed Hat Quayã®ã³ã³ããã¨ã¢ããªã±ã¼ã·ã§ã³ã®ã¬ã¸ã¹ããªã¯ãããããã¤ã³ãã©ä¸ã§ã³ã³ããã®å®å ¨ãªä¿ç®¡ãé å¸ããããã¤ãæä¾ãã¾ããã¹ã¿ã³ãã¢ãã³ã®ã³ã³ãã¼ãã³ãã¨ãã¦ããOpenShiftã¨çµã¿åããã¦ãå©ç¨å¯è½ã§ãã
ã¾ãQuayã«ãã°ã¤ã³ããå¿ è¦ãããã¾ãããããã¯ä»¥ä¸ã®ããã«è¡ãã¾ãã
$ docker login -u="sshaaf" -p="XXXX" quay.io
ããã¦ãæ°ããä½ã£ãã¤ã¡ã¼ã¸ãQuayã«ããã·ã¥ãã¾ãï¼
$ docker push quay.io/sshaaf/rhel7-jre8-mpdemo
ããã§ã¯ããããã¤ããåã®æ§æãè¦ã¦ã¿ã¾ããããæ°ã«ãªãæ¹ã¯ããããã¤ãã³ãã¬ã¼ãã®è©³ç´°ãèªã¿é£ã°ãã¦ãããã¸ã§ã¯ãã®ä½æã«é²ãã§ãã ããã
ã¤ã¡ã¼ã¸ãã§ããã®ã§ãã¹ããªã¼ã ãå®ç¾©ãã¾ãã
- apiVersion: v1 kind: ImageStream metadata: name: rhel7-jre8-mpdemo spec: dockerImageRepository: quay.io/sshaaf/rhel7-jre8-mpdemo
ä¸ã®ä¾ã§ã¯ãQuay.ioã®ã¤ã¡ã¼ã¸ãªãã¸ããªã«ç´æ¥ã¢ã¯ã»ã¹ãã¦ãã¾ãã
ãããã¤ã¡ã³ãã³ã³ãã£ã°
次ã¯ããããã¤ã¡ã³ãè¨å®ã§ããããã§ã¯ãããããããªã¬ã¼ãè¨å®ããæ°ããä½æããã¹ããªã¼ã ãæå®ãããªã©ãã¾ãã
ã³ã³ãããOpenShiftã®ãããã¤ã¡ã³ãã«æ £ãã¦ããªãæ¹ã¯ããã¡ãã®ä¾¿å©ãªebookãã覧ã«ãªãã¨ããã§ãããã
- apiVersion: v1 kind: DeploymentConfig metadata: name: rhel7-jre8-mpdemo spec: template: metadata: labels: name: rhel7-jre8-mpdemo spec: containers: - image: quay.io/sshaaf/rhel7-jre8-mpdemo:latest name: rhel7-jre8-mpdemo ports: - containerPort: 8080 protocol: TCP replicas: 1 triggers: - type: ConfigChange - imageChangeParams: automatic: true containerNames: - rhel7-jre8-mpdemo from: kind: ImageStreamTag name: rhel7-jre8-mpdemo:latest type: ImageChange
ãµã¼ãã¹
ããã§ãããã¤ã¡ã³ããã§ããã®ã§ãå é¨ã®ãã¼ããã©ã³ã·ã³ã°ããããã®IPã¢ãã¬ã¹ãªã©ã確ä¿ãããµã¼ãã¹ãå®ç¾©ãããã¨æãã¾ãã
ãµã¼ãã¹ã¯ãæ°ããä½æããã¢ããªãæçµçã«å¤é¨ã®ãã©ãã£ãã¯ã«å ¬éãããå ´åã«éè¦ã§ãã
- apiVersion: v1 kind: Service metadata: name: rhel7-jre8-mpdemo spec: ports: - name: 8080-tcp port: 8080 protocol: TCP targetPort: 8080 selector: deploymentconfig: rhel7-jre8-mpdemo
ã«ã¼ã
ããã¦ããããã¤ã¡ã³ãã®æå¾ã®é¨åã¯ãã«ã¼ãã§ããã«ã¼ãã使ã£ã¦ã¢ããªãå¤é¨ã«å ¬éããæãæ¥ã¾ããããã®ã«ã¼ããã©ã®å é¨ãµã¼ãã¹ãæãã®ããã©ã®ãã¼ããã¿ã¼ã²ããã«ããã®ããå®ç¾©ã§ãã¾ããOpenShift ã¯ã«ã¼ãã«ãã¬ã³ããªã¼ãª URL ãä¸ãã¾ãããã® URL ãæå®ãããã¨ã§ãæ°ããä½æãã Java 8 ã©ã³ã¿ã¤ã ãã¼ã¹ã®ãããã¤ã¡ã³ãä¸ã§ MicroProfile ã¢ããªãå®è¡ãããã®ã確èªã§ãã¾ãã
- apiVersion: v1 kind: Route metadata: name: rhel7-jre8-mpdemo spec: port: targetPort: 8080-tcp to: kind: Service name: rhel7-jre8-mpdemo weight: 100
ä¸è¨ã®å®å ¨ãªãã³ãã¬ã¼ãã¯GitHubã®ããã«ããã¾ãã
ã¾ãããã®ããã«OpenShiftã§ããã¸ã§ã¯ããä½æãã¦ã¿ã¾ãããã
$ oc new-project jredemos
ããã¦ããã³ãã¬ã¼ããå¦çãã¦ãOpenShiftä¸ã§Java 8ã©ã³ã¿ã¤ã ã使ã£ããã¢ãåå¾ãã¾ãããã®ããã«ã¯ã以ä¸ã®ã³ãã³ããå®è¡ãã¾ãã
$ oc process -f deployment.yaml | oc create -f -
ããã§ãããã¤ã¡ã³ãå ¨ä½ãä½æããã以ä¸ã®ããã«è¡¨ç¤ºãããã¯ãã§ãã
ããã§ã次ã®ã³ãã³ããå®è¡ãã¾ãã
$ oc get routes
ããã«ããã以ä¸ã®ãããªã«ã¼ãã表示ããã¾ãã
ãã®ã«ã¼ãããã©ã¦ã¶ã«ã³ãã¼ããã¨ãRHEL 7ä¸ã§Java 8ã©ã³ã¿ã¤ã ãåä½ããWebã¢ããªããããã¤ããã¦ãããã¨ã確èªã§ãã¾ãã(以ä¸ã®ã¢ãã¬ã¹ã¯ãã¯ã©ã¹ã¿ã®ãã¹ãå°ç¨ã§ãããã¯ã©ã¹ã¿ãã¨ã«ç°ãªãã¾ã)
http://rhel7-jre8-mpdemo-jredemos.apps.cluster-1fda.1fda.openshiftworkshop.com/
ã¾ã¨ã
Dockerã¾ãã¯Buildahã使ã£ã¦ãJava 8ã©ã³ã¿ã¤ã ã®ã³ã³ããã¤ã¡ã¼ã¸ãæ§ç¯ã»ä½æãããã¨ã«æåãã¾ããã以ä¸ã®ç¹ã«æ³¨æãã¦ãã ããã
- ãã®ç»åã¯ãã©ã®ããã«ãã¦å®ç¾ãããã示ãããã®ãã®ã§ãããã¨ã«æ³¨æãã¦ãã ãããJolokioãHawkularã®ãããªããããã¤ã«å¿ è¦ãªãã®ã¯å«ã¾ãã¦ãã¾ããã
- ããã«ãã³ã³ããå ã§Javaã¢ããªãå®è¡ããããã«å¿ è¦ãªãã©ã¡ã¼ã¿ã¯èæ ®ããã¦ãã¾ãããããã«ã¤ãã¦ã¯ãRafael Benevidesæ°ã®è¨äºã§é常ã«ãã説æããã¦ãã¾ãã
- ããã«ãç¬èªã®ã³ã³ããã¤ã¡ã¼ã¸ããããã¤ããéã«ã¯ãRed Hat ã® OpenJDK ãã«ããå®è¡ãã¦ããå ´åããµãã¼ãããã³ã©ã¤ããµã¤ã¯ã«ããªã·ã¼ ãã¡ã ã確èªãããã¨ã常ã«å¿ããªãã§ãã ããã
ãã®å¾ãMicroProfile Starter betaããåºæ¬çãªMicroProfileã®ãã¢ã¢ããªã使ã£ã¦OpenShiftã«ãããã¤ãã¾ããã
ããå æ¬çãªãã¢ã¢ããªã®ä½æãæ¤è¨ããã¦ããæ¹ã¯ã以ä¸ã®è³æããåç §ãã ããã
- Deploying MicroProfile apps on Microsoft Azure using the Azure Open Service Broker
- The MicroProfile ebook ãã¡ã
æ¬è¨äºã®å ¨è³æã¯ãã¡ãããã覧ããã ãã¾ãã