Skip to content

Commit

Permalink
New: "docker-workshop-registry" box with pre-loaded images
Browse files Browse the repository at this point in the history
Purpose: to decrease students' image download time and possible errors.
  • Loading branch information
William-Yeh committed Mar 9, 2015
1 parent adea18b commit 9181994
Show file tree
Hide file tree
Showing 13 changed files with 279 additions and 74 deletions.
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -25,6 +25,11 @@ Read the documents:
## History


**v3.0** / 第三梯次 (2015-04-11)

- 簡化 Vagrant 環境設定程序。


**v2.0** / 第二梯次 (2015-03-07)

- 更新至 Docker 1.5.0。
Expand Down
23 changes: 3 additions & 20 deletions Vagrantfile
Expand Up @@ -3,14 +3,11 @@ Vagrant.require_version ">= 1.7.2"
# change default synced_folder for convenience
SYNCED_FOLDER = "/home/vagrant/docker-workshop"

# image list
IMAGE_LIST = File.join(SYNCED_FOLDER, "provision/IMAGE-LIST")

# expose ports from guest to host for convenience
FORWARDED_PORT_RANGE = 10080..10100

# external provision script files
PROVISION_SCRIPTS = [ "provision/setup-docker-tools.sh", "provision/setup-env.sh" ]
PROVISION_SCRIPTS = [ "provision/setup-docker-tools.sh", "provision/setup-env.sh", "provision/setup-hosts.sh" ]


Vagrant.configure(2) do |config|
Expand All @@ -21,9 +18,6 @@ Vagrant.configure(2) do |config|
node.vm.box_version = ">= 1.5.0"

node.vm.network "private_network", ip: "10.0.0.10"
node.vm.provision "hosts" do |hosts|
hosts.add_host '10.0.0.200', ['registry.com', 'registry']
end

for i in FORWARDED_PORT_RANGE
node.vm.network "forwarded_port", guest: i, host: i
Expand All @@ -49,9 +43,6 @@ Vagrant.configure(2) do |config|
node.vm.box_version = ">= 1.5.0"

node.vm.network "private_network", ip: "10.0.0.11"
node.vm.provision "hosts" do |hosts|
hosts.add_host '10.0.0.200', ['registry.com', 'registry']
end

node.vm.synced_folder ".", SYNCED_FOLDER

Expand All @@ -68,9 +59,6 @@ Vagrant.configure(2) do |config|
node.vm.box_version = ">= 1.5.0"

node.vm.network "private_network", ip: "10.0.0.12"
node.vm.provision "hosts" do |hosts|
hosts.add_host '10.0.0.200', ['registry.com', 'registry']
end

node.vm.synced_folder ".", SYNCED_FOLDER

Expand Down Expand Up @@ -99,21 +87,16 @@ Vagrant.configure(2) do |config|

config.vm.define "registry" do |node|

node.vm.box = "williamyeh/insecure-registry"
node.vm.box_version = ">= 1.5.0"
node.vm.box = "williamyeh/docker-workshop-registry"
node.vm.box_version = ">= 3.0.0"

node.vm.network "private_network", ip: "10.0.0.200"
node.vm.provision "hosts" do |hosts|
hosts.add_host '10.0.0.200', ['registry.com', 'registry']
end

node.vm.synced_folder ".", SYNCED_FOLDER

for f in PROVISION_SCRIPTS
node.vm.provision "shell", path: f
end
node.vm.provision "shell",
inline: "PRIVATE_DOCKER_REGISTRY=registry.com docker-mirror " + IMAGE_LIST

end

Expand Down
86 changes: 38 additions & 48 deletions config.md
@@ -1,16 +1,30 @@
行前準備 Part 2:預載範例程式碼
===

[ <-- Prev: [行前準備 Part 1](prepare.md) ]


為了節省課程現場下載程式及相關資源的時間及頻寬,請學員先在**網路暢通的地方**,根據指示備妥必要的軟體及設定。

如果網路順暢,整個過程可能會花上數十分鐘,請耐心等候。
整個過程可能會花上數十分鐘,請耐心等候。
整個過程可能會花上數十分鐘,請耐心等候。
整個過程可能會花上數十分鐘,請耐心等候。
(因為很重要,所以要說三次。)

&nbsp;

