Aws-sam-cli: Publish Docker image of AWS SAM CLI

Created on 28 Nov 2018  路  4Comments  路  Source: aws/aws-sam-cli

Description:
Feature request from the Twitter thread. Publishing our own docker image for SAM CLI can help customers use it without installing separately on a CI/CD pipeline or locally. They can do docker run sam-cli-image deploy. Docker-in-Docker will be needed to enable sam local commands. But Docker images will certainly be another good distribution mechanism.

typfeature

Most helpful comment

I use something like this:

FROM alpine:3.8

ENV LANG C.UTF-8

ENV HOME /tmp

RUN apk add --no-cache python py-pip && \
    apk add --no-cache gcc python-dev musl-dev && \
    pip --disable-pip-version-check install \
        boto3 botocore awscli aws-sam-cli && \
    apk -v --purge --no-cache del gcc python-dev musl-dev

RUN apk add --no-cache docker bash

All 4 comments

I use something like this:

FROM alpine:3.8

ENV LANG C.UTF-8

ENV HOME /tmp

RUN apk add --no-cache python py-pip && \
    apk add --no-cache gcc python-dev musl-dev && \
    pip --disable-pip-version-check install \
        boto3 botocore awscli aws-sam-cli && \
    apk -v --purge --no-cache del gcc python-dev musl-dev

RUN apk add --no-cache docker bash

sam init

docker run --rm -it \
    -v $PWD:$PWD:Z \
    -w $PWD \
    -u=$UID:$(id -g) \
    sam-cli-image sam init

sam local

docker run --rm -it \
    -e "AWS_DEFAULT_REGION=us-east-1" \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -v $PWD:$PWD:ro,Z \
    -w $PWD \
    -p 3000:3000 \
    sam-cli-image sam local start-api --host 0.0.0.0

P.S. If you use selinux you can add the z or Z options to modify the selinux label of the host file or directory being mounted into the container. This affects the file or directory on the host machine itself and can have consequences outside of the scope of Docker.

Considering that many (most? well, me at least...) folks will be using CodeBuild as their starting point for deploying apps with SAM, I think this would do a lot to smooth out onboarding with SAM.

could you also publish an image per language? most modern CI/CD systems run builds inside of containers so this would prevent the need for docker in docker- you could just get the right sam image for your language

I assume you already have an image per language because of the --use-container switch right? wouldnt you just have to add the sam cli to those images if its not in there already?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

goldenbearkin picture goldenbearkin  路  3Comments

jpbarto picture jpbarto  路  4Comments

zhangzhx picture zhangzhx  路  3Comments

cmccoypdx picture cmccoypdx  路  3Comments

Caian picture Caian  路  3Comments