4

Below is the Dockerfile for aws sam:

FROM buildpack-deps:stable
ARG PYTHON_VERSION=3.7.4


# Update and allow for apt over HTTPS
RUN apt-get update && \
  apt-get install -y apt-utils
RUN apt-get install -y apt-transport-https

# download and build Python 3.7, install basic Python libraries
# (this predates pipenv so a mixture of dependencies)
ADD requirements.txt /requirements.txt
RUN cd /usr/src && \
  wget https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz && \
  tar xzf Python-${PYTHON_VERSION}.tgz && \
  cd Python-${PYTHON_VERSION} && \
  ./configure --enable-optimizations && \
  make altinstall && \
  apt-get install -y python3-pip && \
  pip3 install -r /requirements.txt

RUN pip3 install awscli --upgrade --user && \
    pip3 install --user aws-sam-cli

that gave error:

ERROR: Could not find a version that satisfies the requirement serverlessrepo==0.1.5 (from aws-sam-cli) (from versions: 0.1.6, 0.1.7, 0.1.8, 0.1.9)
ERROR: No matching distribution found for serverlessrepo==0.1.5 (from aws-sam-cli)

The command '/bin/sh -c pip3 install awscli --upgrade --user &&     pip3 install --user aws-sam-cli' returned a non-zero code: 1

How to install serverlessrepo version 0.1.5?

overexchange
  • 15,768
  • 30
  • 152
  • 347

2 Answers2

2

SAM CLI supports Python2.7, 3.6, and 3.7 and your docker image come with python3.5. The workaround can be something below or update the base version from your base docker image.

FROM buildpack-deps:stable

# Update and allow for apt over HTTPS
RUN apt-get update && \
  apt-get install -y apt-utils
RUN apt-get install -y apt-transport-https

# Install python3
RUN apt-get update \
  && apt-get install -y python3-pip python3-dev \
  && cd /usr/local/bin \
  && ln -s /usr/bin/python3 python \
  && pip3 install --upgrade pip

RUN pip3 install awscli --upgrade --user 
RUN python --version
RUN apt-get install python-pip  -y
RUN python2.7 -m pip install aws-sam-cli

Update: The base image changed to buildpack-deps:buster

FROM buildpack-deps:buster
# Update and allow for apt over HTTPS
RUN apt-get update && \
  apt-get install -y apt-utils
RUN apt-get install -y apt-transport-https
RUN apt update -y 
RUN apt install python3-pip -y
RUN pip3 install awscli --upgrade --ignore-installed six
RUN python3.7 -m pip install aws-sam-cli
RUN  rm /usr/bin/python
RUN ln -s /usr/bin/python3.7 /usr/bin/python

enter image description here

Adiii
  • 54,482
  • 7
  • 145
  • 148
  • Am looking for python 3.7 dependency. you are using python2.7 to install aws-sam-cli – overexchange Jul 26 '19 at 19:04
  • 1
    I do not want python2 in my image – overexchange Jul 26 '19 at 19:07
  • it seems hard to update python in docker image, there is no repository by default to install, and adding repo is having issue. you can try this image `docker pull praekeltfoundation/alpine-buildpack-deps` its light wright base on alpine and having python3.6 which supported in case – Adiii Jul 26 '19 at 19:48
  • you can change base image, if needed – overexchange Jul 26 '19 at 19:50
  • I do not find `praekeltfoundation/alpine-buildpack-deps` with python 3.6. I see it is 3.8 – overexchange Jul 26 '19 at 19:52
  • yes you can check user `RUN whoami` you can add user as in normal linux we do – Adiii Jul 26 '19 at 20:45
  • I would request you to use alpine image or some other base image... because the size of image is going more than 1GB... did you check that? – overexchange Jul 27 '19 at 05:34
  • yes alpine is much better, I will look into later today – Adiii Jul 27 '19 at 06:28
  • I already looked into it... here is the problem: https://stackoverflow.com/q/57229496/3317808 – overexchange Jul 27 '19 at 06:29
  • okay so then this answer should be considered accepted, So I will follow up you that question – Adiii Jul 27 '19 at 06:30
  • Related question: https://stackoverflow.com/questions/58001628/public-key-is-not-available-no-pubkey-f76221572c52609d and https://stackoverflow.com/questions/58000876/docker-file-master-jenkins-hudson-util-hudsonfailedtoload – overexchange Sep 18 '19 at 23:08
1

It will not work with python3. Check this out.

You need to install either Python2.7, 3.6, or 3.7.

More info here.

Hope this helps.

mchawre
  • 10,744
  • 4
  • 35
  • 57