Apr 5th, 2021


AWS CodeCommit 使用小記
AWS CodeCommit 使用小記
OS: openSUSE Leap 15.2
git: 2.26.2
最近因為使用 GitLab 的關係, 所以有些資料原本是使用 share folder 的方式, 現在也會考慮使用 git 的方式儲存.
今天來寫 AWS CodeCommit 的使用紀錄
目前使用的方式是參考
官方文件 在 Linux, MacOS, or Unix 上設定CodeCommit
Youtube Video
Introduction to AWS CodeCommit: Setting Up Permissions https://youtu.be/W-SM4m19JMA
Introduction to AWS CodeCommit: Creating a Repo https://youtu.be/SWqh7LvxKqI
連接 AWS CodeCommit 有很多方式, 我是採取 SSH Key 的方式, 網路上有人反應這樣的做法比較穩妥, 比較不會出現奇怪的現象.
實作的方式
建立 IAM Group, 綁定相關權限, 將使用者加入到 Group
這邊的 Policy 我使用的的是 AWSCodeCommitPowerUser, 他與 AWSCodeCommitFullAccess 差異主要就是可否刪除儲存庫, 相關細節可以參考 https://docs.aws.amazon.com/zh_tw/codecommit/latest/userguide/auth-and-access-control-iam-identity-based-access-control.html
將使用者的 SSH Public Key 上傳到 IAM 使用者的 SSH Keys for AWS CodeCommit
設定 ~/.ssh/config 檔案, 指定 User ID 與相關檔案
建立 CodeCommit Repository, 使用 git clone 測試操作
接下來就讓我們開始吧
首先登入 AWS IAM console
點選左方的 Groups -- > 點選 Create New Group
群組名稱輸入: CodeCommitPowerUser -- > 點選 Next Step
在 Attach Policy 頁面
搜尋 CodeCommit -- > 勾選 AWSCodeCommitPowerUser
點選 Next Step
檢閱相關設定
點選 Create Group
接下來加入使用者
點選剛剛建立的 CodeCommitPowerUser 群組
在 Users 頁籤 -- > 點選 Add Users to Group
勾選要加入的使用者 -- > Add Users
接下來要將使用者的 SSH Public Key 上傳到 IAM 使用者的 SSH Keys for AWS CodeCommit
點選 IAM console 左方的 Users
點選 剛剛被加入的使用者
點選 Security credentials 頁籤
點選 Upload SSH public key 按鈕
將 SSH 公鑰貼上
點選 Upload SSH public Key
如果沒有已經存在的 SSH Key, 或是想要額外建立 Key 可以參考官方文件的方式建立
將 SSH key ID 記錄下來, 等等這個 ID 就是 SSH User ID
再來建立 ~/.ssh/config
使用自己習慣的編輯器 建立 ~/.ssh/config 檔案, 內容如下
User 後面那串字元, 請換成之前的 SSH key ID
IdentityFile 請換成 自己的 SSH Private Key, 如 id_rsa
將 ~/.ssh/config 檔案設定相關權限
> chmod 600 ~/.ssh/config
最後階段, 建立 CodeCommit Repository, 使用 git clone 測試操作
登入 AWS CodeCommit 主控台 https://console.aws.amazon.com/codesuite/codecommit/home
CodeCommit 也是 Region 服務, 所以可以先選取你要建立的 Region, 我這邊的例子是使用 Ohio ( us-east-2 )
點選 Create repository
輸入 儲存庫名稱
點選 Create
建立完成之後, 其實會有不同的頁籤來說明如何連接
點選 SSH 頁籤
展開你要的 OS 選項, 我是用 openSUSE Leap 15.2 , 所以展開 Linux
點選 Step 4 的 Copy
他會複製 git clone ssh 的指令
接下來進行 git clone 的測試
切換到要進行 git clone 的目錄
貼上與執行剛剛複製的 git clone 指令
> git clone ssh://git-codecommit.us-east-2.amazonaws.com/v1/repos/test20210405
正複製到 'test20210405'...
warning: 您似乎複製了一個空版本庫。
進入到相關目錄
> cd test20210405/
接下來嘗試建立檔案進行 commit 測試
> echo "CodeCommit Test" > README.md
> git add .
> git commit -m "20210405"
[master (根提交) 6381ea1] 20210405
1 file changed, 1 insertion(+)
create mode 100644 README.md
> git push -u origin master
Warning: Permanently added the RSA host key for IP address '52.95.17.51' to the list of known hosts.
枚舉物件: 3, 完成.
物件計數中: 100% (3/3), 完成.
寫入物件中: 100% (3/3), 227 位元組 | 227.00 KiB/s, 完成.
總共 3 (差異 0),復用 0 (差異 0),重用包 0
To ssh://git-codecommit.us-east-2.amazonaws.com/v1/repos/test20210405
* [new branch] master -> master
分支 'master' 設定為追蹤來自 'origin' 的遠端分支 'master'。
回到 AWS CodeCommit 觀察
這樣又多了一個 git 存儲的去處, 也多向 AWS 服務邁向一步
~ enjoy it
Reference:


Rancher 2.5.7 with container in Azure 安裝小記
Rancher 2.5.7 with container in Azure 安裝小記
OS: openSUSE Leap 15.2 in Azure
Rancher: 2.5.7
今年又開始重拾 Kubernetes 的研讀, 之前就有注意 Rancher 的相關消息, 在 SUSE 正式併購 Rancher 之後, 就有打算找時間看看他
目前的想法就是研讀 K8S 的時候, 搭配他來看看, 因為是嘗試, 就從 single node with container 方式開始
安裝需求
https://rancher.com/docs/rancher/v2.x/en/installation/requirements/
以 single-node 方式, 規格是 1 vCPU 4GB RAM / 2 vCPU 8GB RAM, 換成 Azure Virtual Machine 的 Size 比較節費的就是 Standard_B2ms
使用 SSH 連入建立的 openSUSE Leap 15.2 in Azure
切換身份爲 root
> sudo su -
啟動 docker 服務, 並預設啟動
# systemctl start docker
# systemctl enable docker
叄考官方文件 啟用 rancher container
https://rancher.com/docs/rancher/v2.x/en/installation/other-installation-methods/single-node-docker/
因為是測試性質, 所以使用 docker 方式 A Docker installation of Rancher is recommended only for development and testing purposes.
For Rancher v2.5+, the Rancher backup operator can be used to migrate Rancher from the single Docker container install to an installation on a high-availability Kubernetes cluster. For details, refer to the documentation on migrating Rancher to a new cluster.
這樣看起來至少都要考慮 Rancher 2.5 以上的版本爲佳
啟動 Rancher
#docker run -d --restart=unless-stopped -p 80:80 -p 443:443 --privileged rancher/rancher:latest
然後在 Azure 的 網路安全性群組 開放 Port 443 與 Port 80
開啟瀏覽器 https://YOUR_IP:443
會看到歡迎畫面
輸入管理者 admin 的密碼
勾選同意協定 -- > Continue
設定 Rancher 的 URL
輸入相關 IP 或是 URL 後 -- > Save URL
接下來會看到歡迎畫面與 Rancher 2.5 的介紹視窗
這樣可以清楚的知道目前使用的是 Rancher 2.5 (笑)
觀察一下目前的歡迎畫面
右下角可以調整介面的語系, 可以調整成自己想要的語系
切換後的樣貌
我們來嘗試透過 Rancher 來建立 AKS Cluster 吧
點選 添加叢集
看的出來有支援很多種型態
這邊我點選 Azure AKS
接下來有看到設定畫面
在新增 Cluster 之前要先處理 Azure 上面 Service principals 的部分
我是使用 Azure 的 Cloud Shell 來進行
建議建立之前可以先使用下列指定觀察目前的 Service principals
$ az ad sp list --all --output table
根據官方文件建立 Service Principal
$ az ad sp create-for-rbac --skip-assignment --name testRancherServicePrincipal
這樣的方式顯示出來的欄位爲 appID / displayName / name / password / tenant
可是其實我們只需要的是 Subscription ID / Client ID / Tenant ID / Client Secret
補充: Client ID 就是 AppID, Client Secret 就是 password, 所以只差了 Subscription ID
所以決定把剛剛那個 Service Principal 先刪除了 ( 順便複習一下之前的 )
使用剛剛的指令加上 grep Rancher 找出剛剛的 Service Principal
$ az ad sp list --all --output table | grep Rancher
參考之前自己的文章
刪除剛剛建立的 Service Principal
$ az ad sp delete --id 8faa88b0-a540-4d8c-a790-1ca6a0522dsd
8faa88b0-a540-4d8c-a790-1ca6a0522dsd 爲剛剛建立的 AppId, 可以看第三欄位
建立 Service Principal
$ az ad sp create-for-rbac --name testRancherServicePrincipal-20210404 --query '{"client_id": appId, "secret": password, "Tenant_id": tenant}'
這邊有個雷點, 不可以加上 --skip-assignment 否則會遇到權限不足的問題, 會遇到錯誤訊息 access was recently granted, please refresh your credentials
這次的指令相比於之前自己文章的指令, 有加上 --name 的選項在裡面, 如果沒有使用 --name 指定名稱, 預設會是 azure-cli-20xx-xx-xx-xx-xx-xx, 這樣的好處是可以知道建立時間, 所以我的名稱也有加入時間進去, 以免以後不知道那個 SP 過期
加上 --query 的方式, 輸出自己要的資訊
接下來取得 Subscription ID
使用 az account 指令取得
$ az account show --query "{ subscription_id: id }"
{
"subscription_id": "6a2bdf3b-XXXX-XXXX-XXXX-3371d3401feb"
}
好的, 原料備齊, 回到 Rancher 填入資訊
點選 Next: Authenticate & configure nodes
再次提醒自己剛剛在建立 az ad sp 的時候不可以加上 --skip-assignment 否則會遇到權限不足的問題
驗證通過之後, 就是設定 Kubernetes 相關選項
版本我用他預設給的 1.19.7
填入 Resource Group 名稱
設定要使用的 VM 規格, 主機數量
貼上 SSH 公鑰
點選 創建
這個時候可以觀察相關狀態
建立需要一點時間, 可以同步觀察 Azure 上面的資源
建立完成, 可以在 Rancher 與 Azure 上面同步觀察
可以直接在網頁上面執行 kubectl
也可以下載 Kubeconfig
Azure 這邊則可以觀察到
有建立相關的 AKS 服務以及 Resource Group for AKS
最後來測試一個猛的, 刪除 cluster
點選剛剛建立的 Cluster 點選刪除
觀察了一下 Azure 那邊, Rancher 也很盡責的刪除剛剛建立的 AKS 與相關資源
小結一下: 目前看起來 Rancher UI 是很方便的, 所以日後可以多嘗試一下他的相關功能
也算是跨出 Rancher 的一小步了
~ enjoy it
Reference:
https://rancher.com/docs/rancher/v2.x/en/installation/requirements/
https://rancher.com/docs/rancher/v2.x/en/installation/other-installation-methods/single-node-docker/
https://docs.microsoft.com/en-us/azure/aks/kubernetes-service-principal
http://sakananote2.blogspot.com/2020/05/azure-dynamic-inventory-with-ansible.html


openSUSE Leap 15.2 以非互動方式註冊 GitLab runner with docker executor in Azure 小記
openSUSE Leap 15.2 以非互動方式註冊 GitLab runner with docker executor in Azure 小記
OS: openSUSE Leap 15.2 in Azure
GitLab: 使用 gitlab.com
上次的文章使用互動的方式註冊 gitlab-runner 然後是用 shell executor
今天要來實作以非互動的方式註冊 gitlab-runner 然後採取 docker 來當 executor
實作前提
在 gitlab.com 有帳號 ( 免費的就可以, 有付錢的功能更多 )
確認自己的 GitLab project / Group CI / CD Runner 設定與 Token
在 GitLab.com 登入自己帳號
在 Project / Group 內 的 Settings -- > CI / CD
展開 Runners 就會看到 Token
接下來開始建立實驗
建立 openSUSE Leap 15.2 in Azure
我是用 Cloud Shell in VS code 然後透過 ansible 建立
使用 zypper 新增 gitlab 的 repo
語法 zypper ar -f <URL> <alias>
# zypper ar -f https://download.opensuse.org/repositories/openSUSE:/infrastructure:/gitlab/openSUSE_Leap_15.2 gitlab
觀察相關資訊
# zypper lr
Repository priorities are without effect. All enabled repositories share the same priority.
# | Alias | Name | Enabled | GPG Check | Refresh
--+---------------------+-----------------------------+---------+-----------+--------
1 | gitlab | gitlab | Yes | ( p) Yes | Yes
2 | repo-debug | Debug Repository | Yes | ( p) Yes | Yes
3 | repo-debug-update | Update Repository (Debug) | Yes | ( p) Yes | Yes
4 | repo-non-oss | Non-OSS Repository | Yes | ( p) Yes | Yes
5 | repo-oss | Main Repository | Yes | ( p) Yes | Yes
6 | repo-source | Source Repository | Yes | ( p) Yes | Yes
7 | repo-update | Main Update Repository | Yes | ( p) Yes | Yes
8 | repo-update-non-oss | Update Repository (Non-Oss) | Yes | ( p) Yes | Yes
匯入 GPG Key 與 refresh repo
# zypper --gpg-auto-import-keys refresh
安裝 gitlab-runner
# zypper install -y gitlab-runner
啟動 docker 服務
# systemctl start docker
設定 docker 開機時啟動
# systemctl enable docker
使用 gitlab-runner register 搭配 --non-interactive 方式非互動註冊
# gitlab-runner register --non-interactive --url https://gitlab.com --registration-token YOUR_TOKEN --executor docker --docker-image opensuse/leap:latest --name test-gitlab-runner-docker --tag-list "opensuse-docker"
--url 與 --registration-token 請換成自己要註冊的 Server 與 token
--executor 指定 docker 方式 並指定預設的 docker image 爲 opensuse/leap:latest
--name 指定名稱
--tag-list 指定 tag
觀察相關資訊
# cat /etc/gitlab-runner/config.toml
concurrent = 1
check_interval = 0
[session_server]
session_timeout = 1800
[[runners]]
name = "test-gitlab-runner-docker"
url = "https://gitlab.com"
token = "5kYxjqvGPPy63Vus_W66K"
executor = "docker"
[runners.custom_build_dir]
[runners.cache]
[runners.cache.s3]
[runners.cache.gcs]
[runners.docker]
tls_verify = false
image = "opensuse/leap:latest"
privileged = false
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
volumes = ["/cache"]
pull_policy = "always"
shm_size = 0
這邊的 token 是 runner 的 token
啟動 gitlab-runner
# gitlab-runner start
觀察相關資訊
# gitlab-runner status
也可以到 Gitlab 上面觀察
又前進一步
下次預計來弄 ansible playbook :)
~ enjoy it
Reference:
https://gitlab.com/gitlab-org/gitlab-runner/-/issues/2811#note_49993634
http://sakananote2.blogspot.com/2021/02/opensuse-leap-152-as-gitlab-runner-in.html


openSUSE Leap 15.2 as GitLab runner in Azure 小記
openSUSE Leap 15.2 as GitLab runner in Azure 小記
OS: openSUSE Leap 15.2 in Azure
GitLab: 使用 gitlab.com
最近開始學 GitLab
先感謝 陳正瑋 的鐵人賽文章以及 和艦長一起30天玩轉 GitLab 書籍
入門多了很多的資訊
今天要來寫的是把 openSUSE Leap 15.2 當成 gitlab runner 來執行
爲何要寫這篇呢? 當然是因為官方的文件上沒有列出 openSUSE 安裝方式 :)
那就只好自己嘗試, 然後記錄下來了 (攤手)
實作前提
在 gitlab.com 有帳號 ( 免費的就可以, 有付錢的功能更多 )
確認自己的 GitLab project / Group CI / CD Runner 設定與 Token
在 GitLab.com 登入自己帳號
在 Project / Group 內 的 Settings -- > CI / CD
展開 Runners 就會看到 Token
接下來開始建立實驗
建立 openSUSE Leap 15.2 in Azure
我是用 Cloud Shell in VS code 然後透過 ansible 建立的 ~ 開心
回到 gitlab 身上來
如果在 software.opensuse.org 上面搜尋 gitlab-runner
這邊其實就有看到實驗性套件了
使用 ssh 連入剛剛的 openSUSE Leap 15.2 in Azure
使用 yast repositories 新增套件庫
#yast repositories
新增套件庫 (Alt + A)
方式選取 指定 URL
點選下一步 (Alt + N)
套件庫的名稱可以自行取
URL 的部分指定
點選下一步 (Alt + N)
有遇到 GnuPG Key 可以 Trust 一下
確認 GitLab 套件庫有被加入
點選 OK (Alt + O)
接下來新增相關套件
# zypper install gitlab-runner
Loading repository data...
Reading installed packages...
Resolving package dependencies...
The following 5 NEW packages are going to be installed:
dash gitlab-common gitlab-runner libruby2_6-2_6 ruby2.6
5 new packages to install.
Overall download size: 12.6 MiB. Already cached: 0 B. After the operation, additional 52.3
MiB will be used.
Continue? [y/n/v/...? shows all options] (y): y
註冊 gitlab-runner
# gitlab-runner register
輸入 Gitlab-runner token
輸入 這個 runner 的敘述
輸入 這個 runner 的 tag ( 這個很重要 )
輸入 這個 runner 的 executor ( 一般都是 docker or shell, 請見官方文件 )
啟動 gitlab-runner
# gitlab-runner start
Runtime platform arch=amd64 os=linux pid=3192 revision=1b659122 version=12.8.0
觀察相關資訊
# gitlab-runner status
Runtime platform arch=amd64 os=linux pid=3210 revision=1b659122 version=12.8.0
gitlab-runner: Service is running!
Notes:
Runner 的 config 會存放在 /etc/gitlab-runner/config.toml
要成為 gitlab-runner 也要安裝 git 不然執行會出現錯誤
執行的時候相關工作目錄會在 /srv/gitlab-runner/builds/GITLAB-RUNNER-TOKEN/ 下
在 GitLab.com 上面確認 runner 有設定成功
找時間要看的文件
Disable SKEL 說明
https://docs.gitlab.com/runner/install/linux-repository.html#disable-skel
Gitlab runner 安裝說明
https://docs.gitlab.com/runner/install/linux-repository.html
這樣算是又向 GitLab 前進一步了
~ enjoy it
Reference:


VS code Azure Account extension 小記
VS code Azure Account extension 小記
OS: openSUSE Leap 15.2
vscode: 1.52.1
Extension: Azure Account v0.9.5
今天要來寫 Azure Account extension in vscode
在很多實驗情境的時候, 可能會使用 vscode 來撰寫 shell script 或是 ansible playbook 來對雲端上面的機器進行實驗. 甚至是使用 Remote SSH 在雲端上面開發.
在 Azure 的使用上面, 我就常常使用到 Cloud Shell 來進行 ansible playbook 的佈署.
VS code 對我最亮眼的地方就是有一大推好用的 Extension.
今天要來寫的就是 Azure Account 這個 extension. 我主要用來在 vscode 內開啟 Bash 版本 Cloud Shell
安裝方式
開啟 vscode
點選左側 Extension 圖示, 搜尋 Azure 可以找到 Azure Account 這個 Extension
點選 Install 進行安裝
在 vscode 內 點選 View -- > Command Palette (或是按 Ctrl + Shift + P)
選取 Azure: Open Bash in Cloud Shell
如果還沒有登入 Azure, 會被要求登入 Azure
順利的話就會在 vscode 內開啟 Cloud Shell :)
接下來就可以快樂的在 vscode 內開啟 Cloud Shell 來進行管理
不用開啟 Azure Portal 真是方便 :)
同場加映: 如果碰到要開啓 Cloud Shell 要求選取目錄導致無法開啟的問題
請見 https://github.com/microsoft/vscode-azure-account/issues/220
解法
登入 Azure Portal
開啟 Cloud shell
輸入 az account list
複製 tenantId
開啟 VS code
點選 Azure Account extension 設定
在Azure: Tenant 設定將剛剛的 tenantId 貼上去
這樣就解決了
再次感謝 DanielMOliveira
這個 issue 我也開了快五個月 :p
又向 Azure 前進一步
~ enjoy it
Reference:


WordPress with container 練習小記
WordPress with container 練習小記
OS: openSUSE Leap 15.2 in Azure
今天來寫 WordPress 的練習文章
現在 WordPress 的使用率已經越來越高了, 今年的一些讀書計劃的內容內也有 WordPress 的規劃
首先就使用 container 的方式來進行練習.
規劃架構
使用 openSUSE Leap 15.2 VM in Azure 作為 container host
使用 container 方式執行 MySQL 與 WordPress
建立獨立的 container network 給 WordPress 與 MySQL
好處是可以使用名稱的方式連接
建立 container volume web-data
掛載 MySQL 的 /var/lib/mysql 以利後續維護與升級
可以考慮另外建立獨立的 volume 來存放 WordPress 的 Plugin
在 Azure 內建立 openSUSE Leap 15.2 的 VM
SSH 連線虛擬機器, 並使用 > sudo su - 切換為管理者 root
啟動 docker 服務
# systemctl start docker
首先觀察主機上的 volume
# docker volume ls
DRIVER VOLUME NAME
建立 volume
# docker volume create web-data
web-data
觀察資訊
# docker volume ls
DRIVER VOLUME NAME
local web-data
# docker volume inspect web-data
[
{
"CreatedAt": "2021-01-03T06:04:30Z",
"Driver": "local",
"Labels": {},
"Mountpoint": "/var/lib/docker/volumes/web-data/_data",
"Name": "web-data",
"Options": {},
"Scope": "local"
}
]
可以觀察 web-data 在本機上面的 mountpoint
一樣, 建立之前先觀察資訊
# docker network ls
NETWORK ID NAME DRIVER SCOPE
0362ba8e433b bridge bridge local
1e4986872739 host host local
0ac3b895fef7 none null local
建立 network
# docker network create web-network
457bc7fc24f0b26796f32f5f3191853b9363a3a83e07044cf8d4fe5bd8a213fa
再次觀察資訊
# docker network ls
NETWORK ID NAME DRIVER SCOPE
0362ba8e433b bridge bridge local
1e4986872739 host host local
0ac3b895fef7 none null local
457bc7fc24f0 web-network bridge local
爲何要建立 network, 因為預設 bridge network 不能用名稱解析, 這樣會連接不到
可以參考官方的說明: Differences between user-defined bridges and the default bridge
User-defined bridges provide automatic DNS resolution between containers
Containers on the default bridge network can only access each other by IP addresses, unless you use the --link option, which is considered legacy
另外一篇文章
開始佈署 MySQL
# docker run --name web-mysql --network web-network -e MYSQL_ROOT_PASSWORD=rootpassword -e MYSQL_DATABASE=wp -e MYSQL_USER=sakana -e MYSQL_PASSWORD=sakanapassword -d mysql:5.7
開始佈署 WordPress
# docker run --name web-wordpress --network web-network -e WORDPRESS_DB_HOST=web-mysql:3306 -e WORDPRESS_DB_NAME=wp -e WORDPRESS_DB_USER=sakana -e WORDPRESS_DB_PASSWORD=sakanapassword -p 80:80 -d wordpress
因為只是實驗, 所以上面的相關密碼就用簡單的方式
如果要更安全的方式可以考慮使用 docker secret
參考 Wordpress dockerHub
Docker Secrets 方式可以考慮 -e WORDPRESS_DB_PASSWORD_FILE=/run/secrets/mysql-root
進行測試
首先在 Azure 上的網路安全性群組, 先開放 port 80 可以存取
接下來連線 VM 的對外 IP
就會進入 WordPress 的安裝畫面
語系選繁體中文 -- > 繼續
輸入相關資訊
點選 安裝WordPress
大功告成
點選 登入
使用剛剛建立的帳號密碼
就可以進行登入
接下來就可以進入後台轉寫文章, 進行設定
或是觀察自己的第一個 WordPress 了
另外也有看到 docker-compose 安裝方式, 先放在下面, 以後再說
docker-compose 安裝
在 minikube 上架設 Stateless Wordpress
又離 WordPress 進了一步
~ enjoy it
Reference


Stackdriver-agent with openSUSE Leap 15.2 in GCP 安裝小記
Stackdriver-agent with openSUSE Leap 15.2 in GCP 安裝小記
OS: openSUSE Leap 15.2 in GCP
今天要來嘗試在 openSUSE Leap 15.2 in GCP 安裝 stackdriver 的 agent
首先先來談談爲何要在 GCP 的 OS 內安裝 stackdriver-agent
預設在 GCP 內使用 OS, GCP 是會提供相關監控的數值
例如 CPU 用量 / 網路狀況 / 磁碟 IOPS
但是 如果是要監控 Memory Utilization / Disk Space Utilization 就是要安裝 Stackdriver-agent
安裝 agent 的官方頁面如下
主要流程大概就是
下載 script
安裝 stackdriver-agent
啟動 stackdriver-agent 服務
但是目前 stackdriver-agent 只有針對已經支援的 OS 來進行安裝 script, 可惜的是 openSUSE Leap 沒有列在裡面, 所以我就嘗試用 SLES 的方式來修改, 讓 openSUSE Leap 15.2 in GCP 也可以看到相關資訊
所以以下為個人實驗, 不負責相關影響
在 GCP 建立 openSUSE Leap 15.2 GCE
SSH 連入該台 GCE 進行安裝
切換為 root 身份進行處理 (個人習慣)
> sudo su -
下載 GCP add agent script 到目前目錄
# curl -sSO https://dl.google.com/cloudagents/add-monitoring-agent-repo.sh
觀察相關資訊
# ls
.bash_history .gnupg .ssh add-monitoring-agent-repo.sh bin
觀察 script 內容
# egrep -v '^#|^$' add-monitoring-agent-repo.sh
REPO_HOST='packages.cloud.google.com'
MONITORING_AGENT_DOCS_URL="https://cloud.google.com/monitoring/agent"
MONITORING_AGENT_SUPPORTED_URL="${MONITORING_AGENT_DOCS_URL}/#supported_operating_systems"
[[ -z "${REPO_SUFFIX-}" ]] && REPO_SUFFIX='all'
if [[ -f /etc/os-release ]]; then
. /etc/os-release
fi
handle_debian() {
lsb_release -v >/dev/null 2>&1 || { \
apt-get update; apt-get -y install lsb-release; \
}
apt-get update; apt-get -y install apt-transport-https ca-certificates
local CODENAME="$(lsb_release -sc)"
local REPO_NAME="google-cloud-monitoring-${CODENAME}${REPO_SUFFIX+-${REPO_SUFFIX}}"
cat > /etc/apt/sources.list.d/google-cloud-monitoring.list <<EOM
deb https://${REPO_HOST}/apt ${REPO_NAME} main
EOM
curl --connect-timeout 5 -s -f "https://${REPO_HOST}/apt/doc/apt-key.gpg" | apt-key add -
}
handle_rpm() {
lsb_release -v >/dev/null 2>&1 || yum -y install redhat-lsb-core
local REPO_NAME="google-cloud-monitoring-${1}-\$basearch${REPO_SUFFIX+-${REPO_SUFFIX}}"
cat > /etc/yum.repos.d/google-cloud-monitoring.repo <<EOM
[google-cloud-monitoring]
name=Google Cloud Monitoring Agent Repository
baseurl=https://${REPO_HOST}/yum/repos/${REPO_NAME}
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://${REPO_HOST}/yum/doc/yum-key.gpg
https://${REPO_HOST}/yum/doc/rpm-package-key.gpg
EOM
}
handle_redhat() {
local VERSION_PRINTER='import platform; print(platform.dist()[1].split(".")[0])'
local MAJOR_VERSION="$(python2 -c "${VERSION_PRINTER}")"
handle_rpm "el${MAJOR_VERSION}"
}
handle_amazon_linux() {
handle_rpm "amzn"
}
handle_suse() {
SUSE_VERSION=${VERSION%%-*}
local REPO_NAME="google-cloud-monitoring-sles${SUSE_VERSION}-\$basearch${REPO_SUFFIX+-${REPO_SUFFIX}}"
zypper --non-interactive refresh || { \
echo "Could not refresh zypper repositories."; \
echo "This is not necessarily a fatal error; proceeding..."; \
}
cat > /etc/zypp/repos.d/google-cloud-monitoring.repo <<EOM
[google-cloud-monitoring]
name=Google Cloud Monitoring Agent Repository
baseurl=https://${REPO_HOST}/yum/repos/${REPO_NAME}
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://${REPO_HOST}/yum/doc/yum-key.gpg
https://${REPO_HOST}/yum/doc/rpm-package-key.gpg
EOM
zypper --non-interactive --gpg-auto-import-keys refresh google-cloud-monitoring || \
exit $?
}
case "${ID:-}" in
amzn)
echo 'Adding agent repository for Amazon Linux.'
handle_amazon_linux
;;
debian|ubuntu)
echo 'Adding agent repository for Debian or Ubuntu.'
handle_debian
;;
rhel|centos)
echo 'Adding agent repository for RHEL or CentOS.'
handle_redhat
;;
sles)
echo 'Adding agent repository for SLES.'
handle_suse
;;
*)
# Fallback for systems lacking /etc/os-release.
if [[ -f /etc/debian_version ]]; then
echo 'Adding agent repository for Debian.'
handle_debian
elif [[ -f /etc/redhat-release ]]; then
echo 'Adding agent repository for Red Hat.'
handle_redhat
elif [[ -f /etc/SuSE-release ]]; then
echo 'Adding agent repository for SLES.'
handle_suse
else
echo >&2 'Unidentifiable or unsupported platform.'
echo >&2 "See ${MONITORING_AGENT_SUPPORTED_URL} for a list of supported platforms."
exit 1
fi
esac
這邊我只看 suse 的相關處理, 大概就是建立 /etc/zypp/repos.d/google-cloud-monitoring.repo 以及進行 gpg key import 與 refresh
仿造上面的做法來建立 /etc/zypp/repos.d/google-cloud-monitoring.repo
還沒做之前觀察 gpg key 資訊
# rpm -qa gpg-pubkey*
gpg-pubkey-307e3d54-5aaa90a5
gpg-pubkey-3dbdc284-53674dd4
gpg-pubkey-39db7c82-5847eb1f
建立 google-cloud-monitoring.repo 相關資訊
#vi /etc/zypp/repos.d/google-cloud-monitoring.repo
內容如下
[google-cloud-monitoring-sles15-x86_64-all]
name=google-cloud-monitoring
enabled=1
autorefresh=1
baseurl=https://packages.cloud.google.com/yum/repos/google-cloud-monitoring-sles15-x86_64-all
type=rpm-md
keeppackages=0
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
匯入 上面的 gpgkey
# rpm --import https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
# rpm --import https://packages.cloud.google.com/yum/doc/yum-key.gpg
這樣可以避免 Signature verification failed for file 'repomd.xml' 問題
進行 gpgkey 比對
# rpm -qa gpg-pubkey*
gpg-pubkey-3e1ba8d5-558ab6a8
gpg-pubkey-307e3d54-5aaa90a5
gpg-pubkey-3dbdc284-53674dd4
gpg-pubkey-a7317b0f-551deab2
gpg-pubkey-836f4beb-5fc97e5e
gpg-pubkey-39db7c82-5847eb1f
gpg-pubkey-ba07f4fb-5ac168db
藍色部分爲新增進來的 Key
將 zypper refresh 以及加入 gpg key
# zypper --gpg-auto-import-keys refresh
Retrieving repository 'google-cloud-monitoring' metadata ..............................[done]
Building repository 'google-cloud-monitoring' cache ...................................[done]
Retrieving repository 'Debug Repository' metadata .....................................[done]
Building repository 'Debug Repository' cache ..........................................[done]
Retrieving repository 'Update Repository (Debug)' metadata ............................[done]
Building repository 'Update Repository (Debug)' cache .................................[done]
Retrieving repository 'Non-OSS Repository' metadata ...................................[done]
Building repository 'Non-OSS Repository' cache ........................................[done]
Retrieving repository 'Main Repository' metadata ......................................[done]
Building repository 'Main Repository' cache ...........................................[done]
Retrieving repository 'Source Repository' metadata ....................................[done]
Building repository 'Source Repository' cache .........................................[done]
Retrieving repository 'Main Update Repository' metadata ...............................[done]
Building repository 'Main Update Repository' cache ....................................[done]
Retrieving repository 'Update Repository (Non-Oss)' metadata ..........................[done]
Building repository 'Update Repository (Non-Oss)' cache ...............................[done]
All repositories have been refreshed.
安裝 agent
# zypper install stackdriver-agent
Loading repository data...
Reading installed packages...
Resolving package dependencies...
The following 2 NEW packages are going to be installed:
insserv-compat stackdriver-agent
2 new packages to install.
Overall download size: 1.2 MiB. Already cached: 0 B. After the operation, additional 5.2 MiB
will be used.
Continue? [y/n/v/...? shows all options] (y): y
Retrieving package insserv-compat-0.1-lp152.5.1.noarch (1/2), 14.9 KiB ( 8.5 KiB unpacked)
Retrieving: insserv-compat-0.1-lp152.5.1.noarch.rpm .....................[done (259.7 KiB/s)]
Retrieving package stackdriver-agent-6.1.0-1.sles15.x86_64
(2/2), 1.2 MiB ( 5.2 MiB unpacked)
Retrieving: cde909b8d24e2beabdbd489e42e5bd65c64c14e09b710c56852736aecd3bf3a7-stackdrive[done]
Checking for file conflicts: ..........................................................[done]
(1/2) Installing: insserv-compat-0.1-lp152.5.1.noarch .................................[done]
(2/2) Installing: stackdriver-agent-6.1.0-1.sles15.x86_64 .............................[done]
Additional rpm output:
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
stackdriver-agent 0:off 1:off 2:on 3:on 4:on 5:on 6:off
觀察服務狀態
# systemctl status stackdriver-agent
● stackdriver-agent.service - LSB: start and stop Stackdriver Agent
Loaded: loaded (/etc/init.d/stackdriver-agent; generated; vendor preset: disabled)
Active: inactive (dead)
重新啟動服務
# systemctl restart stackdriver-agent
觀察服務狀態
# systemctl status stackdriver-agent
● stackdriver-agent.service - LSB: start and stop Stackdriver Agent
Loaded: loaded (/etc/init.d/stackdriver-agent; generated; vendor preset: disabled)
Active: active (running) since Sun 2020-12-27 13:59:30 UTC; 32s ago
觀察如果重開機是否會啟動服務
# systemctl is-enabled stackdriver-agent
stackdriver-agent.service is not a native service, redirecting to systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install is-enabled stackdriver-agent
enabled
回 GCP 觀察相關資訊
這個時候就發現 Memory Utilization / Disk Space Utilization 有相關資訊了
大功告成
~ enjoy it
Reference
Dec 5th, 2020


