星期日, 7月 07, 2019

三大雲平台工具容器升級小記 with openSUSE Leap 15 container

三大雲平台工具容器升級小記 with openSUSE Leap 15 container

OS: container with openSUSE Leap 15

awscli:  aws-cli/1.16.193
gcloud: Google Cloud SDK 252.0.0
azure-cli: 2.0.68

上次升級雲平台工具是 20190627, 短短不到 10 天, 因為以下需求今天又來進行升級 
  • azure 以及 aws 工具又有版本升級
  • 加上 aws 指令補齊以及修正 vim 針對中文顯示問題

==== 處理 container 內相關套件升級以及設定 ====

使用 docker run 啟動 container, 進入到 shell
  • docker run -v ~/.aws:/root/.aws -v ~/.azure:/root/.azure -v ~/.config/gcloud:/root/.config/gcloud  -it  sakana/ansible_opensuse15   /bin/bash

Azure 與 AWS 升級的部份參考之前的文章來進行升級

Vim 中文顯示問題處理

#vi   ~/.vimrc

加入相關設定
set encoding=utf8


AWS 指令補齊處理
  • 在 linux 內的處理方式跟 Mac 不一樣, 要用 source 的方式不是使用 complete

#vi  ~/.bashrc

加入相關設定
source   /usr/bin/aws_bash_completer
alias  ls=’ls --color-tty’

==== 處理 container 內相關套件升級以及設定  End ====


接下來進行 image 的 commit
首先觀察剛剛修改的 contaner ID

> docker  ps

CONTAINER ID        IMAGE         COMMAND CREATED             STATUS PORTS NAMES

9b8705c120fb        sakana/ansible_opensuse15   "/bin/bash" 5 minutes ago       Up 5 minutes optimistic_blackwell

使用 docker commit 指令建立新的 container image
> docker  commit  -m "upgrade cli"  -a  "sakana"  9b870  sakana/ansible_opensuse15:20190707

  • 9b870 為剛剛修改好的 container ID
  • 我這邊建立一個 container image 然後 tag name 為 20190707

觀察相關資訊
> docker images

REPOSITORY                  TAG IMAGE ID            CREATED SIZE
sakana/ansible_opensuse15   20190707 05a52c0a9d24        20 seconds ago 2.05GB
sakana/ansible_opensuse15   latest db3e48156fd3        9 days ago 1.68GB
opensuse/leap               15 48b19e84798d        2 months ago 103MB

使用 docker tag 指令將剛剛建立的 image tag 設為 latest
> docker  tag  05a52c0a9d24  sakana/ansible_opensuse15:latest

觀察相關資訊
> docker images

REPOSITORY                  TAG IMAGE ID            CREATED SIZE
sakana/ansible_opensuse15   20190707 05a52c0a9d24        About a minute ago   2.05GB
sakana/ansible_opensuse15   latest 05a52c0a9d24        About a minute ago   2.05GB
sakana/ansible_opensuse15   <none>              db3e48156fd3        9 days ago           1.68GB
opensuse/leap               15 48b19e84798d        2 months ago 103MB

從上面可以看出, 剛剛的 latest 已經被取代, 目前的 latest 是剛剛編輯的版本

為了日後使用, 接下來進行上傳動作

首先 進行 docker  login
> docker login


將剛剛的 image 上傳到 docker hub

> docker push sakana/ansible_opensuse15:20190707

> docker push sakana/ansible_opensuse15:latest

清除沒用到的相關資源
> docker  system  prune

啟動 container 進行相關測試
> docker run -v ~/.aws:/root/.aws -v ~/.azure:/root/.azure -v ~/.config/gcloud:/root/.config/gcloud  -it  sakana/ansible_opensuse15   /bin/bash

工具升級 ok / aws 補齊 ok / vim 中文 ok

~ enjoy it

Reference:

星期五, 6月 28, 2019

三大雲平台工具升級 + awscli 指令補齊小記

三大雲平台工具升級 + awscli 指令補齊小記

OS: container with openSUSE Leap 15


上次建立容器化方式來管理雲平台是上個月5號, 這中間三個工具都有版本升級
今天就來寫一下工具升級的方式

首先是 aws cli, 因為使用 pip , 所以就使用 pip install  方式升級

# pip install awscli --upgrade

檢查版本
# aws  --version
aws-cli/1.16.189

接下來是 Google SDK (  gcloud ), 使用  gcloud  components update 方式升級

檢查版本
# gcloud  --version

Google Cloud SDK 240.0.0
bq 2.0.42
core 2019.03.22
gsutil 4.37

升級套件
# gcloud   components  update

檢查版本
# gcloud  --version

Google Cloud SDK 252.0.0
bq 2.0.43
core 2019.06.21
gsutil 4.39

最後是 Azure , 因為當初是將  repo 匯入到 openSUSE, 所以使用 zypper 處理

先更新 repo, 這個部分很重要因為azure 的套件庫預設沒有自動更新
# zypper  refresh
使用 zypper 升級套件
# zypper  update  -y  azure-cli

檢查版本
# az  --version
azure-cli                         2.0.67

同場加映: aws   命令補齊

OS: Mac 10.14.5
awscli:  1.16.157

因為在裝 Google Cloud SDK ( gcloud )  初始化的時候, 就會將 completion 功能整合進去
所以相對應 aws 指令, 沒有預設啟用 completion 就顯得不方便

參考官方網站
我是使用 Mac 10.14.5, shell 是 bash

所以做法上很簡單

啟用命令補齊
$complete -C  '/usr/local/bin/aws_completer'  aws

讓預設開終端機就執行 aws_completer
在 ~/.bash_profile 檔案內
加入
# this is for aws complete
complete -C '/usr/local/bin/aws_completer' aws

大功告成

~ enjoy it

Reference:

星期四, 6月 27, 2019

列出 IAM 使用者與加入 Tag 到使用者小記

列出 IAM 使用者與加入 Tag 到使用者小記

想法: 列出專案使用者清單, 另外為了方便管理使用者,  加入 tag 到使用者, 好快速分辨該使用者相關資訊, 例如: 姓名, 工號 ...

列出 aws  iam 使用者名稱

$ aws  iam  list-users --output  text  | cut -f  2 | cut  -d  '/'  -f  2

列出指定帳號 IAM 使用者
$ aws  iam  list-users  --profile  sakana  --output text  | cut  -f  2 | cut -d  '/'  -f  2

加入 tag 到使用者
以下兩種方式都可以加入 tag 到使用者, 但是我比較喜換第一種

$ aws  iam  tag-user  --user-name 1203080 --tags "Key=姓名, Value=Max"

> aws  iam  tag-user  --user-name 1203080 --tags '{ "Key": "姓名", "Value": "Max"}'

列出使用者 tag
>aws  iam  list-user-tags  --user-name 1203080

Notes:
  • aws resourcegroupstaggingapi get-resources  不能搜尋 IAM tag


Reference