Docker – Boris blog! http://idesmanb.com Just another boring site Sun, 16 Oct 2022 14:38:56 +0000 en-US hourly 1 https://wordpress.org/?v=6.3.2 http://idesmanb.com/wp-content/uploads/2020/12/cropped-logo-32x32.bmp Docker – Boris blog! http://idesmanb.com 32 32 Atlantis for Terraform with support for automated building of python AWS Lambda Functions [Dockerfile] http://idesmanb.com/2021/02/17/atlantis-terraform-python-lambda-aws/?utm_source=rss&utm_medium=rss&utm_campaign=atlantis-terraform-python-lambda-aws http://idesmanb.com/2021/02/17/atlantis-terraform-python-lambda-aws/#comments Wed, 17 Feb 2021 07:42:23 +0000 http://idesmanb.com/?p=417 Read More »]]> If you look for a way to use Atlantis both to deploy your infrastructure as a code and package and build AWS Lambda Functions with Python I provide you a Dockerfile for that purpose. Some use cases require, that the Terraform repository holds the infra as code and also the actual source code that this infra should execute. In the case of the Lambda functions, that is both the description for a function (how much memory, timeout, IAM role) as well as the actual code that has to be executed. On the other hand python lambda functions has to be built and zipped locally, especially if they contain external libraries, before uploading them to the cloud. That means, the machine, or cluster that runs Atlantis needs Python to perform the task, and that is what the following image gives you: it pulls the original Atlantis image from Docker Hub and on top of that installs Python.

Important: You probably want to include this (or similar) terraform module to build the python packages: https://github.com/claranet/terraform-aws-lambda

Dockerfile:

FROM runatlantis/atlantis:latest
ENV USER atlantis_deploy
RUN adduser -D $USER
ENV HOME /home/$USER
ENV PY_VERSION='3.7.2'
RUN apk add --no-cache --update \
    curl git bash bash-doc bash-completion \
    openssh libffi-dev \
    openssl-dev \
    bzip2-dev zlib-dev zip \
    readline-dev sqlite-dev \
    build-base \
    linux-headers \
    util-linux \
    docker
WORKDIR /home/$USER
# Install Python 3.7 via pyenv
ARG PYENV_HOME=$HOME/.pyenv
RUN git clone --depth 1 https://github.com/pyenv/pyenv.git $PYENV_HOME && \
    rm -rfv $PYENV_HOME/.git
ENV PATH $PYENV_HOME/shims:$PYENV_HOME/bin:$PATH
RUN pyenv install $PY_VERSION
RUN pyenv global $PY_VERSION
RUN pip install --upgrade pip && pyenv rehash
RUN rm -rf ~/.cache/pip
# Install additional software
RUN pip3 install --upgrade awscli pipenv boto3 click ssm-cache

]]>
http://idesmanb.com/2021/02/17/atlantis-terraform-python-lambda-aws/feed/ 1