使用 certbot 取得 Let’s Encrypt 憑證 with openSUSE in Azure 小記2
使用 certbot 取得 Let’s Encrypt 憑證 with openSUSE in Azure 小記2
上次寫使用 certbot 建立 Let’s Encrypt 憑證是 2020/9/15
一般來說是簽發 90 天, 所以最近就有收到 Let's Encrypt certificate expiration notice for domain 通知信件.
今天就是來寫如何手動取得憑證的小記
OS: openSUSE Leap 15.2 in Azure
DNS provider: gandi.net
首先會看到 Let’s Encrypt 官方網頁對套件做法已經改變, 他把他包進 snap 裡面
You'll need to install snapd and make sure you follow any instructions to enable classic snap support
snap 安裝on openSUsE文件如下
==== 原有 certbot 方式驗證是否仍可取得憑證 ====
在使用 snap 方式之前, 先來驗證如果是舊有的 certbot 指令是否可以取得 Let’s Encrypt 憑證
可以參考之前的文章
使用 zypper 指令安裝
# zypper install python3-certbot
# certbot certonly --manual --preferred-challenges=dns -d ines.tw
驗證還是可以取得相關憑證的
==== 使用 snap 方式安裝並驗證可否取得憑證 ====
暫時小結論: 使用 snapd 目前會有 apparmor 問題, 所以暫時我還是使用 python3-certbot 來處理
使用 zypper 指令 新增 repo
# zypper addrepo --refresh https://download.opensuse.org/repositories/system:/snappy/openSUSE_Leap_15.2 snappy
Adding repository 'snappy' .............................................................................................[done]
Repository 'snappy' successfully added
URI : https://download.opensuse.org/repositories/system:/snappy/openSUSE_Leap_15.2
Enabled : Yes
GPG Check : Yes
Autorefresh : Yes
Priority : 99 (default priority)
Repository priorities are without effect. All enabled repositories share the same priority.
匯入 GPG Key
# zypper --gpg-auto-import-keys refresh
Retrieving repository 'Debug Repository' metadata ......................................................................[done]
Building repository 'Debug Repository' cache ...........................................................................[done]
Retrieving repository 'Update Repository (Debug)' metadata .............................................................[done]
Building repository 'Update Repository (Debug)' cache ..................................................................[done]
Retrieving repository 'Non-OSS Repository' metadata ....................................................................[done]
Building repository 'Non-OSS Repository' cache .........................................................................[done]
Retrieving repository 'Main Repository' metadata .......................................................................[done]
Building repository 'Main Repository' cache ............................................................................[done]
Retrieving repository 'Source Repository' metadata .....................................................................[done]
Building repository 'Source Repository' cache ..........................................................................[done]
Retrieving repository 'Main Update Repository' metadata ................................................................[done]
Building repository 'Main Update Repository' cache .....................................................................[done]
Retrieving repository 'Update Repository (Non-Oss)' metadata ...........................................................[done]
Building repository 'Update Repository (Non-Oss)' cache ................................................................[done]
Retrieving repository 'snappy' metadata -----------------------------------------------------------------------------------[-]
Automatically importing the following key:
Repository: snappy
Key Name: system:snappy OBS Project <system:snappy@build.opensuse.org>
Key Fingerprint: 4F2FA05B 2C6589C3 FD12055E F7C6E425 ED340235
Key Created: Sat Oct 31 16:59:39 2020
Key Expires: Mon Jan 9 16:59:39 2023
Rpm Name: gpg-pubkey-ed340235-5f9d97fb
Retrieving repository 'snappy' metadata ................................................................................[done]
Building repository 'snappy' cache .....................................................................................[done]
All repositories have been refreshed.
Upgrade package cache
# zypper dup --from snappy
Loading repository data...
Reading installed packages...
Computing distribution upgrade...
Nothing to do.
安裝 snapd
# zypper install snapd
Loading repository data...
Reading installed packages...
Resolving package dependencies...
The following 3 NEW packages are going to be installed:
snapd squashfs system-user-daemon
3 new packages to install.
Overall download size: 15.0 MiB. Already cached: 0 B. After the operation, additional 68.0 MiB will be used.
Continue? [y/n/v/...? shows all options] (y): Y
安裝完之後, 雖然官方文件說 You then need to either reboot, logout/login or source /etc/profile to have /snap/bin added to PATH.
但是我試過, #source /etc/profile 不一定會把 /snap/bin 加入 $PATH, 還是登出登入比較保險
# systemctl enable --now snapd
這一招還不錯, 起動 snapd 的同時, 設定開機啟動, 以往我都是分開兩個指令執行
# snap install core
error: cannot perform the following tasks:
- Setup snap "core" (10444) security profiles (cannot setup profiles for snap "core": cannot create host snap-confine apparmor configuration: cannot reload snap-confine apparmor profile: cannot load apparmor profiles: exit status 1
apparmor_parser output:
AppArmor parser error for /var/lib/snapd/apparmor/profiles/snap-confine.core.10444 in /var/lib/snapd/apparmor/profiles/snap-confine.core.10444 at line 2: Could not open 'tunables/global'
安裝失敗, apparmor 有問題
官方文件有提到 Tumbleweed 要額外設定 snapd.apparmor
在 openSUSE Leap 15.2 使用該指令會找不到相關服務, snpad 也不是 openSUSE 的主要做法, 暫時先放棄
===================
暫時來說, 目前會先使用 python3-certbot 做法, 除非哪天只能在 snapd 才能取得再考慮 :)
~ enjoy it
Reference
Nov 29th, 2020


三大雲平台工具容器升級小記 - ansible 2.10.3 與 Azure module
三大雲平台工具容器升級小記 - ansible 2.10.3 與 Azure module
OS: container with openSUSE Leap 15.2
上次升級是 2020/11/14 , 這次會來升級的原因是
Ansible 在 2.10 以後的版本, 有很多 module 被移動到 Ansible Collections, 也就是說現在不是如同 Ansible 官網上面的 pip3 install ‘ansible[azure]’ 的安裝方式. 接下來就是透過 collection 方式來進行安裝
參考網路上的文章 https://stackoverflow.com/questions/64921336/warning-ansible-2-10-3-does-not-provide-the-extra-azure
https://docs.ansible.com/ansible/latest/scenario_guides/guide_azure.html
這樣也是好事, 之前也是因為這樣報了一個 issue
然後也同步紀錄一下目前 Azure CloudShell 上面的 Ansible 資訊
Ansible: 2.9.11 / python 2.7
但是目前已經出現 Python 2 is no longer support by the Python core team 訊息了
先整理結果
升級前
OS: openSUSE Leap 15.2
awscli: aws-cli/2.1.1 Python/3.7.3
gcloud: Google Cloud SDK 318.0.0
azure-cli: 2.14.2
ansible: 2.10.3
升級後
OS: openSUSE Leap 15.2
awscli: aws-cli/2.1.4 Python/3.7.3
gcloud: Google Cloud SDK 319.0.0
azure-cli: 2.15.1 (目前有 bug)
ansible: 2.10.3
AWS CLI v2 安裝文件
GCP Cloud SDK 版本
這次的做法還是會透過 docker build 指令來進行
我有比較過 docker build 以及使用現有的 docker image 修改後再使用 docker commit 建立的 image 大小還是很有差異的
Dockerfile 的部分我是拿之前 openSUSE Leap 15.2 來修改
修改細節
Update time
修改 pip3 安裝 ansible
修改 安裝 ansible azure module 方式, 使用 collection 方式安裝
Google SDK 版本還有下載的檔案路徑以及檔案名稱
列出 diff 的結果給大家參考
> diff opensuseLeap152_ansible_202001129_Dockerfile opensuseLeap151_ansible_20201114_Dockerfile
6c6
< # update: 20201129
---
> # update: 20201114
12c12
< # Install python3-pip, upgrade pip, ansible, boto, boto3
---
> # Install python3-pip, upgrade pip, ansible[azure], boto, boto3
15c15
< pip3 install ansible && \
---
> pip3 install ansible[azure] && \
43d42
< # 2020/11/29 Still have az login issue in Github https://github.com/Azure/azure-cli/issues/13209
49,58d47
< # Install Ansible azure module
< # After ansible 2.10, some module move to ansible collect, change install method
< RUN zypper install -y curl && \
< curl -O https://raw.githubusercontent.com/ansible-collections/azure/dev/requirements-azure.txt && \
< pip3 install -r requirements-azure.txt && \
< rm -f requirements-azure.txt && \
< ansible-galaxy collection install azure.azcollection
<
<
<
75c64
< # Install google cloud SDK 319.0.0
---
> # Install google cloud SDK 318.0.0
77,78c66,67
< RUN wget https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-319.0.0-linux-x86_64.tar.gz && \
< tar zxvf google-cloud-sdk-319.0.0-linux-x86_64.tar.gz && \
---
> RUN wget https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-318.0.0-linux-x86_64.tar.gz && \
Dockerfile 內容如下
我檔案的名稱取名爲 opensuseLeap152_ansible_20201129_Dockerfile
# openSUSE Leap 15.2 with ansible, azure-cli, aws cli, gcloud
FROM opensuse/leap:15.2
# Author
# MAINTAINER 已經棄用, 之後要使用 LABEL 方式
# update: 20201129
LABEL maintainer="sakana@cycu.org.tw"
# Set LANG for UTF-8 - for Chinese
ENV LANG C.UTF-8
# Install python3-pip, upgrade pip, ansible, boto, boto3
RUN zypper install -y python3-pip && \
pip3 install --upgrade pip && \
pip3 install ansible && \
pip3 install boto boto3
# Install openssh, set ls alias
RUN zypper install -y openssh
RUN echo "alias ls='ls --color=tty'" >> /root/.bashrc
# Install wget, download azure_rm.py, set permission
RUN zypper install -y wget
# azure_rm.py no need to download
# Starting with Ansible 2.8, Ansible provides an Azure dynamic-inventory plug-in
# https://docs.ansible.com/ansible/latest/plugins/inventory/azure_rm.html
# old azure_rm.py URL https://raw.githubusercontent.com/ansible/ansible/devel/contrib/inventory/azure_rm.py
#
# Create working directory in /root
RUN mkdir /root/.azure && \
mkdir /root/.aws && \
mkdir /root/playbook && \
mkdir -p /root/.config/gcloud && \
wget https://raw.githubusercontent.com/sakanamax/LearnAnsible/master/template/ansible.cfg && \
mv /ansible.cfg /root && \
wget https://raw.githubusercontent.com/sakanamax/LearnAnsible/master/template/hosts && \
mv /hosts /root
#### Azure ####
# Install azure-cli
# 2020/11/29 Still have az login issue in Github https://github.com/Azure/azure-cli/issues/13209
RUN zypper install -y curl && \
rpm --import https://packages.microsoft.com/keys/microsoft.asc && \
zypper addrepo --name 'Azure CLI' --check https://packages.microsoft.com/yumrepos/azure-cli azure-cli && \
zypper install --from azure-cli -y azure-cli
# Install Ansible azure module
# After ansible 2.10, some module move to ansible collect, change install method
RUN zypper install -y curl && \
curl -O https://raw.githubusercontent.com/ansible-collections/azure/dev/requirements-azure.txt && \
pip3 install -r requirements-azure.txt && \
rm -f requirements-azure.txt && \
ansible-galaxy collection install azure.azcollection
#install vim tar gzip jq unzip less bind-utils iputils groff
RUN zypper install -y vim tar gzip jq unzip less bind-utils iputils groff
RUN echo "set encoding=utf8" > /root/.vimrc
#### AWS ####
# Install awscli v1
#RUN pip3 install awscli
#RUN echo "source /usr/bin/aws_bash_completer" >> /root/.bashrc
# Install awscli v2
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && \
unzip awscliv2.zip && \
/aws/install
RUN echo "complete -C '/usr/local/bin/aws_completer' aws" >> /root/.bashrc
#### GCP ####
# Install google cloud SDK 319.0.0
ENV CLOUDSDK_CORE_DISABLE_PROMPTS 1
RUN wget https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-319.0.0-linux-x86_64.tar.gz && \
tar zxvf google-cloud-sdk-319.0.0-linux-x86_64.tar.gz && \
/google-cloud-sdk/install.sh && \
echo "if [ -f '/google-cloud-sdk/path.bash.inc' ]; then . '/google-cloud-sdk/path.bash.inc'; fi" >> /root/.bashrc && \
echo "if [ -f '/google-cloud-sdk/completion.bash.inc' ]; then . '/google-cloud-sdk/completion.bash.inc'; fi" >> /root/.bashrc
使用 docker build 指令建立 image
> docker build -t sakana/ansible_opensuse152:20201129 -f ./opensuseLeap152_ansible_20201129_Dockerfile .
使用 -f 指定 Dockerfile 名稱
最後是 ” . “ 目前的目錄
測試 container image
> docker run -v ~/.aws:/root/.aws -v ~/.azure:/root/.azure -v ~/.config/gcloud:/root/.config/gcloud -it sakana/ansible_opensuse152:20201129 /bin/bash
測試結果 OK, 建立 tag
這邊目前因為 openSUSE Leap 15 使用舊的 azure cli 以及相依性, 所以現在 az 指令會有問題, 已經 update issue 以及花了很多時間調整, 目前還是要等 openSUSE and Azure 看是否會有後續更新
但是 ansible with azure 沒有問題, 所以目前 az 指令可能會暫時透過 Azure cloud shell
觀察資訊
> docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
sakana/ansible_opensuse152 20201129 c69c2e1c6e9e 13 minutes ago 2.09GB
opensuse/leap 15.2 573008f769b5 20 hours ago 106MB
sakana/ansible_opensuse152 latest 9f8d6b777cc9 2 weeks ago 1.82GB
建立 tag
> docker tag c69c2e1c6e9e sakana/ansible_opensuse152:latest
登入 docker
> docker login
上傳 image
> docker push sakana/ansible_opensuse152:20201129
> docker push sakana/ansible_opensuse152:latest
完工, 以後使用就用
> docker run -v ~/.aws:/root/.aws -v ~/.azure:/root/.azure -v ~/.config/gcloud:/root/.config/gcloud -it sakana/ansible_opensuse152 /bin/bash
~ enjoy it
Reference:
https://sakananote2.blogspot.com/2020/11/opensuse-leap-152-container.html
https://stackoverflow.com/questions/64921336/warning-ansible-2-10-3-does-not-provide-the-extra-azure
http://sakananote2.blogspot.com/2020/08/opensuse-leap-152-container.html
https://sakananote2.blogspot.com/2020/05/aws-cli-v2-with-opensuse-leap-151.html
http://sakananote2.blogspot.com/2020/01/python-3-with-opensuse-leap-151.html
http://sakananote2.blogspot.com/2019/07/with-opensuse-leap-15-container.html
http://sakananote2.blogspot.com/2019/05/ansible-azure-cli-awscli-gcloud-with.html
http://sakananote2.blogspot.com/2019/11/with-opensuse-leap-151-container.html
Nov 14th, 2020


