要求を満たすために構築方法を調査する。
要求
- 簡単に構築できる
- selenium grid環境
- ローカルマシン内で完結
- Infrastructure as code
- 軽い
1. docker hostを構築 @ Virtualbox
-
docker for macをインストール
docker-machineコマンドなどももつかえるようになった
-
dockerのホストサーバ作成
dockerホストサーバ作成$ docker-machine create --driver virtualbox default
【引数の説明】
- create : ホストOSを作成
- --driver : どこでつくるか (vitrualbox/amazonec2を指定する)
- default : サーバ名
作成されたことを確認$ docker-machine ls NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS default * virtualbox Running tcp://192.168.99.100:2376 v17.03.0-ce
-
dockerホストとして使うマシンをdefaultという名前のVMに設定する。
$ eval "$(docker-machine env default)"
-
docker seleniumをpull
$ docker pull elgalu/selenium #upgrades to latest if a newer version is available
-
docker run
$ docker run -d --name=grid -p 4444:24444 -p 5900:25900 \ -e TZ="Asia/Tokyo" --shm-size=1g elgalu/selenium 4394cb095f13ca6b09f7a037704d5e5210af8a96897ba74ee14da34a13c1073e
$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4394cb095f13 elgalu/selenium "entry.sh" 7 minutes ago Up 7 minutes 0.0.0.0:4444->24444/tcp, 0.0.0.0:5900->25900/tcp grid
-
テスト前にseleniumの設定確認(推奨)
bashdocker exec grid wait_all_done 30s Waiting for docker-selenium to be ready... Container docker internal IP: 172.17.0.2 Note if you are in Mac (OSX) 'boot2docker ip' or 'docker-machine ip default' will tell you the relevant IP Selenium all done and ready for testing!
-
grid console確認
dockerホストサーバのIP確認$ docker-machine ip default
-
停止
$ docker exec grid stop
-
vncの設定も含めてdocker run
$ docker run -d --name=grid -p 4444:24444 -p 5900:25900 \ --shm-size=1g -e VNC_PASSWORD=hola \ elgalu/selenium $ docker exec grid wait_all_done 10s Waiting for docker-selenium to be ready... Container docker internal IP: 172.17.0.2 Note if you are in Mac (OSX) 'boot2docker ip' or 'docker-machine ip default' will tell you the relevant IP Selenium all done and ready for testing! $ open vnc://:hola@192.168.88.199:5900
2. docker hostを構築 @ AWS EC2
-
aws cli インストール & aws configure作成
aws_configure$ aws configure AWS Access Key ID [None]: ******************** AWS Secret Access Key [None]: ***************************************** Default region name [None]: ap-northeast-1 Default output format [None]:
-
docker host作成
$ docker-machine create --driver amazonec2 --amazonec2-region ap-northeast-1 --amazonec2-vpc-id vpc-******** docker-test Running pre-create checks... Creating machine... (docker-test) Launching instance... Waiting for machine to be running, this may take a few minutes... Detecting operating system of created instance... Waiting for SSH to be available... Detecting the provisioner... Provisioning with ubuntu(systemd)... Installing Docker... Copying certs to the local machine directory... Copying certs to the remote machine... Setting Docker configuration on the remote daemon... Checking connection to Docker... Docker is up and running! To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env docker-test
-
docker-machine envに設定
$ eval "$(docker-machine env docker-test)"
-
docker run
$ docker run -d --name=grid -p 4444:24444 -p 5900:25900 \ -e TZ="Asia/Tokyo" --shm-size=1g elgalu/selenium
-
grid consoleで確認
security group に4444の穴を開ける必要がある -
docker stop & docker host stop
$ % docker stop grid grid $ docker-machine stop docker-test Stopping "docker-test"... Machine "docker-test" was stopped.
参考リンク
-
scaleするのに良さそう。
https://github.com/zalando/zaleniumA Selenium Grid extension to scale up and down your local grid dynamically with docker containers. It uses docker-selenium to run your tests in Firefox and Chrome locally, and when you need a different browser, your tests get redirected to Sauce Labs and/or BrowserStack and/or TestingBot.