☛ 程式範例會在每一梯次開課前一週才定案,因此,建議**等開課前一週再進行下列步驟**
☛ 注意事項:

- 程式範例會在每一梯次開課前一週才定案,因此,建議**等開課前一週再進行下列步驟**

- 進行以下步驟之前,請先確定 VirtualBox 之【預設機器資料夾】所在的磁碟上,仍有足夠空間,以容納各虛擬機內容及預載之 Docker 映像檔。建議至少要預留 15 GB:
![預留 VirtualBox 虛擬機所需空間](img/vbox-diskspace.png)

☛ 進行以下步驟之前,請先確定 VirtualBox 之【預設機器資料夾】所在的磁碟上,仍有足夠空間,以容納各虛擬機內容及預載之 Docker 映像檔。建議至少要預留 15 GB:
![預留 VirtualBox 虛擬機所需空間](img/vbox-diskspace.png)
- 進行以下步驟之前,建議您先關閉(甚至解除安裝)可能與 VirtualBox 相衝的其他虛擬機軟體。譬如說,以下命令可暫時關閉 Hyper-V(還需要你手動重新開機,才會生效):

```
bcdedit /set hypervisorlaunchtype off
```


&nbsp;
Expand All @@ -29,9 +43,7 @@

### 步驟二:開啟終端機,以進行後續步驟

Linux 使用者:請使用 xterm 或任何你慣用的終端機軟體。

Mac 使用者:請使用終端機 (Terminal)、iTerm 或任何你慣用的終端機軟體。
Linux 及 Mac 使用者:請使用 xterm、終端機 (Terminal)、iTerm 或任何你慣用的終端機軟體。

Windows 使用者:

Expand All @@ -43,7 +55,7 @@ Windows 使用者:

### 步驟三:下載 workshop 範例程式

請先切換到你選定的工作目錄,譬如:
請先切換到你選定的工作目錄(Windows 用戶,請避免選用「含中文字」),譬如:

```shell
cd YOUR_OWN_WORKING_DIRECTORY
Expand All @@ -63,35 +75,18 @@ Windows 使用者:
cd docker-workshop
```

#### ⇡ 以上所列的幾個步驟,如有不清楚的,請見示範錄影:

[![Docker Workshop - How to Fork Project](http://img.youtube.com/vi/n2ogtWHZRzo/0.jpg)](http://youtu.be/n2ogtWHZRzo)

---
<br/>

#### ⇣ 以下所列的幾個步驟,如有不清楚的,請見示範錄影:
這個目錄,課堂上會反覆用到。建議你設桌面捷徑,以節省切換目錄的時間。

[![Docker Workshop - How to Setup Lab Environment](http://img.youtube.com/vi/0aaMQ8u9Dvg/0.jpg)](http://youtu.be/0aaMQ8u9Dvg)

#### ⇡ 以上所列的幾個步驟,如有不清楚的,請見示範錄影:


### 步驟五:安裝必要的 Vagrant 擴充套件

➤ 錄影 0:00~01:16 片段。

```shell
vagrant plugin install vagrant-hosts
vagrant plugin install vagrant-vbox-snapshot
```
[![Docker Workshop - How to Fork Project](http://img.youtube.com/vi/n2ogtWHZRzo/0.jpg)](http://youtu.be/n2ogtWHZRzo)


### 步驟六:初始化 Vagrant 虛擬機
### 步驟五:初始化 Vagrant 虛擬機

耗時最久的,就是這個步驟,請耐心等候。

➤ 錄影 01:23~57:25 片段。

- 如果你的電腦是 Mac 或 Linux,請輸入:

```shell
Expand All @@ -105,31 +100,26 @@ vagrant plugin install vagrant-vbox-snapshot
```


### 步驟七:快照 (snapshot)

➤ 錄影 57:38~58:42 片段。
### 步驟六:確認已設定完畢

先替這一批 snapshot 取個易於辨識追溯的名稱,建議以現在時間 *mm/dd-HH:MM* 為名。

假設現在時間是 `02/19-08:00` (Feb 19, 08:00),請輸入以下指令:
輸入以下指令,查看各虛擬機的狀態:

```shell
vagrant snapshot take main 02/19-08:00
vagrant snapshot take alice 02/19-08:00
vagrant snapshot take bob 02/19-08:00
vagrant snapshot take centos 02/19-08:00
vagrant snapshot take registry 02/19-08:00
vagrant status
```

如果看到以下畫面,五台虛擬機都呈現 "poweroff" 狀態,就表示已經順利設定完畢:

### 步驟八:確認 snapshot 已完成
```
Current machine states:
➤ 錄影 59:08~片尾。
main poweroff (virtualbox)
alice poweroff (virtualbox)
bob poweroff (virtualbox)
centos poweroff (virtualbox)
registry poweroff (virtualbox)
```shell
vagrant snapshot list main
vagrant snapshot list alice
vagrant snapshot list bob
vagrant snapshot list centos
vagrant snapshot list registry
This environment represents multiple VMs. The VMs are all listed
above with their current state. For more information about a specific
VM, run `vagrant status NAME`.
```
File renamed without changes.
37 changes: 37 additions & 0 deletions make-registry-box/README.md
@@ -0,0 +1,37 @@
Building a Docker Registry box with pre-loaded images
===


## Name

Official box name in Atlas (was: Vagrant Cloud): [`williamyeh/docker-workshop-registry`](https://atlas.hashicorp.com/williamyeh/boxes/docker-workshop-registry).



## Purpose

To build a Vagrant box, which:

- derives from [`williamyeh/insecure-registry`](https://vagrantcloud.com/williamyeh/insecure-registry) box.
- pre-loads Docker images listed in the `IMAGE-LIST` file from Docker Hub.



## Build it on your own...

### Prerequisite

Install [`vagrant-hosts`](https://github.com/adrienthebo/vagrant-hosts) plugin:

```bash
vagrant plugin install vagrant-hosts
```

### Build!


```bash
$ ./build.sh
```

If everything is OK, you'll obtain a box file `docker-workshop-registry.box`. Feel free to place it on your local disk or cloud storage (Dropbox, S3, etc).
40 changes: 40 additions & 0 deletions make-registry-box/Vagrantfile
@@ -0,0 +1,40 @@
Vagrant.require_version ">= 1.7.2"


$script = <<PULL_SCRIPT
# download "docker-mirror" tool
curl -o /usr/local/bin/docker-mirror https://raw.githubusercontent.com/William-Yeh/docker-host-tools/master/docker-mirror
chmod a+x /usr/local/bin/*
# start the "docker-registry" app
service docker-registry start
# pull images from Docker Hub
PRIVATE_DOCKER_REGISTRY=registry.com docker-mirror /vagrant/IMAGE-LIST
PULL_SCRIPT



Vagrant.configure(2) do |config|

config.vm.box = "williamyeh/ubuntu-trusty64-docker"
config.vm.box_version = ">= 1.5.0"

# avoid possible request "vagrant@127.0.0.1's password:" when "up" and "ssh"
config.ssh.password = "vagrant"


config.vm.provision "hosts" do |hosts|
hosts.add_host '127.0.0.1', ['registry.com']
end

config.vm.provision "shell", path: "install-registry-app.sh"

config.vm.provision "shell", inline: $script

config.vm.provision "shell", path: "cleanup.sh"

end
13 changes: 13 additions & 0 deletions make-registry-box/build.sh
@@ -0,0 +1,13 @@
#!/bin/bash

readonly BOX_FILE=docker-workshop-registry.box
#readonly BOX_FILE=output.box


vagrant halt
vagrant destroy --force

vagrant up
vagrant package --output $BOX_FILE

vagrant destroy --force
32 changes: 32 additions & 0 deletions make-registry-box/cleanup.sh
@@ -0,0 +1,32 @@
#!/bin/bash

# clean up docker's execution trace
sudo docker kill docker-registry
sudo docker rm `sudo docker ps --no-trunc -a -q`

# clean "registry.com" host entry
sed -i -e \
's/^.*registry.com$//' \
/etc/hosts


sudo rm -f \
/var/log/messages \
/var/log/lastlog \
/var/log/auth.log \
/var/log/syslog \
/var/log/daemon.log \
/var/log/docker.log


#---------------------------------------#
# Vagrant-specific settings below
#


# zero out the free space to save space in the final image
sudo dd if=/dev/zero of=/EMPTY bs=1M
sudo rm -f /EMPTY


rm -f /home/vagrant/.bash_history /var/mail/vagrant

0 comments on commit 9181994

Please sign in to comment.