Skip to content

Commit bd147e3

Browse files
Update README + Finalize Changes
1 parent 251f4a6 commit bd147e3

File tree

6 files changed

+69
-31
lines changed

6 files changed

+69
-31
lines changed

Dockerfile

+3-2
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@ COPY docker/fpm/*.conf /usr/local/etc/php-fpm.d/
6868

6969
COPY docker/entrypoints /usr/local/bin/
7070
COPY docker/healthcheck /usr/local/bin/
71-
COPY docker/post-* /usr/local/bin/
71+
COPY docker/post-build /usr/local/bin/
72+
COPY docker/pre-run /usr/local/bin/
7273
COPY docker/fpm/fpm-healthcheck /usr/local/bin/
73-
RUN chmod +x /usr/local/bin/entrypoint-* /usr/local/bin/post-* /usr/local/bin/healthcheck
74+
RUN chmod +x /usr/local/bin/entrypoint-* /usr/local/bin/post-build /usr/local/bin/pre-run /usr/local/bin/*healthcheck
7475

7576
# ---------------------------------------------------- Composer --------------------------------------------------------
7677

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019 Sherif Abdel-Naby
3+
Copyright (c) 2021 Sherif Abdel-Naby
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Makefile

-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ deploy: ## Deploy Prod Image
1212
${COMPOSE_PREFIX_CMD} docker-compose -f docker-compose.prod.yml up --build -d
1313

1414
up: ## Start service
15-
${COMPOSE_PREFIX_CMD} docker-compose up -d
16-
17-
build-up: ## Start service, rebuild if necessary
1815
${COMPOSE_PREFIX_CMD} docker-compose up --build -d
1916

2017
build: ## Build The Image

README.md

+62-22
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
<p align="center">
2-
<img width="520px" src="https://user-images.githubusercontent.com/16992394/65461542-697e1300-de54-11e9-8e4f-34adcc448747.png">
2+
<img width="520px" src="https://user-images.githubusercontent.com/16992394/116017444-e03a4e00-a63f-11eb-8070-1cdf9fc8678e.png">
33
</p>
4-
<h2 align="center">🐳 A preconfigured, extendable, multistage, PHP Symfony 4.3+ Docker Image for Production and Development</h2>
5-
<p align="center">.</p>
4+
<h2 align="center">🐳 Production Grade, Rootless, Pre-configured, Extendable, and Multistage
5+
6+
PHP Docker Image for Cloud Native Deployments (and Kubernetes)</h2>
7+
8+
<h4 align="center">compatible with popular PHP Frameworks such as <a href="https://laravel.com/">Laravel 5+</a> &amp; <a href="https://symfony.com/">Symfony 4+</a> and their variants.</h4>
9+
610
<p align="center">
711
<a>
812
<img src="https://img.shields.io/github/v/tag/sherifabdlnaby/symdocker?label=release&amp;sort=semver">
@@ -13,9 +17,6 @@
1317
<a>
1418
<img src="https://img.shields.io/badge/PHP-%3E=7-blueviolet" alt="PHP >=7^">
1519
</a>
16-
<a>
17-
<img src="https://img.shields.io/badge/Symfony-4%5E-black" alt="Symfony 4^">
18-
</a>
1920
<a href="https://github.com/sherifabdlnaby/symdocker/network">
2021
<img src="https://img.shields.io/github/forks/sherifabdlnaby/symdocker.svg" alt="GitHub forks">
2122
</a>
@@ -41,27 +42,48 @@ The Image utilizes multistage builds to create multiple targets optimized for **
4142
- Designed to run in orchestrated environments like Kubernetes.
4243
- Multi-Container setup with `Nginx` & `PHP-FPM` communicating via TCP.
4344
- Production Image that are **immutable** and **fully contained** with source code and dependencies inside.
45+
- Configured for graceful shutdowns/restarts, and correctly pass termination signal.
4446
- Multi-stage builds for an optimized cache layers.
4547
- Transparent configuration, all configuration determine app behavior are captured in VCS, such as PHP, FPM, and Nginx Config
4648
- Production configuration with saint defaults tuned for performance.
47-
- Easily extend the image with extra configuration, and scripts; with predictable execution.
48-
- Fast container start time.
49-
- Development Image supports mounting code and hot-reloading.
49+
- Easily extend the image with extra configuration, and scripts; such as post-build & pre-run scripts.
50+
- Fast container start time done by only doing the necessary steps at application start and offload anything else to build.
51+
- Override-able container CMD, used to run PHP Commands, to be used for cron-jobs/consumers.
5052
- Image tries to fail at build time as much as possible by running all sort of checks.
53+
- Default Healtchecks embedded for PHP FPM and Nginx
54+
- Development Image supports mounting code and hot-reloading.
5155

5256
## How to add to my project ?
5357

5458
- Copy this repository`Dockerfile`, `docker` Directory, `Makefile`, and `.dockerignore` to your application root directory and configure it to your needs.
5559

5660
## How to configure image to run my project ?
5761

58-
- You'll need to iterate over your application's dependency system packages, and required PHP Extensions; and add them to their respective locations in the image. (instructions below)
62+
You'll need to iterate over your application's dependency system packages, and required PHP Extensions; and add them to their respective locations in the image.
63+
64+
1. Add System Dependencies and PHP Extensions your application depends on to the Image.
65+
2. Port in any configuration changes you made for PHP.ini to the image, otherwise use the saint defaults.
66+
3. `make build && make up` for development setup, `make deploy` to run the production variant.
67+
68+
These steps explained in details below.
69+
70+
## How is it deployed ?
71+
72+
<img src="https://user-images.githubusercontent.com/16992394/116017065-dd8b2900-a63e-11eb-917e-6b04a4e6e89b.png">
73+
74+
Your application will be split into two components.
75+
76+
1. **The Webserver** -> Server Static Content and proxy dynamic requests to PHP-FPM over TCP, webserver also applies rate limiting, security headers... and whatever it is configured for.
77+
2. **The PHP Process** -> PHP FPM process that will run you PHP Code.
78+
79+
> Other type of deployments such as a cron-job, or a supervised consumer can be achieved by overriding the default image CMD.
5980
6081
-----
82+
6183
# Requirements
6284

6385
- [Docker 20.05 or higher](https://docs.docker.com/install/)
64-
- [Docker-Compose 3.5 or higher](https://docs.docker.com/compose/install/) (optional)
86+
- [Docker-Compose 3.7 or higher](https://docs.docker.com/compose/install/) (optional)
6587
- PHP >= 7 Application
6688

6789
# Setup
@@ -146,27 +168,45 @@ However, in an environment where CI/CD pipelines will build the image, they will
146168
1. PHP `prod` Only Configuration `docker/conf/php/php-prod.ini`[🔗](https://github.com/sherifabdlnaby/symdocker/blob/master/docker/php/prod-php.ini)
147169
2. PHP `dev` Only Configuration `docker/conf/php/php-dev.ini`[🔗](https://github.com/sherifabdlnaby/symdocker/blob/master/docker/php/dev-php.ini)
148170

149-
150171
### PHP FPM Configuration
172+
1. PHP FPM Configuration `docker/fpm/*.conf` [🔗](https://github.com/sherifabdlnaby/symdocker/blob/master/docker/fpm)
173+
174+
### Nginx Configuration
175+
1. Nginx Configuration `docker/nginx/*.conf && docker/nginx/conf.d/* ` [🔗](https://github.com/sherifabdlnaby/symdocker/blob/master/docker/nginx)
176+
177+
## Post Build and Pre Run optional scripts.
151178

152-
Nginx defaults are all defined in `docker/conf/nginx/` [🔗](https://github.com/sherifabdlnaby/symdocker/blob/master/docker/conf/nginx/)
179+
In `docker/` directory there is `post-build` and `post-install` scripts that are used **to extend the image** and add extra behavior.
153180

154-
Nginx is pre-configured with:
155-
1. HTTP, HTTPS, and HTTP2.
156-
2. Rate limit (`rate=5r/s`)
157-
3. Access & Error logs to `stdout/err`
158-
4. Recommended Security Headers
159-
5. Serving Static content with default cache `7d`
160-
6. Metrics endpoint at `:8080/stub_status` from localhost only.
181+
1. `post-build` command runs at the end of Image build.
182+
183+
Run as the last step during the image build. Are Often framework specific commands that generate optimized builds.
184+
185+
2. `pre-run` command runs **in runtime** before running the container main command
186+
187+
Runs before the container's CMD, but after the composer's post-install and post-autload-dump. Used for commands that needs to run at runtime before the application is started. Often are scripts that depends on other services or runtime parameters.
161188

162189
--------
163190

164191
# Misc Notes
165192
- Your application [should log app logs to stdout.](https://stackoverflow.com/questions/38499825/symfony-logs-to-stdout-inside-docker-container). Read about [12factor/logs](https://12factor.net/logs)
166-
- By default, `php-fpm` access & error logs are disabled as they're mirrored on `nginx`, this is so that `php-fpm` image will contain **only** application logs written by PHP.
167-
- During Build, Image will run `composer dump-autoload` and `composer dump-env` to optimize for performance.
193+
- By default, `php-fpm` access logs are disabled as they're mirrored on `nginx`, this is so that `php-fpm` image will contain **only** application logs written by PHP.
168194
- In **production**, Image contains source-code, however, you must sync both `php-fpm` and `nginx` images so that they contain the same code.
169195
196+
197+
--------
198+
199+
# FAQ
200+
201+
1. Why two containers instead of one ?
202+
203+
1. In containerized environment, you need to only run one process inside the container. This allows us to better instrument our application for many reasons like separation of health status, metrics, logs, etc.
204+
205+
2. Why `debian` based image not `alpine` ?
206+
207+
1. While a smaller image is very desired, and PHP image is infamous of being big. Alpine lacks a lot of packages (Available via `apk`) that a typical PHP would need. Some packages are not even available for alpine as they link to glibc not musl.
208+
209+
170210
# License
171211
[MIT License](https://raw.githubusercontent.com/sherifabdlnaby/symdocker/blob/master/LICENSE)
172212
Copyright (c) 2021 Sherif Abdel-Naby

docker/entrypoints/entrypoint-base

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ then
2323
echo "✔ Successful"
2424
fi
2525

26-
# Run custom ad-hoc post-install script
27-
echo "► Running custom post-install script..."
28-
output=$(post-install 2>&1) || { echo "error running custom post-install script: $output"; exit 1; }
26+
# Run custom ad-hoc pre-run script
27+
echo "► Running custom pre-run script..."
28+
output=$(pre-run 2>&1) || { echo "error running custom pre-run script: $output"; exit 1; }
2929
echo "✔ Successful"
3030

3131
# ----------------------------------------------------------------------------------------------------------------------
File renamed without changes.

0 commit comments

Comments
 (0)