OpenShift S2I動作確認メモ

s2iのダウンロード
https://github.com/openshift/source-to-image/releases/latest
この動作確認ではsource-to-image-v1.1.13-b54d75d3-linux-386.tar.gzを利用している。

git cloneでサンプルを取得

```
git clone https://github.com/43books/ch09-builderimage.git
```

ビルダイメージの雛形を作成

```
s2i create builderimage ./ch09-builderimage
```

Dockerビルドの実行

```
[root@localhost ch09-builderimage]# make build
docker build -t builderimage .
Sending build context to Docker daemon  90.62kB
Step 1/8 : FROM openshift/base-centos7
latest: Pulling from openshift/base-centos7
45a2e645736c: Pull complete
734fb161cf89: Pull complete
78efc9e155c4: Pull complete
8a3400b7e31a: Pull complete
Digest: sha256:aea292a3bddba020cde0ee83e6a45807931eb607c164ec6a3674f67039d8cd7c
Status: Downloaded newer image for openshift/base-centos7:latest
 ---> 4842f0bd3d61
Step 2/8 : RUN yum install -y epel-release && yum install -y lighttpd && yum clean all -y
 ---> Running in 9358cafe1897
Loaded plugins: fastestmirror, ovl
Determining fastest mirrors
 * base: ftp.jaist.ac.jp
 * extras: ftp.jaist.ac.jp
 * updates: ftp.jaist.ac.jp
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:7-11 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                Arch             Version         Repository        Size
================================================================================
Installing:
 epel-release           noarch           7-11            extras            15 k

Transaction Summary
================================================================================
Install  1 Package

Total download size: 15 k
Installed size: 24 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : epel-release-7-11.noarch                                     1/1
  Verifying  : epel-release-7-11.noarch                                     1/1

Installed:
  epel-release.noarch 0:7-11

Complete!
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
 * base: ftp.jaist.ac.jp
 * epel: ftp.iij.ad.jp
 * extras: ftp.jaist.ac.jp
 * updates: ftp.jaist.ac.jp
Resolving Dependencies
--> Running transaction check
---> Package lighttpd.x86_64 0:1.4.52-1.el7 will be installed
--> Processing Dependency: system-logos >= 7.92.1 for package: lighttpd-1.4.52-1.el7.x86_64
--> Processing Dependency: psmisc for package: lighttpd-1.4.52-1.el7.x86_64
--> Processing Dependency: libfam.so.0()(64bit) for package: lighttpd-1.4.52-1.el7.x86_64
--> Running transaction check
---> Package centos-logos.noarch 0:70.0.6-3.el7.centos will be installed
---> Package gamin.x86_64 0:0.1.10-16.el7 will be installed
---> Package psmisc.x86_64 0:22.20-15.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package             Arch          Version                    Repository   Size
================================================================================
Installing:
 lighttpd            x86_64        1.4.52-1.el7               epel        433 k
Installing for dependencies:
 centos-logos        noarch        70.0.6-3.el7.centos        base         21 M
 gamin               x86_64        0.1.10-16.el7              base        128 k
 psmisc              x86_64        22.20-15.el7               base        141 k

Transaction Summary
================================================================================
Install  1 Package (+3 Dependent packages)

Total download size: 22 M
Installed size: 24 M
Downloading packages:
warning: /var/cache/yum/x86_64/7/epel/packages/lighttpd-1.4.52-1.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY
Public key for lighttpd-1.4.52-1.el7.x86_64.rpm is not installed
--------------------------------------------------------------------------------
Total                                              3.5 MB/s |  22 MB  00:06
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
Importing GPG key 0x352C64E5:
 Userid     : "Fedora EPEL (7) <epel@fedoraproject.org>"
 Fingerprint: 91e9 7d7c 4a5e 96f1 7f3e 888f 6a2f aea2 352c 64e5
 Package    : epel-release-7-11.noarch (@extras)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : gamin-0.1.10-16.el7.x86_64                                   1/4
  Installing : centos-logos-70.0.6-3.el7.centos.noarch                      2/4
  Installing : psmisc-22.20-15.el7.x86_64                                   3/4
  Installing : lighttpd-1.4.52-1.el7.x86_64                                 4/4
  Verifying  : psmisc-22.20-15.el7.x86_64                                   1/4
  Verifying  : lighttpd-1.4.52-1.el7.x86_64                                 2/4
  Verifying  : centos-logos-70.0.6-3.el7.centos.noarch                      3/4
  Verifying  : gamin-0.1.10-16.el7.x86_64                                   4/4

Installed:
  lighttpd.x86_64 0:1.4.52-1.el7

Dependency Installed:
  centos-logos.noarch 0:70.0.6-3.el7.centos     gamin.x86_64 0:0.1.10-16.el7
  psmisc.x86_64 0:22.20-15.el7

Complete!
Loaded plugins: fastestmirror, ovl
Cleaning repos: base epel extras updates
Cleaning up everything
Cleaning up list of fastest mirrors
Removing intermediate container 9358cafe1897
 ---> 72c4d4d842d6
Step 3/8 : COPY ./etc/ /opt/app-root/etc/
 ---> d5e9d384df5b
Step 4/8 : COPY ./s2i/bin/ /usr/libexec/s2i
 ---> 3364507cd1bd
Step 5/8 : RUN chown -R 1001:1001 /opt/app-root
 ---> Running in edb5b1524fc6
Removing intermediate container edb5b1524fc6
 ---> d4e7a1d514ae
Step 6/8 : RUN chmod +x /usr/libexec/s2i/*
 ---> Running in 2438d65082fd
Removing intermediate container 2438d65082fd
 ---> f53e45ceb36a
Step 7/8 : USER 1001
 ---> Running in a1ec455afc78
Removing intermediate container a1ec455afc78
 ---> 911a8bc6fa92
Step 8/8 : EXPOSE 8080
 ---> Running in c0171e2ccfbb
Removing intermediate container c0171e2ccfbb
 ---> e6de206bc533
Successfully built e6de206bc533
Successfully tagged builderimage:latest
```

コンテナイメージが作成されたことの確認

```
[root@localhost ch09-builderimage]# docker images builderimage
REPOSITORY          TAG                ```
 IMAGE ID            CREATED             SIZE
builderimage        latest              e6de206bc533        3 minutes ago       430MB
```

S2Iでbuilderimageからアプリケーションコンテナのイメージを作成する。

```
[root@localhost openshift]# ./s2i build https://github.com/43books/ch09-apps.git builderimage:latest appimage:latest
---> Installing application source...
Build completed successfully
```

アプリケーションコンテナの起動

```
[root@localhost openshift]# docker run -d -t -p 8080:8080 appimage:latest
9c2f66fc986fd6911a2d56cf65d55d1db466b67551591399962984b22dfde310
```


起動確認

```
[root@localhost openshift]# curl http://localhost:8080/index.html
Hello World!
```

OpenShift上でのアドレス確認

```
C:\Users\gtoru\OpenShift>oc login -u system:admin
Logged into "https://192.168.99.100:8443" as "system:admin" using existing credentials.

You have access to the following projects and can switch between them with 'oc project <projectname>':

    default
    kube-dns
    kube-proxy
    kube-public
    kube-system
  * myproject
    openshift
    openshift-apiserver
    openshift-controller-manager
    openshift-core-operators
    openshift-infra
    openshift-node
    openshift-web-console

Using project "myproject".

C:\Users\gtoru\OpenShift>oc get svc docker-registry -n default
NAME              TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)    AGE
docker-registry   ClusterIP   172.30.1.1   <none>        5000/TCP   45d
```

builderイメージをOpenShift上のDocker Registryへ登録する。

```
C:\Users\gtoru\OpenShift>oc login -u developer
Logged into "https://192.168.99.100:8443" as "developer" using existing credentials.

You have one project on this server: "myproject"

Using project "myproject".

C:\Users\gtoru\OpenShift>oc new-project chapter09
Now using project "chapter09" on server "https://192.168.99.100:8443".

You can add applications to this project with the 'new-app' command. For example, try:

    oc new-app centos/ruby-22-centos7~https://github.com/openshift/ruby-ex.git

to build a new example application in Ruby.
```

ログインユーザのセッショントークンを取得する。

```
C:\Users\gtoru\OpenShift>oc whoami -t
gbHq0WJdXmGvpToBYm9AauzdtxAEC79E5_Lk1EFP7O4
```

Dockerレジストリにログインする。（別窓でminishift ssh経由で）

```
[docker@minishift ~]$ docker login -u developer -p gbHq0WJdXmGvpToBYm9AauzdtxAEC79E5_Lk1EFP7O4 172.30.1.1:5000
Login Succeeded
```