三大雲平台工具容器升級小記 - 使用 openSUSE Leap 15.2 Container
三大雲平台工具容器升級小記 - 使用 openSUSE Leap 15.2 Container
OS: container with openSUSE Leap 15.2
上次升級是 2020/8/2 , 這次會來升級的原因是
升級 gcloud 版本
升級 azure-cli 版本
升級 aws cli 版本
先整理結果
升級前
OS: openSUSE Leap 15.2
awscli: aws-cli/2.0.36 Python/3.7.3
gcloud: Google Cloud SDK 303.0.0
azure-cli: 2.9.14.
ansible: 2.9.11
升級後
OS: openSUSE Leap 15.2
awscli: aws-cli/2.1.1 Python/3.7.3
gcloud: Google Cloud SDK 318.0.0
azure-cli: 2.14.2
ansible: 2.10.3
AWS CLI v2 安裝文件
GCP Cloud SDK 版本
這次的做法還是會透過 docker build 指令來進行
我有比較過 docker build 以及使用現有的 docker image 修改後再使用 docker commit 建立的 image 大小還是很有差異的
Dockerfile 的部分我是拿之前 openSUSE Leap 15.2 來修改
修改細節
Update time
修改 pip3 安裝 boto 與 boto3
Google SDK 版本還有下載的檔案路徑以及檔案名稱
列出 diff 的結果給大家參考
> diff opensuseLeap152_ansible_20200802_Dockerfile opensuseLeap151_ansible_20200531_Dockerfile
6c6
< # update: 20200802
---
> # update: 20201114
12c12
< # Install python3-pip, upgrade pip, ansible[azure], boto
---
> # Install python3-pip, upgrade pip, ansible[azure], boto, boto3
16c16
< pip3 install boto
---
> pip3 install boto boto3
64c64
< # Install google cloud SDK 303.0.0
---
> # Install google cloud SDK 318.0.0
66,67c66,67
< RUN wget https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-303.0.0-linux-x86_64.tar.gz && \
< tar zxvf google-cloud-sdk-303.0.0-linux-x86_64.tar.gz && \
---
> RUN wget https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-318.0.0-linux-x86_64.tar.gz && \
> tar zxvf google-cloud-sdk-318.0.0-linux-x86_64.tar.gz && \
Dockerfile 內容如下
我檔案的名稱取名爲 opensuseLeap152_ansible_20201114_Dockerfile
# openSUSE Leap 15.2 with ansible, azure-cli, aws cli, gcloud
FROM opensuse/leap:15.2
# Author
# MAINTAINER 已經棄用, 之後要使用 LABEL 方式
# update: 20201114
LABEL maintainer="sakana@cycu.org.tw"
# Set LANG for UTF-8 - for Chinese
ENV LANG C.UTF-8
# Install python3-pip, upgrade pip, ansible[azure], boto, boto3
RUN zypper install -y python3-pip && \
pip3 install --upgrade pip && \
pip3 install ansible[azure] && \
pip3 install boto boto3
# Install openssh, set ls alias
RUN zypper install -y openssh
RUN echo "alias ls='ls --color=tty'" >> /root/.bashrc
# Install wget, download azure_rm.py, set permission
RUN zypper install -y wget
# azure_rm.py no need to download
# Starting with Ansible 2.8, Ansible provides an Azure dynamic-inventory plug-in
# https://docs.ansible.com/ansible/latest/plugins/inventory/azure_rm.html
# old azure_rm.py URL https://raw.githubusercontent.com/ansible/ansible/devel/contrib/inventory/azure_rm.py
#
# Create working directory in /root
RUN mkdir /root/.azure && \
mkdir /root/.aws && \
mkdir /root/playbook && \
mkdir -p /root/.config/gcloud && \
wget https://raw.githubusercontent.com/sakanamax/LearnAnsible/master/template/ansible.cfg && \
mv /ansible.cfg /root && \
wget https://raw.githubusercontent.com/sakanamax/LearnAnsible/master/template/hosts && \
mv /hosts /root
#### Azure ####
# Install azure-cli
RUN zypper install -y curl && \
rpm --import https://packages.microsoft.com/keys/microsoft.asc && \
zypper addrepo --name 'Azure CLI' --check https://packages.microsoft.com/yumrepos/azure-cli azure-cli && \
zypper install --from azure-cli -y azure-cli
#install vim tar gzip jq unzip less bind-utils iputils groff
RUN zypper install -y vim tar gzip jq unzip less bind-utils iputils groff
RUN echo "set encoding=utf8" > /root/.vimrc
#### AWS ####
# Install awscli v1
#RUN pip3 install awscli
#RUN echo "source /usr/bin/aws_bash_completer" >> /root/.bashrc
# Install awscli v2
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && \
unzip awscliv2.zip && \
/aws/install
RUN echo "complete -C '/usr/local/bin/aws_completer' aws" >> /root/.bashrc
#### GCP ####
# Install google cloud SDK 318.0.0
ENV CLOUDSDK_CORE_DISABLE_PROMPTS 1
RUN wget https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-318.0.0-linux-x86_64.tar.gz && \
tar zxvf google-cloud-sdk-318.0.0-linux-x86_64.tar.gz && \
/google-cloud-sdk/install.sh && \
echo "if [ -f '/google-cloud-sdk/path.bash.inc' ]; then . '/google-cloud-sdk/path.bash.inc'; fi" >> /root/.bashrc && \
echo "if [ -f '/google-cloud-sdk/completion.bash.inc' ]; then . '/google-cloud-sdk/completion.bash.inc'; fi" >> /root/.bashrc
使用 docker build 指令建立 image
> docker build -t sakana/ansible_opensuse152:20201114 -f ./opensuseLeap152_ansible_20201114_Dockerfile .
使用 -f 指定 Dockerfile 名稱
最後是 ” . “ 目前的目錄
測試 container image
> docker run -v ~/.aws:/root/.aws -v ~/.azure:/root/.azure -v ~/.config/gcloud:/root/.config/gcloud -it sakana/ansible_opensuse152:20201114 /bin/bash
測試結果 OK, 建立 tag
觀察資訊
> docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
sakana/ansible_opensuse152 20201114 9f8d6b777cc9 10 minutes ago 1.82GB
opensuse/leap 15.2 da63484e1af5 4 days ago 106MB
sakana/ansible_opensuse152 latest d1bb9da2d2e1 3 months ago 1.66GB
建立 tag
> docker tag 9f8d6b777cc sakana/ansible_opensuse152:latest
登入 docker
> docker login
上傳 image
> docker push sakana/ansible_opensuse152:20201114
> docker push sakana/ansible_opensuse152:latest
完工, 以後使用就用
> docker run -v ~/.aws:/root/.aws -v ~/.azure:/root/.azure -v ~/.config/gcloud:/root/.config/gcloud -it sakana/ansible_opensuse152 /bin/bash
~ enjoy it
Reference:
http://sakananote2.blogspot.com/2020/08/opensuse-leap-152-container.html
https://sakananote2.blogspot.com/2020/05/aws-cli-v2-with-opensuse-leap-151.html
http://sakananote2.blogspot.com/2020/01/python-3-with-opensuse-leap-151.html
http://sakananote2.blogspot.com/2019/07/with-opensuse-leap-15-container.html
http://sakananote2.blogspot.com/2019/05/ansible-azure-cli-awscli-gcloud-with.html
http://sakananote2.blogspot.com/2019/11/with-opensuse-leap-151-container.html