Skip to content

Commit

Permalink
Docker image for layer generation and dev purpose
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume-Rossignol committed Jul 12, 2019
1 parent 85f4a73 commit 6e22cf4
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 34 deletions.
30 changes: 7 additions & 23 deletions runtime/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,14 @@ compiler: compiler.Dockerfile
# Compile PHP and its extensions
build: compiler
docker build -f ${PWD}/php-intermediary.Dockerfile -t bref/php-72-intermediary:latest $(shell helpers/docker_args.sh versions.ini php72) .
cd layers/fpm ; docker build -f ${PWD}/layers/fpm/Dockerfile -t bref/php-72-fpm:latest --build-arg LAYER_IMAGE=bref/php-72-intermediary:latest . ; cd ../..
cd layers/function ; docker build -f ${PWD}/layers/function/Dockerfile -t bref/php-72:latest --build-arg LAYER_IMAGE=bref/php-72-intermediary:latest . ; cd ../..
cd layers/fpm ; docker build -t bref/php-72-fpm:latest --build-arg LAYER_IMAGE=bref/php-72-intermediary:latest . ; cd ../..
cd layers/fpm-dev ; docker build -t bref/php-72-fpm-dev:latest --build-arg LAYER_IMAGE=bref/php-72-intermediary:latest . ; cd ../..
cd layers/function ; docker build -t bref/php-72:latest --build-arg LAYER_IMAGE=bref/php-72-intermediary:latest . ; cd ../..
docker build -f ${PWD}/php-intermediary.Dockerfile -t bref/php-73-intermediary:latest $(shell helpers/docker_args.sh versions.ini php73) .
cd layers/fpm ; docker build -f ${PWD}/layers/fpm/Dockerfile -t bref/php-73-fpm:latest --build-arg LAYER_IMAGE=bref/php-73-intermediary:latest . ; cd ../..
cd layers/function ; docker build -f ${PWD}/layers/function/Dockerfile -t bref/php-73:latest --build-arg LAYER_IMAGE=bref/php-73-intermediary:latest . ; cd ../..

# Export the compiled PHP artifacts into zip files that can be uploaded as Lambda layers
distribution: build
# Run the export script for PHP 7.2
docker run --rm \
--env PHP_SHORT_VERSION=72 \
--volume ${PWD}/layers:/layers:ro \
--volume ${PWD}/export:/export \
--volume ${PWD}/export.sh:/export.sh:ro \
bref/php-72:latest \
/export.sh
# Run the export script for PHP 7.3
docker run --rm \
--env PHP_SHORT_VERSION=73 \
--volume ${PWD}/layers:/layers:ro \
--volume ${PWD}/export:/export \
--volume ${PWD}/export.sh:/export.sh:ro \
bref/php-73:latest \
/export.sh
cd layers/fpm ; docker build -t bref/php-73-fpm:latest --build-arg LAYER_IMAGE=bref/php-73-intermediary:latest . ; cd ../..
cd layers/fpm-dev ; docker build -t bref/php-73-fpm-dev:latest --build-arg LAYER_IMAGE=bref/php-73-intermediary:latest . ; cd ../..
cd layers/function ; docker build -t bref/php-73:latest --build-arg LAYER_IMAGE=bref/php-73-intermediary:latest . ; cd ../..
cd layers/web; docker build -t bref/web:latest . ; cd ../..

publish: build
docker push bref/php-72:latest
Expand Down
2 changes: 1 addition & 1 deletion runtime/compiler.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# https://docs.aws.amazon.com/lambda/latest/dg/current-supported-versions.html
# AWS has kindly provided us with it as a base docker image.
# https://github.com/aws/amazon-linux-docker-images/tree/2017.03
FROM amazonlinux:2017.03
FROM amazonlinux:2
LABEL authors="Bubba Hines <[email protected]>"
LABEL vendor1="Signature Tech Studio, Inc."
LABEL vendor2="bref"
Expand Down
9 changes: 3 additions & 6 deletions runtime/layers/fpm-dev/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
ARG LAYER_IMAGE=bref/php-73:latest
ARG LAYER_IMAGE
FROM $LAYER_IMAGE

WORKDIR /opt/bin
COPY ./php-fpm.conf /opt/bref/etc/php-fpm.conf
EXPOSE 9000

COPY ./local/php-fpm.conf /opt/bref/etc/php-fpm.conf

CMD [ "php-fpm", "-F", "-y", "/opt/bref/etc/php-fpm.conf" ]
CMD /opt/bin/php-fpm -F -y /opt/bref/etc/php-fpm.conf
2 changes: 1 addition & 1 deletion runtime/layers/fpm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ COPY bootstrap bootstrap
COPY php.ini bref/etc/php/conf.d/bref.ini
COPY php-fpm.conf bref/etc/php-fpm.conf

FROM lambci/lambda:provided
FROM lambci/lambda:build-provided

WORKDIR /
COPY --from=0 /opt /opt
2 changes: 1 addition & 1 deletion runtime/layers/function/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ WORKDIR /opt
COPY bootstrap bootstrap
COPY php.ini bref/etc/php/conf.d/bref.ini

FROM lambci/lambda:provided
FROM lambci/lambda:build-provided

WORKDIR /
COPY --from=0 /opt /opt
4 changes: 4 additions & 0 deletions runtime/layers/web/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM nginx:latest
COPY default.conf /etc/nginx/conf.d/default.conf

CMD sed -i "s|##DOCUMENT_ROOT##|$DOCUMENT_ROOT|g" /etc/nginx/conf.d/default.conf;sed -i "s|##HANDLER##|$HANDLER|g" /etc/nginx/conf.d/default.conf&& cat /etc/nginx/conf.d/default.conf&& nginx -g "daemon off;"
14 changes: 14 additions & 0 deletions runtime/layers/web/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
server {
server_name php-docker.local;
root /var/task/##DOCUMENT_ROOT##;

# Allow /src/index.php and src/test.php. This two routes should be in the .stack.yaml
location = / {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
include fastcgi_params;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /var/task/##HANDLER##;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
3 changes: 1 addition & 2 deletions runtime/php-intermediary.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ RUN mkdir -p ${BUILD_DIR} \
# - php
# Used By:
# - xml2
ARG plop
ARG zlib
ENV VERSION_ZLIB=${zlib}
ENV ZLIB_BUILD_DIR=${BUILD_DIR}/xml2
Expand Down Expand Up @@ -479,7 +478,7 @@ RUN ln -s /opt/bref/sbin/* /opt/bin

# Now we get rid of everything that is unnecessary. All the build tools, source code, and anything else
# that might have created intermediate layers for docker. Back to base AmazonLinux we started with.
FROM amazonlinux:2017.03
FROM amazonlinux:2
ENV INSTALL_DIR="/opt/bref"
ENV PATH="/opt/bin:${PATH}" \
LD_LIBRARY_PATH="${INSTALL_DIR}/lib64:${INSTALL_DIR}/lib"
Expand Down

0 comments on commit 6e22cf4

Please sign in to comment.