Skip to content

Commit

Permalink
refactoring for serverless
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiocicerchia committed Jun 17, 2021
1 parent 5520706 commit dd2e8aa
Show file tree
Hide file tree
Showing 17 changed files with 136 additions and 341 deletions.
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

###> docker ###
REDIS_HOST=redis
PHPFPM_HOST=php
PHPFPM_CANARY_HOST=php
PHPFPM_HOST=phpfpm
PHPFPM_CANARY_HOST=phpfpm
RESOLVER_IP=127.0.0.11
DARK_CANARY_THRESHOLD=0 # 0%
ENABLE_CW=0
Expand Down
28 changes: 13 additions & 15 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
version: '3.8'

services:
webserver:
image: bref/fpm-dev-gateway
container_name: badge-poser-bref
nginx:
build:
context: .
dockerfile: sys/docker/alpine-nginx/Dockerfile
network: host
container_name: badge-poser-nginx
env_file:
- ./.env
- ./.env.local
depends_on:
- php
- phpfpm
deploy:
resources:
limits:
cpus: '0.25'
memory: 128M
env_file:
- ./.env
- ./.env.local
environment:
- ENABLE_CW=0
ports:
- 8001:80
volumes:
- .:/var/task
environment:
HANDLER: public/index.php
DOCUMENT_ROOT: public

php:
# image: bref/php-80-fpm-dev
phpfpm:
build:
context: .
#dockerfile: sys/docker/alpine-phpfpm/Dockerfile
dockerfile: sys/docker/Dockerfile
dockerfile: sys/docker/bref-phpfpm/Dockerfile
network: host
container_name: badge-poser-php
container_name: badge-poser-phpfpm
volumes:
- .:/var/task:ro
depends_on:
Expand Down
24 changes: 1 addition & 23 deletions sys/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ aws ecr get-login-password --profile badge-poser | docker login --password-stdin
VER=$(date +%s);
docker build -t $ACCOUNT.dkr.ecr.eu-west-1.amazonaws.com/badge-poser:nginx-$VER -f sys/docker/alpine-nginx/Dockerfile .
docker build -t $ACCOUNT.dkr.ecr.eu-west-1.amazonaws.com/badge-poser:phpfpm-$VER -f sys/docker/alpine-phpfpm/Dockerfile .
docker build -t $ACCOUNT.dkr.ecr.eu-west-1.amazonaws.com/badge-poser:phpfpm-$VER -f sys/docker/bref-phpfpm/Dockerfile .
docker push $ACCOUNT.dkr.ecr.eu-west-1.amazonaws.com/badge-poser:nginx-$VER
docker push $ACCOUNT.dkr.ecr.eu-west-1.amazonaws.com/badge-poser:phpfpm-$VER
Expand All @@ -45,25 +45,3 @@ docker-compose up
npm install artillery
./node_modules/.bin/artillery run sys/docker/artillery.yml
```


# COMPILE BREF

## BREF

```
cd runtime
cd base ; docker build --file php-74.Dockerfile -t bref/build-php-74 --target build-environment .
cd base ; docker build --file php-74.Dockerfile -t bref/tmp/cleaned-build-php-74 .
cd layers/function ; docker build -t bref/php-74 --build-arg PHP_VERSION=74 .
cd layers/fpm ; docker build -t bref/php-74-fpm --build-arg PHP_VERSION=74 .
cd layers/fpm ; docker build -t fabiocicerchia/bref-php-74-fpm --build-arg PHP_VERSION=74 .
cd layers/fpm-dev ; docker build -t bref/php-74-fpm-dev --build-arg PHP_VERSION=74 .
cd layers/fpm-dev ; docker build -t fabiocicerchia/bref-php-74-fpm-dev --build-arg PHP_VERSION=74 .
```

## BREF-EXTRA

```
cd layers/gd; docker build -t fabiocicerchia/bref-extra-gd-php-74 . --build-arg PHP_VERSION=74
```
4 changes: 2 additions & 2 deletions sys/cloudformation/stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,9 @@ Resources:
ContainerDefinitions:
- Name: 'phpfpm'
PortMappings:
- HostPort: 9000
- HostPort: 9001
Protocol: tcp
ContainerPort: 9000
ContainerPort: 9001
Environment:
- Name: APP_ENV
Value: !Ref EnvAPPENV
Expand Down
8 changes: 0 additions & 8 deletions sys/docker/Dockerfile

This file was deleted.

2 changes: 1 addition & 1 deletion sys/docker/alpine-nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM fabiocicerchia/nginx-lua:1.19.4-alpine3.12.1
FROM fabiocicerchia/nginx-lua:1.21.0-alpine3.13.5

ENV RUN_IN_CONTAINER="True"

Expand Down
67 changes: 0 additions & 67 deletions sys/docker/alpine-phpfpm/Dockerfile

This file was deleted.

27 changes: 27 additions & 0 deletions sys/docker/bref-phpfpm/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM bref/php-80-fpm-dev

ENV LD_LIBRARY_PATH=/opt/bref/lib64:/opt/bref/lib

COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer
COPY --from=bref/extra-gd-php-80 /opt /opt
COPY --from=bref/extra-imagick-php-80 /opt /opt
COPY --from=bref/extra-redis-php-80 /opt /opt
COPY --from=bref/extra-yaml-php-80 /opt /opt
COPY --from=awsbuilder /tmp /tmp
COPY --from=awsbuilder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=awsbuilder /opt/aws/amazon-cloudwatch-agent /opt/aws/amazon-cloudwatch-agent
COPY sys/php/php.ini /opt/bref/etc/php/php.ini
COPY sys/php/docker-php-ext-opcache8.ini /opt/bref/etc/php/conf.d/ext-opcache.ini
COPY sys/php/php-fpm.conf /opt/bref/etc/php-fpm.conf.default
COPY sys/php/www.conf /opt/bref/etc/php-fpm.d/www.conf.default

COPY . /var/task

WORKDIR /var/task

RUN /usr/local/bin/composer install --optimize-autoloader --no-ansi --no-interaction --no-progress \
&& php-fpm -t \
&& php-fpm -tt

ENTRYPOINT ["/var/task/sys/docker/bref-phpfpm/start.sh"]
CMD /opt/bin/php-fpm --nodaemonize --fpm-config /opt/bref/etc/php-fpm.conf -d opcache.validate_timestamps=1 --force-stderr
File renamed without changes.
8 changes: 4 additions & 4 deletions sys/nginx/default.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ server {
listen 80;
server_name poser.pugx.org poser.packagist.org poser.local stg.poser.pugx.org;

root /application/public;
root /var/task/public;

if ($request_uri ~ "/dark-canary/") { set $skip_cache 1; }

Expand Down Expand Up @@ -75,15 +75,15 @@ server {
return string.gsub(ngx.var.document_uri, "/dark%-canary", "")
}

fastcgi_pass ${PHPFPM_CANARY_HOST}:9000;
fastcgi_pass ${PHPFPM_CANARY_HOST}:9001;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
include fastcgi_params;
fastcgi_param REQUEST_URI $request_url;
fastcgi_param DOCUMENT_URI $document_url;
fastcgi_param SCRIPT_NAME /index.php;
fastcgi_param SCRIPT_FILENAME /application/public/index.php;
fastcgi_param SCRIPT_FILENAME /var/task/public/index.php;
fastcgi_param DOCUMENT_ROOT $realpath_root;
}

Expand Down Expand Up @@ -118,7 +118,7 @@ server {

# local = phpfpm
# aws = 127.0.0.1
fastcgi_pass ${PHPFPM_HOST}:9000;
fastcgi_pass ${PHPFPM_HOST}:9001;

fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
Expand Down
4 changes: 0 additions & 4 deletions sys/php.ini

This file was deleted.

131 changes: 0 additions & 131 deletions sys/php/docker-php-ext-opcache.ini

This file was deleted.

3 changes: 0 additions & 3 deletions sys/php/docker-php-ext-opcache8.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
; Enable Zend OPcache extension module
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20200930/opcache.so

; Determines if Zend OPCache is enabled
opcache.enable=1

Expand Down
Loading

0 comments on commit dd2e8aa

Please sign in to comment.