星期四, 10月 27, 2016

docker swarm mode with openSUSE Leap 42.1 建立小記

Docker swarm mode with openSUSE Leap 42.1

OS: openSUSE Leap 42.1

3 個 node
  • 1 個 manager node
  • 2 個 worker node

# docker  --version
Docker version 1.12.1, build 8eab29e

在 Manager node 上面

初始化 swarm, 如果有多張網卡就要使用 --advertise-add 指定 IP
# docker   swarm   init   --advertise-addr   192.168.100.254
Swarm initialized: current node (bhmgljncagkfzsnhob3d9ricd) is now a manager.

To add a worker to this swarm, run the following command:

   docker swarm join \
   --token SWMTKN-1-5iju0vxuje0wkczh52qdwa73k0xq3s6jd8coql0wrlogo57l5c-8nl9nbnxs192kgu09kotylwd8 \
   192.168.100.254:2377

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

使用 docker  info 觀察 Swarm 啟動狀況
# docker   info  |   grep  Swarm
Swarm: active

檢查 node 資訊
# docker  node   ls
ID                           HOSTNAME  STATUS  AVAILABILITY  MANAGER STATUS
bhmgljncagkfzsnhob3d9ricd *  docker1   Ready   Active        Leader


在所有 worker node 上面
加入 swarm,
使用 剛剛 docker swarm init 顯示出來的資訊加入 ,或是使用 #docker swarm join-token work 查詢

# docker   swarm   join \
  --token  SWMTKN-1-5iju0vxuje0wkczh52qdwa73k0xq3s6jd8coql0wrlogo57l5c-8nl9nbnxs192kgu09kotylwd8 \
 192.168.100.254:2377


在 Manager node 上面

檢查相關資訊
# docker   node  ls
ID                           HOSTNAME  STATUS  AVAILABILITY  MANAGER STATUS
8268xbtnb28i9sy2tbkwlz7i0    docker2   Ready   Active        
bhmgljncagkfzsnhob3d9ricd *  docker1   Ready   Active        Leader
ezwivow6sctk9wiit19g89fz7    docker3   Ready   Active  


到此 swarm mode  佈署成功

建立測試服務



參考文件



星期四, 10月 13, 2016

Docker Swarm 移除小記

OS: openSUSE Leap 42.1


之前的測試環境用的是測試版本的 repo, 目前官方已經到 1.12.1 所以就想進行重新安裝
重新安裝前, 先記下移除 swarm mode 相關程序


Docker 版本
# docker --version
Docker version 1.13.0-dev, build dcdf2b4


使用的來源
# zypper   repos  -E
#  | Alias                                  | Name                                                                            | Enabled | GPG Check | Refresh
---+----------------------------------------+---------------------------------------------------------------------------------+---------+-----------+--------
1 | Virtualization_containers_experimental | Docker Experimental Packages (openSUSE_Leap_42.1)                               | Yes     | (r ) Yes  | Yes

目前的測試環境是 3 個 nodes
先使用 docker  node ls 來列出所有的 node


# docker   node  ls
ID                           HOSTNAME  STATUS  AVAILABILITY  MANAGER STATUS
71llz5z3q8f390s9l47qeypue    docker2   Ready   Active        
91ilfph3oq77e1jfwfzm1hm3g    docker3   Ready   Active        
bvbah38n6vusy7nilnbcve22w *  docker1   Ready   Active        Leader


因為要重新安裝, 所以就把上面的服務都移除了
# docker  service  ls
ID  NAME  REPLICAS  IMAGE  COMMAND

參考官方移除的程序


移除所有 work node
以我的環境來說, 我有兩個 work nodes, 一個 manager node


首先到 work node 上面進行 node 移除動作
使用 docker  swarm  leave 指令移除 node


# docker   swarm   leave
Node left the swarm.


回到 manager node 上面觀察
會發現 Availability 為 Down


# docker node ls
ID                           HOSTNAME  STATUS  AVAILABILITY  MANAGER STATUS
71llz5z3q8f390s9l47qeypue    docker2   Ready   Active        
91ilfph3oq77e1jfwfzm1hm3g    docker3   Down    Active        
bvbah38n6vusy7nilnbcve22w *  docker1   Ready   Active        Leader


# docker   node  rm  docker3
docker3

觀察結果
# docker   node   ls
ID                           HOSTNAME  STATUS  AVAILABILITY  MANAGER STATUS
71llz5z3q8f390s9l47qeypue    docker2   Ready   Active        
bvbah38n6vusy7nilnbcve22w *  docker1   Ready   Active        Leader


在執行 docker  rm 的時候, node 必須狀態為 Down 才可以移除, 否則就會出現警告並不能執行


# docker   node  rm  docker2
Error response from daemon: rpc error: code = 9 desc = node 71llz5z3q8f390s9l47qeypue is not down and can't be removed


接下來到 所有的 work node 離開 swarm mode
並進行 docker  node  rm


回到 manager node
目前只剩下 manager node
# docker  node  ls
ID                           HOSTNAME  STATUS  AVAILABILITY  MANAGER STATUS
bvbah38n6vusy7nilnbcve22w *  docker1   Ready   Active        Leader


觀察目錄
# du  -sh   /var/lib/docker/swarm/raft/
123M /var/lib/docker/swarm/raft/


使用 docker swarm leave 指令離開, 因為是 manager node 所以會被提示使用 --force
# docker  swarm  leave
Error response from daemon: You are attempting to leave the swarm on a node that is participating as a manager. Removing the last manager erases all current state of the swarm. Use `--force` to ignore this message.

# docker  swarm  leave  --force
Node left the swarm.


再次觀察
# du  -sh  /var/lib/docker/swarm/
4.0K /var/lib/docker/swarm/


到這邊就可以了
接下來就是在各個 node 移除實驗的 repos, 以及移除 docker 套件重新安裝


# zypper   -n   remove    docker


# yast2   repositories


:)


先記下來


~ enjoy it


參考文件

星期六, 9月 24, 2016

Open Build Service 實作練習 Workshop 101 小記

Open Build Service 實作練習 Workshop 101

OS: openSUSE Leap 42.1

預先準備
  • 安裝 osc 套件
    • #zypper   install   osc
  • 有 OBS 帳號

首先設定 API 的 URL
# osc    -A   https://api.opensuse.org

Your user account / password are not configured yet.
You will be asked for them below, and they will be stored in
/root/.oscrc for future use.

Creating osc configuration file /root/.oscrc ...
Username: 輸入帳號
Password: 輸入密碼

建立完之後家目錄會產生  .oscrc  以及 .osc_cookiejar
  • ~/.oscrc 為相關apiurl 以及帳號資訊, 檔案權限為 600, 後續可以用 ring 來處理


使用 osc 指令進行 check out 專案  osc  co   home:使用者帳號
# osc  co  home:sakana

觀察目錄就會出現專案的資料夾
# ls
.bash_history  .dbus        inst-sys        .oscrc    .Xauthority bin            .gnupg       .local          .rnd
.config        home:sakana  .osc_cookiejar  .viminfo

切換到專案目錄
# cd   home\:sakana/

使用 osc mkpac 指令建立 package, 這次workshop 使用的是  ctris
# osc  mkpac   ctris
A    ctris

再次觀察
# ls
ctris  gmchess  Helloworld-test  jUploadr  .osc  owncloud
進入 套件工作目錄
# cd   ctris/

修改 .spec 檔案, 可以參考講師提供的  http://paste.opensuse.org/8035d628
# vi  ctris.spec

Name:           ctris
Summary:        Console based Tetris clone
URL:            http://www.hackl.dhs.org/ctris/
License:        GPL-2.0
Group:          Amusements/Games/Action/Arcade
Version:        0.42
Release:        1
Source:         %{name}-%{version}.tar.bz2
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
BuildRequires:  ncurses-devel
Requires:       ncurses

%description
An ASCII version of the well known game Tetris

%prep
%setup -q

%build
make

%install
%make_install
%debug_package

%clean
rm -rf $RPM_BUILD_ROOT;

%files
%defattr(-,root,root)
%doc AUTHORS COPYING README TODO
%doc %{_mandir}/man6/ctris.6.gz
/usr/games/ctris

%changelog

Notes
  • 在 openSUSE 環境內 #vi  xxxx.spec 會自動套入 .spec 格式
  • BuildRequires 為編譯過程中需要的套件
  • Requires 則為執行需要的套件

抓取套件  source code
# wget  http://goo.gl/zWJXyd -O ctris-0.42.tar.bz2

觀察目錄
# ls
ctris-0.42.tar.bz2  ctris.spec  .osc

觀察.osc 目錄
# ls   .osc/
_apiurl  _files  _osclib_version  _package  _project

使用 osc   vc 指令填寫 chang log
# osc  vc

填入 change log
-------------------------------------------------------------------
Sat Sep 24 07:11:09 UTC 2016 -

- OBS workshop

# ls
ctris-0.42.tar.bz2  ctris.changes  ctris.spec  .osc

觀察目錄
# ls .osc/
_apiurl  _files  _osclib_version  _package  _project

標記要新增或是移除的檔案
# osc   addremove
A    ctris.spec
A    ctris.changes
A    ctris-0.42.tar.bz2

觀察目錄, 多了 _to_be_added
# ls .osc/
_apiurl  _files  _osclib_version  _package  _project  _to_be_added

# cat  .osc/_to_be_added
ctris.spec
ctris.changes
ctris-0.42.tar.bz2

到目前為止都是在 local

接下來進行 commit ( -ci ) 以及上傳到 build.opensuse.org
# osc   ci    -m  "Ya! I am a packager"
Sending meta data...
Done.
Sending    ctris
Sending    ctris/ctris.spec
Sending    ctris/ctris.changes
Sending    ctris/ctris-0.42.tar.bz2
Transmitting file data ..
Committed revision 1.
觀察目錄
# ls .osc/
_apiurl  ctris-0.42.tar.bz2  ctris.changes  ctris.spec  _files  _meta  _osclib_version  _package  _project

接下來要設定套件要編譯的 Repositories ( OS )

到 Web UI
點選  Repositories
點選  Add repositories

螢幕快照 2016-09-24 下午3.18.41.png


針對要加入的 repo 勾選
勾選完之後就會自動 build

螢幕快照 2016-09-24 下午3.24.30.png


到此, 就可以在 OBS 上面享受用一個原始碼編譯出不同平台的便利性
也可以到 http://software.opensuse.org/search 搜尋一下自己的套件觀察 :)
2016-09-24 22-16-56 的螢幕擷圖.png


剛剛是在  build.opensuse.org 上面編譯
那如果要在本機編譯呢?

本地端 編譯  ( 要配合自己有裝的 repo )
可以使用 osc  build 指令 後面加上 repo 以及架構 還有 .spec 檔案
# osc  build  openSUSE_Leap_42.1   x86_64   ctris.spec
Building ctris.spec for openSUSE_Leap_42.1/x86_64
Getting buildinfo from server and store to /root/home:sakana/ctris/.osc/_buildinfo-openSUSE_Leap_42.1-x86_64.xml
Getting buildconfig from server and store to /root/home:sakana/ctris/.osc/_buildconfig-openSUSE_Leap_42.1-x86_64
Updating cache of required packages

The build root needs packages from project 'openSUSE:Leap:42.1'.
Note that malicious packages can compromise the build result or even your system.
Would you like to ...
0 - quit (default)
1 - always trust packages from 'openSUSE:Leap:42.1'
2 - trust packages just this time
? 1
adding 'openSUSE:Leap:42.1' to ~/.oscrc: ['https://api.opensuse.org']['trusted_prj']
100.0% cache miss. 0/100 dependencies cached.

[   34s] RPMLINT report:
[   34s] ===============
[   35s] ctris.x86_64: W: incorrect-fsf-address /usr/share/doc/packages/ctris/COPYING
[   35s] The Free Software Foundation address in this file seems to be outdated or
[   35s] misspelled.  Ask upstream to update the address, or if this is a license file,
[   35s] possibly the entire file with a new copy available from the FSF.
[   35s]
[   35s] ctris.x86_64: W: file-contains-current-date /usr/games/ctris
[   35s] Your file contains the current date, this may cause the package to rebuild in
[   35s] excess.
[   35s]
[   35s] 2 packages and 0 specfiles checked; 0 errors, 2 warnings.
[   35s]
[   35s]
[   35s] template finished "build ctris.spec" at Sat Sep 24 07:38:00 UTC 2016.
[   35s]

/var/tmp/build-root/openSUSE_Leap_42.1-x86_64/home/abuild/rpmbuild/SRPMS/ctris-0.42-1.src.rpm

/var/tmp/build-root/openSUSE_Leap_42.1-x86_64/home/abuild/rpmbuild/RPMS/x86_64/ctris-0.42-1.x86_64.rpm
/var/tmp/build-root/openSUSE_Leap_42.1-x86_64/home/abuild/rpmbuild/RPMS/x86_64/ctris-debuginfo-0.42-1.x86_64.rpm

這邊會看到, 編譯完成之後會放到 /var/tmp 下面的目錄


Lab: 共同協作

那如果想要跟其他人共同維護套件呢?

範例 使用現有的套件

使用 osc  branch 指令建立分支, 這邊是使用講師的 套件
# osc   branch   home:gary_lin   ctris

# cd

切換到工作目錄
# osc   co   home:sakana:branches:home:gary_lin/ctris
A    home:sakana:branches:home:gary_lin
A    home:sakana:branches:home:gary_lin/ctris
A    home:sakana:branches:home:gary_lin/ctris/ctris-0.42.tar.bz2
A    home:sakana:branches:home:gary_lin/ctris/ctris.changes
A    home:sakana:branches:home:gary_lin/ctris/ctris.spec
At revision e1fa18eaa16d59e32af37e7b02af3130.

觀察目錄
# ls
.bash_history  bin  .config  .dbus  .gnupg  home:sakana  home:sakana:branches:home:gary_lin  inst-sys  .local  .osc_cookiejar  .oscrc  .rnd  .viminfo

由於只是 workshop 所以先切換到該套件的工作目錄
# cd   home\:sakana\:branches\:home\:gary_lin/ctris/

測試改動 .spec 內容 ( 這邊我改了 release 版本 )
# vim  ctris.spec

填入 change log
# osc   vc

標記新增或是移除檔案
# osc  addremove

進行 build 動作
$ osc  build  openSUSE_Leap_42.1   x86_64

進行  commit, 此時都是在自己的 home project 上面
$ osc   ci   -m   “another change”

可以到 Subprojects 查詢
螢幕快照 2016-09-24 下午4.23.20.png


透過  osc  submitreq 送出更動請求 ( 像是git 的 pull request )
# osc   submitreq
created request id 429914

這樣就可以完成 協同工作

今天的  workshop 真是收穫良多
謝謝 Gary

~ enjoy it