Skip to content
Snippets Groups Projects
Commit 310b8bf9 authored by i.vasilenko@iq-adv.ru's avatar i.vasilenko@iq-adv.ru
Browse files

init

parent c46b33ac
No related branches found
No related tags found
1 merge request!1init docker
Showing
with 438 additions and 0 deletions
#!/bin/sh
set -e
# Load .env and .env.<APP_ENV>, and .env.<APP_ENV>.local into script (won't overwrite OS env vars.)
#set -a
# env_overwrite="./.env.${APP_ENV-prod}"
# env_local_overwrite="./.env.${APP_ENV-prod}.local"
# export -p >> /tmp/envsrc && if [ -f "./.env" ]; then . ./.env; fi && if [ -f "${env_overwrite}" ]; then . $env_overwrite; fi && if [ -f "${env_local_overwrite}" ]; then . $env_local_overwrite; fi && . /tmp/envsrc \
# && rm /tmp/envsrc && unset env_overwrite && unset env_local_overwrite
#set +a
# This script working dir is application's directory, and all ENV variables from .env and OS are available here
# using ${ENV_NAME} with defaults taken from .env and .env.<env>
#
# Ex:
# { echo ${DATABASE_URL}; echo "stdin input"; } | vendor/bin/<script that need stdin input>
# Put Custom Ad-hoc scripts below:
## Run Envsubst on .env to expand embedded Env Variables
#echo "► Expanding Dotenv files with Environment Variables..."
#for f in $(find . -name ".env*"); do cat $f | envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" > "$f.tmp"; mv "$f.tmp" "$f"; done
#!/bin/sh
# Reference: https://github.com/facile-it/terminable-loop-command
# When running a PHP application, you may encounter the need of a background command that runs continuously.
# You can try to write it as a long running process, but it can be prone to memory leaks and other issues.
#
# With this small Shell+PHP combination, you can have a simple loop that:
# 1. starts the command
# 2. does something
# 3. sleeps for a custom amount of time
# 4. shuts down and restarts back again
# 5. The shell script intercepts SIGTERM/SIGINT signals so, when they are received, the PHP script is stopped ASAP but gracefully,
# since the execution of the body of the command is never truncated.
# This means that you can easily obtain a daemon PHP script without running in memory issues; if you run this in a Kubernetes environment this will be very powerful, since the orchestrator will take care of running the script,
# and at the same time it will apply the proper restart policies in case of crashes. Last but not least, the signal handling will play nice with shutdown requests, like during the roll out of a new deployment.
echo "Starting command: $@";
# Send Termination to Child
_term() {
kill -TERM $CHILD 2>/dev/null
wait $CHILD
}
# If we received termination signal we need to pass it to child
trap _term TERM
while true; do
# Start Command in BG
$@ &
# Get It's PID
CHILD=$!
# Wait for it to be finished
wait $CHILD
# Get its status code and break if it exited.
STATUS=$?
if [ $STATUS -ne 0 ]; then
echo "Command exited with status code $STATUS, loop interrupted. shutting down...";
exit $STATUS;
fi
done
\ No newline at end of file
#!/bin/sh
# Reference: https://github.com/facile-it/terminable-loop-command
# When running a PHP application, you may encounter the need of a background command that runs continuously.
# You can try to write it as a long running process, but it can be prone to memory leaks and other issues.
#
# With this small Shell+PHP combination, you can have a simple loop that:
# 1. starts the command
# 2. does something
# 3. sleeps for a custom amount of time
# 4. shuts down and restarts back again
# 5. The shell script intercepts SIGTERM/SIGINT signals so, when they are received, the PHP script is stopped ASAP but gracefully,
# since the execution of the body of the command is never truncated.
# This means that you can easily obtain a daemon PHP script without running in memory issues; if you run this in a Kubernetes environment this will be very powerful, since the orchestrator will take care of running the script,
# and at the same time it will apply the proper restart policies in case of crashes. Last but not least, the signal handling will play nice with shutdown requests, like during the roll out of a new deployment.
cooldown=${@:1:1}
command=${@:2}
echo "Starting command: '$command' with cooldown: '$cooldown' seconds"
# Send Termination to Child
_term() {
kill -TERM $CHILD 2>/dev/null
wait $CHILD
}
# If we received termination signal we need to pass it to child
trap _term TERM
while true; do
# Start Command in BG
$command &
# Get It's PID
CHILD=$!
# Wait for it to be finished
wait $CHILD
# Get its status code and break if it exited.
STATUS=$?
if [ $STATUS -ne 0 ]; then
echo "Command exited with status code $STATUS, loop interrupted. shutting down...";
exit $STATUS;
fi
sleep $cooldown
done
\ No newline at end of file
# syntax = edrevo/dockerfile-plus
ARG NGINX_VERSION="1.25"
# Подключение PHP образов
INCLUDE+ docker/app/Dockerfile
FROM nginx:${NGINX_VERSION}-alpine AS nginx
RUN rm -rf /var/www/* /etc/nginx/conf.d/* && adduser -u 1000 -D -S -G www-data www-data
COPY docker/web/nginx/nginx-* /usr/local/bin/
COPY docker/web/nginx/ /etc/nginx/
RUN chown -R www-data /etc/nginx/ && chmod +x /usr/local/bin/nginx-*
# The PHP-FPM Host
## Localhost is the sensible default assuming image run on a k8S Pod
ENV PHP_FPM_HOST "localhost"
ENV PHP_FPM_PORT "9000"
ENV NGINX_LOG_FORMAT "json"
# For Documentation
EXPOSE 8080
# Switch User
USER www-data
# Add Healthcheck
HEALTHCHECK CMD ["nginx-healthcheck"]
# Add Entrypoint
ENTRYPOINT ["nginx-entrypoint"]
# ======================================================================================================================
# --- NGINX PROD ---
# ======================================================================================================================
FROM nginx AS web
USER root
RUN SECURITY_UPGRADES="curl"; \
apk add --no-cache --upgrade ${SECURITY_UPGRADES}
USER www-data
# Copy Public folder + Assets that's going to be served from Nginx
COPY --chown=www-data:www-data --from=app /app/public /app/public
# ======================================================================================================================
# --- NGINX DEV ---
# ======================================================================================================================
FROM nginx AS web-dev
ENV NGINX_LOG_FORMAT "combined"
COPY --chown=www-data:www-data docker/web/nginx/dev/*.conf /etc/nginx/conf.d/
COPY --chown=www-data:www-data docker/web/nginx/dev/certs/ /etc/nginx/certs/
This diff is collapsed.
# Compression
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 32 16k;
gzip_http_version 1.1;
gzip_min_length 250;
gzip_types image/jpeg image/bmp image/svg+xml text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript image/x-icon;
\ No newline at end of file
# logging
log_format json escape=json '{"@timestamp":"$time_iso8601","status":"$status","method":"$request_method","path":"$request_uri","request_query":"$args","request_time":"$request_time","vhost":"$host","bytes_sent":"$bytes_sent","request_length":"$request_length","request_proto":"$server_protocol","remote_user":"$remote_user","remote_addr":"$remote_addr","http_referrer":"$http_referer","http_user_agent":"$http_user_agent"}';
access_log /dev/stdout ${NGINX_LOG_FORMAT};
error_log /dev/stderr warn;
\ No newline at end of file
# Healthcheck & Metrics endpoint on port 8090
server {
listen 8090;
listen [::]:8090;
location /stub_status {
stub_status;
access_log off;
allow 127.0.0.1;
deny all;
}
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment