Skip to content

Commit f152f14

Browse files
committed
Added volume, import of .aws dir, switched to ONBUILD for copy and requirements install
1 parent b547cdd commit f152f14

File tree

5 files changed

+15
-11
lines changed

5 files changed

+15
-11
lines changed

Dockerfile-2.7

+4
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ RUN pip install python-lambda &&\
44
mkdir /lambda
55
COPY bin/* /usr/local/bin/
66
WORKDIR /lambda
7+
ONBUILD COPY . /lambda
8+
ONBUILD RUN pip install -r requirements.txt &&\
9+
if [[ -d .aws ]]; then cd ~; ln -s /lambda/.aws; fi
10+
ONBUILD VOLUME /lambda

Dockerfile-3.6

+5
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,9 @@ FROM python:3.6-alpine
22
LABEL maintainer="Kilna [email protected]"
33
RUN pip install python-lambda &&\
44
mkdir /lambda
5+
COPY bin/* /usr/local/bin/
56
WORKDIR /lambda
7+
ONBUILD COPY . /lambda
8+
ONBUILD RUN pip install -r requirements.txt &&\
9+
if [[ -d .aws ]]; then cd ~; ln -s /lambda/.aws; fi
10+
ONBUILD VOLUME /lambda

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
[![](https://img.shields.io/docker/pulls/kilna/python-lambda.svg?style=plastic)](https://hub.docker.com/r/kilna/python-lambda/)
55
[![](https://img.shields.io/docker/stars/kilna/python-lambda.svg?style=plastic)](https://hub.docker.com/r/kilna/python-lambda/)
66
[![](https://img.shields.io/badge/docker_build-automated-blue.svg?style=plastic)](https://cloud.docker.com/swarm/kilna/repository/docker/kilna/python-lambda/builds)
7-
[![](https://img.shields.io/badge/python-2.7,_3.3,_3.4,_3.5,_3.6-blue.svg?style=plastic)](https://github.com/kilna/python-lambda-docker/)
7+
[![](https://img.shields.io/badge/python-2.7,_3.6-blue.svg?style=plastic)](https://github.com/kilna/python-lambda-docker/)
88

9-
Lightweight docker image for running and packaging python-based AWS lambda code
9+
Lightweight docker image for running, testing, packaging and deploying python-based AWS lambda functions
1010

1111
## Links
1212

@@ -37,7 +37,7 @@ Any time you make changes to the example project, you'll need to re-run the `doc
3737

3838
#### Switching Python Versions
3939

40-
The example [Dockerfile](./example/Dockerfile) uses a _:latest_ docker tag in the FROM line, which is currently the same as _:3.6_, but if you wish to use a different Python version you can change this. Supported Python versions are 2.7, 3.3, 3.4, 3.5, 3.6. To use Python version 2.7 change the first line of the example [Dockerfile](./example/Dockerfile) to:
40+
The example [Dockerfile](./example/Dockerfile) uses a _:latest_ docker tag in the FROM line, which is currently the same as _:3.6_, but if you wish to use a different Python version you can change this. Supported Python versions are 2.7 and 3.6. To use Python version 2.7 change the first line of the example [Dockerfile](./example/Dockerfile) to:
4141

4242
```
4343
FROM kilna/python-lambda:2.7
@@ -92,7 +92,7 @@ Behind the scenes, what this does is:
9292

9393
### Deploying the Lambda Function
9494

95-
You can deploy your lambda function to Amazon's infrastructure... you'll need to add AWS credentials into the [config.yaml](./example/config.yaml) file. Alternately you can credentials into your container by configuring them through the Dockerfile, for example by adding a `COPY .aws /root/.aws` line, where example/.aws/ is a copy of your ~/.aws/ directory. Once AWS is working within your container, you can then run the following to deploy your function to Amazon:
95+
You can deploy your lambda function to Amazon's infrastructure... you'll need to add AWS credentials into the [config.yaml](./example/config.yaml) file. Alternately, if your local AWS CLI environment is working, you can add a _.aws/_ directory (you can `cp ~/.aws`) into the _example/_ directory), then re-build your image. Once AWS is working within your container, you can then run the following to deploy your function to Amazon:
9696

9797
```
9898
$ docker run example-lambda-image lambda deploy

example/Dockerfile

-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
11
FROM kilna/python-lambda:latest
2-
COPY . /lambda
3-
RUN pip install -r requirements.txt

test/test_dockerfiles

+2-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fi
1717
for dockerfile in "${dockerfiles[@]}"; do
1818

1919
ver=$(echo "$dockerfile" | cut -d '-' -f 2)
20-
tag="test-$ver"
20+
tag="$ver-test"
2121
base_image_tag="$base_image:$tag"
2222
example_image_tag="$example_image:$tag"
2323
example_image_tmp="$TMPDIR/$example_image-$tag"
@@ -35,10 +35,7 @@ for dockerfile in "${dockerfiles[@]}"; do
3535
cd $example_image_tmp
3636
sed -i "1s/.*/FROM $base_image_tag/" Dockerfile
3737
sed -i "s/runtime: .*/runtime: python$ver/" config.yaml
38-
if [[ -d ~/.aws ]]; then
39-
cp -rv ~/.aws $example_image_tmp
40-
echo "COPY .aws/ /root/.aws/" >> Dockerfile
41-
fi
38+
test -d ~/.aws && cp -rv ~/.aws $example_image_tmp
4239
set +x
4340

4441
header "Build derived docker - $ver"

0 commit comments

Comments
 (0)