星期五, 5月 01, 2020

三大雲平台工具容器升級小記 - 使用 AWS CLI v2 with openSUSE Leap 15.1 Container

三大雲平台工具容器升級小記 - 使用 AWS CLI v2  with openSUSE Leap 15.1 Container

OS: container with openSUSE Leap 15.1

上次升級是 2020/1/5 , 這次會來升級的原因是 

先整理結果

升級前
OS: openSUSE Leap 15.1
awscli:  aws-cli/1.16.310 Python/3.6.9
gcloud: Google Cloud SDK 274.0.1
azure-cli: 2.0.78

升級後
OS: openSUSE Leap 15.1
awscli:  aws-cli/2.0.10 Python/3.7.3
gcloud: Google Cloud SDK 290.0.1
azure-cli: 2.5.1

AWS CLI v2 安裝文件

GCP Cloud SDK 版本



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

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

修改細節
  • Update time
  • 加入 LANG C.UTF-8
  • 不需下載 azure_rm.py , 因為現在是用 plug-in 方式
  • 安裝 unzip 與  AWS CLI v2 
  • Google SDK 版本還有下載的檔案路徑以及檔案名稱


列出 diff 的結果給大家參考


> diff opensuseLeap151_ansible_20200501_Dockerfile opensuseLeap151_ansible_20200105_Dockerfile 

6c6
< # update: 20200501
---
> # update: 20200105
9,12c9
< # Set LANG for UTF-8 - for Chinese
< ENV LANG C.UTF-8
< # Install python3-pip, upgrade pip, ansible[azure]
---
> # Install python2-pip, upgrade pip, ansible[azure]
22,28c19,22
< 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
< # 
---
> 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
40d33
< #### Azure #### 
47,48c40,41
< #install vim tar gzip jq unzip
< RUN zypper install -y vim tar gzip jq unzip
---
> #install vim tar gzip jq
> RUN zypper install -y vim tar gzip jq
51,60c44,47
< #### 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
---
> # Install awscli
> RUN pip3 install awscli
> RUN echo "source /usr/bin/aws_bash_completer" >> /root/.bashrc
62,63c49
< #### GCP ####
< # Install google cloud SDK 290.0.1
---
> # Install google cloud SDK 274.0.1
65,66c51,52
< RUN wget https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-290.0.1-linux-x86_64.tar.gz && \
<   tar zxvf google-cloud-sdk-290.0.1-linux-x86_64.tar.gz && \
---
> RUN wget https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-274.0.1-linux-x86_64.tar.gz && \
>   tar zxvf google-cloud-sdk-274.0.1-linux-x86_64.tar.gz && \






Dockerfile 內容如下

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

# Author
# MAINTAINER 已經棄用, 之後要使用 LABEL 方式
# update: 20200501
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]
RUN zypper install -y python3-pip && \
  pip3 install --upgrade pip && \
  pip3 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

# 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
RUN zypper install -y vim tar gzip jq unzip
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 290.0.1
ENV CLOUDSDK_CORE_DISABLE_PROMPTS 1
RUN wget https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-290.0.1-linux-x86_64.tar.gz && \
  tar zxvf google-cloud-sdk-290.0.1-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:20200501  -f  ./opensuseLeap151_ansible_20200501_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:20200105  /bin/bash

測試結果 OK, 建立  tag

觀察資訊
> docker  images

REPOSITORY                   TAG                 IMAGE ID            CREATED              SIZE
sakana/ansible_opensuse151   20200501            c8899a7046f8        About a minute ago   1.32GB
sakana/ansible_opensuse151   latest              3d76040b20fb        6 weeks ago          1.19GB
opensuse/leap                15.1                fef5ad254f63        2 months ago         103MB

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

登入 docker
> docker  login

上傳 image
> docker  push  sakana/ansible_opensuse151:20200501

> 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:

沒有留言: