星期六, 11月 16, 2019

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

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

OS: container with openSUSE Leap 15.1

上次升級是 2019/8/3 , 這次會來升級的原因是 Google SDK 已經到了 271.0.0, 然後最近要作一個 Lab 需要 gcloud compute resource-policies 相關指令,  但是 Google SDK 245.0.0 沒有....
[ 謎之音: 需求是前進的鞭子 ~  ]

先整理結果

升級前
OS: openSUSE Leap 15
awscli:  aws-cli/1.16.210 Python/2.7.14
gcloud: Google Cloud SDK 245.0.0
azure-cli: 2.0.70

升級後
OS: openSUSE Leap 15.1
awscli:  aws-cli/1.16.282 Python/2.7.14
gcloud: Google Cloud SDK 271.0.0
azure-cli: 2.0.76

Todo
  • 12 月的時候將 awscli 用 python3 安裝
    • 原因是 Google SDK 目前還是 Python2, 所以想要一起升級 :p

這次的做法會透過 docker build 指令來進行
  • 我有比較過 docker build 以及使用現有的 docker image 修改後再使用 docker commit 建立的 image 大小還是很有差異的

Dockerfile 的部分我是拿之前 openSUSE Leap 15 來修改

實際上只有修改
  • openSUSE Leap 版本
  • Update time
  • Google SDK 版本還有下載的檔案路徑以及檔案名稱


列出 diff 的結果給大家參考

> diff  opensuseLeap151_ansible_Dockerfile  opensuseLeap15_ansible_Dockerfile 

1,2c1,2
< # openSUSE Leap 15.1 with ansible, azure-cli
< FROM opensuse/leap:15.1
---
> # openSUSE Leap 15 with ansible, azure-cli
> FROM opensuse/leap:15
6c6
< # update: 20191116
---
> # update: 20190727
49c49
< # Install google cloud SDK 271
---
> # Install google cloud SDK 240
51,52c51,52
< RUN wget https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-271.0.0-linux-x86_64.tar.gz && \
<   tar zxvf google-cloud-sdk-271.0.0-linux-x86_64.tar.gz && \
---
> RUN wget https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-245.0.0-linux-x86_64.tar.gz && \
>   tar zxvf google-cloud-sdk-245.0.0-linux-x86_64.tar.gz && \


Dockerfile 內容如下

# openSUSE Leap 15.1 with ansible, azure-cli
FROM opensuse/leap:15.1

# Author
# MAINTAINER 已經棄用, 之後要使用 LABEL 方式
# update: 20191116
LABEL maintainer="sakana@cycu.org.tw"

# Install python2-pip, upgrade pip, ansible[azure]
RUN zypper install -y python2-pip && \
  pip2 install --upgrade pip && \
  pip2 install ansible[azure]

# 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 && \
  wget  https://raw.githubusercontent.com/ansible/ansible/devel/contrib/inventory/azure_rm.py && \
  chmod a+x azure_rm.py && \
  mv azure_rm.py /root

# 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

# 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
RUN zypper install -y vim tar gzip
RUN echo "set encoding=utf8" > /root/.vimrc

# Install awscli
RUN pip install awscli
RUN echo "source /usr/bin/aws_bash_completer" >> /root/.bashrc


# Install google cloud SDK 271
ENV CLOUDSDK_CORE_DISABLE_PROMPTS 1
RUN wget https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-271.0.0-linux-x86_64.tar.gz && \
  tar zxvf google-cloud-sdk-271.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_opensuse151:20191116  -f  ./opensuseLeap151_ansible_Dockerfile   .

  • 使用 -f 指定 Dockerfile 名稱
  • 最後是 ” . “ 目前的目錄


測試 container image

> docker  run  -v  ~/.aws:/root/.aws  -v  ~/.azure:/root/.azure  -v ~/.config/gcloud:/root/.config/gcloud  -it  sakana/ansible_opensuse151:20191116  /bin/bash

測試結果 OK, 建立  tag

觀察資訊
> docker  images

REPOSITORY                   TAG IMAGE ID           CREATED SIZE
sakana/ansible_opensuse151   20191116 dcd69d00b4aa        34 minutes ago      1.19GB
opensuse/leap                15.1 fef5ad254f63        10 days ago 103MB
sakana/ansible_opensuse15    latest 4fe595fb61e4        3 months ago 1.1GB

建立 tag 
> docker  tag  dcd69d00b4aa  sakana/ansible_opensuse151:latest

登入 docker
> docker  login

上傳 image
> docker  push  sakana/ansible_opensuse151:20191116

> docker  push  sakana/ansible_opensuse151:latest

完工, 以後使用就用

> docker  run  -v  ~/.aws:/root/.aws  -v  ~/.azure:/root/.azure  -v ~/.config/gcloud:/root/.config/gcloud  -it  sakana/ansible_opensuse151  /bin/bash


~ enjoy it

Reference:

沒有留言: