如何在高山上安装 aws-cli?

我正在安装 aws-cli 在一个运行高山系统(Linux 0317632a4ad94.9.59-moby # 1 SMP Thu Mar 120:54:00 UTC 2018 x86 _ 64 Linux)的 Docker 群管理器节点上。用于 Alpine 的 aws-cli 包目前在 edge 分支(1.18.55)的社区 repo 中列出。R0).我修改了 /etc/apk/repositories目标是这个回购。

在寻找 py3-urllib3时,安装失败了,但我绕过了这个问题,最终得到了一个干净的安装,没有任何错误,如下所示:

  ~ $ sudo apk add aws-cli@edge-comm
fetch http://dl-cdn.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz
ERROR: unsatisfiable constraints:
py3-urllib3-1.25.9-r0:
masked in: @edge
satisfies: py3-botocore-1.16.12-r0[py3-urllib3<1.26]


~ $ sudo apk add py3-urllib3@edge aws-cli@edge-comm
(1/23) Installing groff (1.22.3-r1)
(2/23) Installing py3-six (1.10.0-r6)
(3/23) Installing py3-dateutil (2.6.0-r1)
(4/23) Installing libpng (1.6.37-r0)
(5/23) Installing freetype (2.7.1-r2)
(6/23) Installing libjpeg-turbo (1.5.3-r2)
(7/23) Installing lcms2 (2.8-r1)
(8/23) Installing openjpeg (2.3.0-r2)
(9/23) Installing tiff (4.0.10-r0)
(10/23) Installing libwebp (0.6.0-r0)
(11/23) Installing py3-pillow (4.1.0-r0)
(12/23) Installing py3-roman (2.0.0-r2)
(13/23) Installing py3-docutils (0.13.1-r0)
(14/23) Installing py3-jmespath@edge-comm (0.9.5-r0)
(15/23) Installing py3-urllib3@edge (1.25.9-r0)
(16/23) Installing py3-botocore@edge-comm (1.16.12-r0)
(17/23) Installing py3-s3transfer@edge-comm (0.3.3-r0)
(18/23) Installing py3-colorama@edge-comm (0.4.3-r0)
(19/23) Installing yaml (0.1.7-r0)
(20/23) Installing py3-yaml (3.12-r1)
(21/23) Installing py3-asn1 (0.2.3-r0)
(22/23) Installing py3-rsa (3.4.2-r1)
(23/23) Installing aws-cli@edge-comm (1.18.55-r0)
Executing busybox-1.26.2-r11.trigger
OK: 576 MiB in 81 packages

二进制文件是在/usr/bin/aws 上创建的,但是在寻找 awscli 模块时崩溃了:

~ $ aws
Traceback (most recent call last):
File "/usr/bin/aws", line 19, in <module>
import awscli.clidriver
ModuleNotFoundError: No module named 'awscli'

谢谢!

87838 次浏览

对于任何谷歌这个的人来说, 我一直在使用图像 node:12.16.1-alpine

RUN apk add --no-cache \
python3 \
py3-pip \
&& pip3 install --upgrade pip \
&& pip3 install --no-cache-dir \
awscli \
&& rm -rf /var/cache/apk/*


RUN aws --version   # Just to make sure its installed alright


# Should output aws-cli/1.18.69 etc.

我觉得挺好的。

注意 : apk --no-cachepip3 --no-cache-dir通过不保留包缓存来保持 Docker 映像的精简。

尽管使用的是 AmazonLinux2而不是 Alpine,但亚马逊在 Docker hub 上发布了一个官方的 AWS-CLI 图像。不过我还是建议你使用它。

参考文献: Https://hub.docker.com/r/amazon/aws-cli

是 DockerFile: Https://github.com/aws/aws-cli/blob/v2/docker/dockerfile

FROM amazonlinux:2 as installer
COPY awscli-exe-linux-x86_64.zip .
RUN yum update -y \
&& yum install -y unzip \
&& unzip awscli-exe-linux-x86_64.zip \
# The --bin-dir is specified so that we can copy the
# entire bin directory from the installer stage into
# into /usr/local/bin of the final stage without
# accidentally copying over any other executables that
# may be present in /usr/local/bin of the installer stage.
&& ./aws/install --bin-dir /aws-cli-bin/


FROM amazonlinux:2
RUN yum update -y \
&& yum install -y less groff \
&& yum clean all
COPY --from=installer /usr/local/aws-cli/ /usr/local/aws-cli/
COPY --from=installer /aws-cli-bin/ /usr/local/bin/
WORKDIR /aws
ENTRYPOINT ["/usr/local/bin/aws"]

扩展和更新@Rose (4317383)的回答(并获得 awscli 版本2) :

由于 musl/non-glibc alpine 实现,常规 pip3数据包(pip3 install awscliv2 && awscliv2 -i)出现以下错误:

Error relocating /root/.awscliv2/binaries/aws: __strcat_chk: symbol not found
Error relocating /root/.awscliv2/binaries/aws: __snprintf_chk: symbol not found
Error relocating /root/.awscliv2/binaries/aws: __vfprintf_chk: symbol not found
Error relocating /root/.awscliv2/binaries/aws: __strdup: symbol not found
Error relocating /root/.awscliv2/binaries/aws: __stpcpy_chk: symbol not found
Error relocating /root/.awscliv2/binaries/aws: __vsnprintf_chk: symbol not found
Error relocating /root/.awscliv2/binaries/aws: __strncpy_chk: symbol not found
Error relocating /root/.awscliv2/binaries/aws: __strcpy_chk: symbol not found
Error relocating /root/.awscliv2/binaries/aws: __fprintf_chk: symbol not found
Error relocating /root/.awscliv2/binaries/aws: __strncat_chk: symbol not found

毫无疑问,GLIBC 是必要的,但 如果您愿意投资 ~ 100MB 的空间,或者您确实需要 v2,下面的片段将有所帮助

RUN apk --no-cache add \
binutils \
curl \
&& GLIBC_VER=$(curl -s https://api.github.com/repos/sgerrand/alpine-pkg-glibc/releases/latest | grep tag_name | cut -d : -f 2,3 | tr -d \",' ') \
&& curl -sL https://raw.githubusercontent.com/sgerrand/alpine-pkg-glibc/master/sgerrand.rsa.pub -o /etc/apk/keys/sgerrand.rsa.pub \
&& curl -sLO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VER}/glibc-${GLIBC_VER}.apk \
&& curl -sLO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VER}/glibc-bin-${GLIBC_VER}.apk \
&& apk add --no-cache \
glibc-${GLIBC_VER}.apk \
glibc-bin-${GLIBC_VER}.apk \
&& curl -sL https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip -o awscliv2.zip \
&& unzip awscliv2.zip \
&& aws/install \
&& rm -rf \
awscliv2.zip \
aws \
/usr/local/aws-cli/v2/*/dist/aws_completer \
/usr/local/aws-cli/v2/*/dist/awscli/data/ac.index \
/usr/local/aws-cli/v2/*/dist/awscli/examples \
&& apk --no-cache del \
binutils \
curl \
&& rm glibc-${GLIBC_VER}.apk \
&& rm glibc-bin-${GLIBC_VER}.apk \
&& rm -rf /var/cache/apk/*


RUN awsv2 --version   # Just to make sure its installed alright

如果您的脚本没有与名为 awscli 的 awscliv2中断,您可以添加:

RUN ln -s $(which awscliv2) /usr/bin/aws
RUN apk update \
&& apk --no-cache add curl \
&& apk --no-cache add unzip \
&& curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" \
&& unzip awscliv2.zip \
&& ./aws/install

你可以使用在我看来阿尔卑斯山不支持 aws cli V2

RUN apk add --no-cache \
python3 \
py3-pip \
&& pip3 install --upgrade pip \
&& pip3 install --no-cache-dir \
awscli \
&& rm -rf /var/cache/apk/*

我一直在使用图像 node:14-alpine

apk add --update --no-cache curl ca-certificates \
&& curl -sL -o /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub \
&& curl -sL -o glibc-2.28-r0.apk https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.28-r0/glibc-2.28-r0.apk \
&& apk add glibc-2.28-r0.apk \
&& curl -sL -o glibc-bin-2.28-r0.apk https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.28-r0/glibc-bin-2.28-r0.apk \
&& apk add glibc-bin-2.28-r0.apk \
&& curl -sL -o awscliv2.zip https://awscli.amazonaws.com/awscli-exe-linux-x86_64-2.0.30.zip \
&& unzip awscliv2.zip \
&& ./aws/install \
&& rm -Rf aws/ awscliv2.zip glibc-2.28-r0.apk glibc-bin-2.28-r0.apk \
&& aws --version

在通用 Linux 的官方 awscliv2安装页面上发布的方法在 Alpine 上可以很好地工作。

RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && \
unzip ./awscliv2.zip && \
rm -f ./awscliv2.zip && \
./aws/install -i /usr/local/aws -b /bin && \
rm -rf ./aws

只要清理您的压缩文件和剩余的安装文件。

Https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html

我们现在有 Aws-cli阿尔卑斯包。所以你可以只是运行

apk add --no-cache aws-cli

解决方案

这就是你们要找的。

https://github.com/robertd/alpine-aws-cdk/blob/master/Dockerfile.v2

它与 Alpine 和 AWS CLI v2一起工作。

罗伯特 · 朱拉萨”的学分

如果你使用阿尔卑斯山最新的图片,那么这总是为我工作

- apt update && apt install curl zip jq -y
# install aws cli
- curl -sL https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip -o awscliv2.zip && unzip -q awscliv2.zip && aws/install && rm -rf awscliv2.zip aws /usr/local/aws-cli/v2/*/dist/aws_completer /usr/local/aws-cli/v2/*/dist/awscli/data/ac.index /usr/local/aws-cli/v2/*/dist/awscli/examples
# verify aws cli installation
- aws --version

昨天,我花了相当长的时间来研究如何为 ci 管道构建一个苗条的 aws-cli v2映像(因此会删除自动完成和示例) ,这个映像不会受到 symbol not found问题的影响。

在安装 glibc 2.35-r0包之后,symlink/lib64/ld-linux-x86-64。所以。2仍然指向 musl 版本的库,而不是 glibc 版本。在 glibc 2.34-r0中,符号链接被正确地替换了,所以我假设它是2.35-r0中的 bug。

这是我用来构建 aws-cli 2.7.33镜像的多阶段 Dockerfile:

FROM alpine:3.16.2 as base
ENV GLIBC_VER=2.35-r0


RUN set euo pipefail; \
apk --no-cache add curl; \
curl --silent --location https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub --output /etc/apk/keys/sgerrand.rsa.pub; \
curl --silent --location --remote-name https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VER}/glibc-${GLIBC_VER}.apk; \
curl --silent --location --remote-name https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VER}/glibc-bin-${GLIBC_VER}.apk; \
curl --silent --location --remote-name https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VER}/glibc-i18n-${GLIBC_VER}.apk; \
apk --no-cache add \
glibc-${GLIBC_VER}.apk \
glibc-bin-${GLIBC_VER}.apk \
glibc-i18n-${GLIBC_VER}.apk; \
# optional: add if needed, will add ~10mb to the final image
#/usr/glibc-compat/bin/localedef -i en_US -f UTF-8 en_US.UTF-8; \
# replace symlink to point to glibc version instead of musl version
ln -sf /usr/glibc-compat/lib/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2; \
apk --no-cache del curl glibc-i18n; \
rm -rf \
/var/cache/apk/* \
/etc/apk/keys/sgerrand.rsa.pub \
glibc*${GLIBC_VER}.apk


FROM base as builder
ARG AWS_CLI_VERSION=2.7.33
RUN set euo pipefail; \
apk --no-cache add curl; \
curl --silent --location --remote-name https://awscli.amazonaws.com/awscli-exe-linux-x86_64-${AWS_CLI_VERSION}.zip; \
unzip -q awscli-exe-linux-x86_64-${AWS_CLI_VERSION}.zip; \
aws/install; \
aws --version; \
rm -rf \
awscli-exe-linux-x86_64-${AWS_CLI_VERSION}.zip \
aws \
/usr/local/aws-cli/v2/*/bin/aws_completer \
/usr/local/aws-cli/v2/*/dist/aws_completer \
/usr/local/aws-cli/v2/*/dist/awscli/data/ac.index \
/usr/local/aws-cli/v2/*/dist/awscli/examples; \
apk --no-cache del \
binutils \
curl; \
rm -rf /var/cache/apk/*


FROM base
COPY --from=builder /usr/local/aws-cli/ /usr/local/aws-cli/
RUN ln -sf /usr/local/aws-cli/v2/current/bin/aws /usr/local/bin/aws
ENTRYPOINT ["aws"]