Skip to content

Commit a05a7b5

Browse files
committed
Share code between amazon-linux:1 and amazon-linux:2 images
1 parent 5dd9524 commit a05a7b5

File tree

13 files changed

+128
-158
lines changed

13 files changed

+128
-158
lines changed

Amazon Linux/Dockerfile

Lines changed: 0 additions & 74 deletions
This file was deleted.

Amazon Linux/cmd.sh

Lines changed: 0 additions & 10 deletions
This file was deleted.

Amazon Linux/usr/local/bin/change-uid

Lines changed: 0 additions & 32 deletions
This file was deleted.

README.md

100644100755
Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ deploy it in Amazon Lambda. Building serverless applications, it is ironic to be
1010

1111
This docker image is based on the [Amazon Linux](https://hub.docker.com/_/amazonlinux/) image and contains `gcc`.
1212

13-
The AWS lambda [runtimes](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html) are now split between `Amazon Linux` and `Amazon Linux 2` execution environments.
13+
The docker image `myrmex/lambda-packager:1` contains `python 2.7`, `python 3.6`, `python 3.7`, `pip`, `node 6.10`, `node 8.10` to create packages for Amazon Lambda.
1414

15-
The docker image for `Amazon Linux` now contains `python 2.7`, `python 3.6`, `python 3.7`, `pip`, `node 6.10`, `node 8.10` to create packages for Amazon Lambda.
16-
17-
The docker image for `Amazon Linux 2` now contains `node 10.15` to create packages for Amazon Lambda.
15+
The docker image for `myrmex/lambda-packager:2` contains `node 10.16` to create packages for Amazon Lambda.
1816

1917
Using the docker images from `myrmex/lambda-packager`, you can avoid errors like these during execution in Amazon Lambda:
2018

@@ -26,39 +24,27 @@ Using the docker images from `myrmex/lambda-packager`, you can avoid errors like
2624
Module version mismatch. Expected 46, got 48.
2725
```
2826

29-
## Building
30-
31-
To build the required images standard `Dockerfile` have been included one for `Amazon Linux` and another for `Amazon Linux 2`.
32-
33-
To build the `Amazon Linux` image that supports node 6.10, node 8.10, python 2.7, python 3.6 and python 3.7
34-
35-
```bash
36-
cd Amazon\ Linux
37-
docker build -t myrmex/lambda-packager .
38-
```
39-
40-
To build the `Amazon Linux 2` image that supports node 10.15
41-
42-
```bash
43-
cd Amazon\ Linux\ 2
44-
docker build -t myrmex/lambda-packager:amazonlinux2 .
45-
```
46-
4727
## Usage
4828

4929
You can use a docker volume to mount the code of the Lambda in a container. The directory where `npm install` or
50-
`pip install` is executed inside the container is `/data`. By default, the installation will be performed for node
51-
6.10.
30+
`pip install` is executed inside the container is `/data`. By default, the installation will be performed for node.
5231

5332
```bash
54-
docker run -v `pwd`:/data myrmex/lambda-packager
33+
docker run -v `pwd`:/data myrmex/lambda-packager:1
5534
```
5635

5736
The image does not create the zip archive for your. It only installs the dependencies in an environment compatible with
5837
Lambda. You will still have to zip the result and deploy it in Amazon Lambda.
5938

6039
For a node package, take care that `node_module` does not already exist before running the command.
6140

41+
## Building images locally
42+
43+
```bash
44+
docker build -t myrmex/lambda-packager:1 -f al1.Dockerfile .
45+
docker build -t myrmex/lambda-packager:2 -f al2.Dockerfile .
46+
```
47+
6248
### Managing permissions
6349

6450
The user account that performs `npm install` or `pip install` inside the container may have a `uid/gid` that differs from the
@@ -74,48 +60,48 @@ docker run -e HOST_UID=`id -u` -e HOST_GID=`id -g` -v `pwd`:/data myrmex/lambda-
7460

7561
The `RUNTIME` environment variable allows to choose the runtime.
7662

77-
### Node 10.15
63+
### Node 10.16
7864

79-
Node 10.15 is the default runtime for `Amazon Linux 2` and does not require any special configuration.
65+
Node 10.16 is the default runtime for `Amazon Linux 2` and does not require any special configuration.
8066

8167
```bash
82-
docker run -v `pwd`:/data myrmex/lambda-packager:amazonlinux2
68+
docker run -v `pwd`:/data myrmex/lambda-packager:2
8369
```
8470

8571
#### Node 8.10
8672

8773
Node 8.10 is the default runtime for `Amazon Linux` and does not require any special configuration.
8874

8975
```bash
90-
docker run -v `pwd`:/data myrmex/lambda-packager
76+
docker run -v `pwd`:/data myrmex/lambda-packager:1
9177
```
9278

9379
#### Node 6.10
9480

9581
```bash
96-
docker run -e RUNTIME=node6 -v `pwd`:/data myrmex/lambda-packager
82+
docker run -e RUNTIME=node6 -v `pwd`:/data myrmex/lambda-packager:1
9783
```
9884

9985
#### Python 3.7
10086

10187
Python 3.7 is the default Python 3 runtime and accepts the values `python3` or `python3.7`
10288

10389
```bash
104-
docker run -e RUNTIME=python3.7 -v `pwd`:/data myrmex/lambda-packager
90+
docker run -e RUNTIME=python3.7 -v `pwd`:/data myrmex/lambda-packager:1
10591
```
10692

10793
#### Python 3.6
10894

10995
```bash
110-
docker run -e RUNTIME=python3.6 -v `pwd`:/data myrmex/lambda-packager
96+
docker run -e RUNTIME=python3.6 -v `pwd`:/data myrmex/lambda-packager:1
11197
```
11298

11399
#### Python 2.7
114100

115101
Accepts the values `python` or `python2`.
116102

117103
```bash
118-
docker run -e RUNTIME=python -v `pwd`:/data myrmex/lambda-packager
104+
docker run -e RUNTIME=python -v `pwd`:/data myrmex/lambda-packager:1
119105
```
120106

121107
### Default command

al1.Dockerfile

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
FROM amazonlinux:1
2+
3+
MAINTAINER Alexis N-o "[email protected]"
4+
5+
ENV DEFAULT_USER=myrmex
6+
ENV NODE_VERSION_6 6.10.3
7+
ENV NODE_VERSION_8 8.10.0
8+
ENV PYTHON_VERSION_3_6 3.6.8
9+
ENV PYTHON_VERSION_3_7 3.7.3
10+
11+
# Install gcc add utilities to manage users and permissions
12+
RUN yum install -y gcc-c++ util-linux shadow-utils zlib-devel openssl-devel libffi-devel
13+
14+
# Add scripts to install node and python versions
15+
COPY /install-node.sh /install-node.sh
16+
COPY /install-python.sh /install-python.sh
17+
18+
# Install node v6 and node v8 as commands "node6" and "node8"
19+
# Command "node" defaults to v8
20+
RUN /install-node.sh ${NODE_VERSION_6} &&\
21+
/install-node.sh ${NODE_VERSION_8}
22+
23+
# Install python 3.6 and python 3.7 including pip, python 2.7 is already available
24+
# Command "python3" defaults to 3.7
25+
RUN curl -O https://bootstrap.pypa.io/get-pip.py &&\
26+
python get-pip.py &&\
27+
/install-python.sh ${PYTHON_VERSION_3_6} &&\
28+
/install-python.sh ${PYTHON_VERSION_3_7}
29+
30+
# Add a script to modify the UID / GID for the default user if needed
31+
COPY /usr/local/bin/change-uid /usr/local/bin/change-uid
32+
RUN chmod +x /usr/local/bin/change-uid
33+
34+
# Add a non root user
35+
RUN useradd $DEFAULT_USER -m -d /home/$DEFAULT_USER/ -s /bin/bash
36+
37+
# Create working directory
38+
RUN mkdir /data && chown $DEFAULT_USER:$DEFAULT_USER /data
39+
WORKDIR /data
40+
41+
# Add entrypoint
42+
COPY /al1.entrypoint.sh /entrypoint.sh
43+
RUN chmod +x /entrypoint.sh
44+
ENTRYPOINT ["/entrypoint.sh"]
45+
46+
# Add default command
47+
COPY /cmd.sh /cmd.sh
48+
RUN chmod +x /cmd.sh
49+
CMD ["/cmd.sh"]
Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,17 @@ FROM amazonlinux:2
33
MAINTAINER Alexis N-o "[email protected]"
44

55
ENV DEFAULT_USER=myrmex
6-
ENV NODE_VERSION_10 10.15.3
6+
ENV NODE_VERSION_10 10.16.3
77

88
# Install gcc add utilities to manage users and permissions
99
RUN yum install -y gcc-c++ util-linux shadow-utils zlib-devel openssl-devel libffi-devel tar
1010

11+
# Add a script to install node versions
12+
COPY /install-node.sh /install-node.sh
13+
1114
# Install node v10
1215
# Command "node" defaults to v10
13-
RUN cd /opt &&\
14-
curl -O https://nodejs.org/dist/v${NODE_VERSION_10}/node-v${NODE_VERSION_10}-linux-x64.tar.gz &&\
15-
tar xvzf node-v${NODE_VERSION_10}-linux-x64.tar.gz &&\
16-
ln -s /opt/node-v${NODE_VERSION_10}-linux-x64/bin/node /usr/local/bin/node10 &&\
17-
ln -s /opt/node-v${NODE_VERSION_10}-linux-x64/bin/node /usr/local/bin/node &&\
18-
ln -s /opt/node-v${NODE_VERSION_10}-linux-x64/bin/npm /usr/local/bin/npm &&\
19-
/opt/node-v${NODE_VERSION_10}-linux-x64/bin/npm install -g npm@4
16+
RUN /install-node.sh ${NODE_VERSION_10}
2017

2118
# Add a script to modify the UID / GID for the default user if needed
2219
COPY /usr/local/bin/change-uid /usr/local/bin/change-uid
@@ -30,7 +27,7 @@ RUN mkdir /data && chown $DEFAULT_USER:$DEFAULT_USER /data
3027
WORKDIR /data
3128

3229
# Add entrypoint
33-
COPY /entrypoint.sh /entrypoint.sh
30+
COPY /al2.entrypoint.sh /entrypoint.sh
3431
RUN chmod +x /entrypoint.sh
3532
ENTRYPOINT ["/entrypoint.sh"]
3633

File renamed without changes.

examples/node/package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "@myrmex/node-packager-example",
3+
"version": "1.0.0",
4+
"description": "A module to test Myrmex Lambda packager",
5+
"main": "index.js",
6+
"dependencies": {
7+
"pebo": "0.0.2"
8+
},
9+
"devDependencies": {},
10+
"scripts": {
11+
"test": "echo \"Error: no test specified\" && exit 1"
12+
},
13+
"author": "",
14+
"license": "ISC"
15+
}

0 commit comments

Comments
 (0)