Closed tonivdv closed 5 years ago
I use to combine Nginx + FPM
Nginx container has the public folder and the typical nginx config:
FROM nginx:1.11-alpine
WORKDIR /app
COPY etc/deploy/nginx/default.conf /etc/nginx/conf.d/default.conf
COPY etc/deploy/nginx/gzip.conf /etc/nginx/conf.d/gzip.conf
COPY etc/deploy/nginx/nginx.conf /etc/nginx/nginx.conf
COPY public /app/public
RUN mkdir -p /var/logs/nginx \
&& touch /var/logs/nginx/access.log && ln -sf /dev/stdout /var/logs/nginx/access.log \
&& touch /var/logs/nginx/error.log && ln -sf /dev/sterr /var/logs/nginx/error.log
Keep in mind if using kubernetes and in the same pod, containers communicate through localhost, like this:
location ~ ^/(index)\.php(/|$) {
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
}
So to deploy using kubernetes:
Deployment.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: demo-api
namespace: demo
spec:
replicas: 3
revisionHistoryLimit: 3
template:
metadata:
labels:
app: demoX
tier: api
spec:
containers:
- name: fpm
image: jorge07/xxx-fpm:tagX
ports:
- containerPort: 9000
resources:
requests:
cpu: 500m
memory: 600Mi
limits:
cpu: 2
memory: 1G
env:
- name: DATABASE_HOST
valueFrom:
configMapKeyRef:
name: config-map-demo
key: database.host
....
volumeMounts:
- name: jwt-private
mountPath: "/app/app/config/security/jwt/private.pem"
readOnly: true
subPath: "private.pem"
- name: jwt-public
mountPath: "/app/app/config/security/jwt/public.pem"
readOnly: true
subPath: "public.pem"
- name: newrelic-ini
mountPath: "/opt/newrelic/newrelic.ini"
readOnly: true
subPath: "newrelic.ini"
- name: nginx
image: jorge07/xxxx-nginx:tagX
ports:
- containerPort: 80
readinessProbe:
httpGet:
path: /api/v1/status/ping
port: 80
initialDelaySeconds: 5
failureThreshold: 10
periodSeconds: 60
successThreshold: 1
timeoutSeconds: 1
livenessProbe:
httpGet:
path: /api/v1/status/ping
port: 80
initialDelaySeconds: 15
periodSeconds: 20
resources:
requests:
cpu: 10m
memory: 100Mi
limits:
cpu: 50m
memory: 200Mi
But deployment depend of your needs and your tools.
I also saw some people running Nginx+FPM by socket in the same container that's easier to deploy as is a single container.
How did you solve the issue where some assets in the public folder point with a symlink to the vendor directory which obviously isn't present in the nginx image ?
The solution I see is to remove the symlink and relative in https://github.com/jorge07/symfony-4-es-cqrs-boilerplate/blob/master/composer.json#L64
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install --symlink --relative %PUBLIC_DIR%": "symfony-cmd"
},
"post-install-cmd": [
"@auto-scripts"
],
"post-update-cmd": [
"@auto-scripts"
]
},
Seems to be the standard configuration now: https://github.com/symfony/recipes/pull/406/files
I never entered in that fight but your proposal makes totally sense.
@jorge07 Thanks. I will finish what I'm doing on my project, which turns out the work perfectly thanks to your previous feedback. Once that is done, I will propose a PR to have an example here. Your repo is a very good reference point and although it focuses on the cqrs part I think heaving a working deployment example would be very nice to have! At least it would have for me ;)
Completely agree with you and I'll really appreciate it!
Hi @jorge07 ,
Me again :)
I was wondering how you run your deployed artifact as showed in this repository? I ask because nginx is not pre-packaged in the image. So I assume the only way currently is to mount the volume of the artifact into a nginx configuration?
This would be how a docker-compose would look like to run the artifact?
Wouldn't it be better to build an image with nginx incorporated and have then 2 images, e.g:
Unless you do this differently? But then I'm very eager to know how ;)
Thanks in advance
Cheers