From 37de94a02b162b3237fb0cb61b742885da8e3edd Mon Sep 17 00:00:00 2001 From: perl Date: Thu, 3 Oct 2024 21:48:45 +0300 Subject: [PATCH] add Dockerfile for static html --- .gitignore | 1 + ComposeProjects/statc-dc.yaml | 0 Dockerfiles/Dockerfile_staticsite | 42 +++++++++++++++++++++++++++ docker_image_configs/static.conf.tmpl | 20 +++++++++++++ 4 files changed, 63 insertions(+) create mode 100644 ComposeProjects/statc-dc.yaml create mode 100644 Dockerfiles/Dockerfile_staticsite create mode 100644 docker_image_configs/static.conf.tmpl diff --git a/.gitignore b/.gitignore index e5249b4..4f4f5c4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ logs/* ssl/* sites-enabled/* +project/* !sites-enabled/reverse.conf.tmpl !sites-enabled/http_redirect.conf !sites-enabled/default.conf diff --git a/ComposeProjects/statc-dc.yaml b/ComposeProjects/statc-dc.yaml new file mode 100644 index 0000000..e69de29 diff --git a/Dockerfiles/Dockerfile_staticsite b/Dockerfiles/Dockerfile_staticsite new file mode 100644 index 0000000..49e0fd4 --- /dev/null +++ b/Dockerfiles/Dockerfile_staticsite @@ -0,0 +1,42 @@ +# Для доставки сертификати в /etc/nginx/ssl/ использовать volume +#ARGS: SERVER_NAMES, CERT_FILE, CERT_KEY_FILE, CONT_IMG_VER + +FROM nginx:stable-alpine + +#http to https redirect +COPY sites-enabled/http_redirect.conf /etc/nginx/sites-enabled/ + +#site config +COPY docker_image_configs/static.conf.tmpl /etc/nginx/sites-enabled/static.conf + +#set server name if arg not empty +ARG SERVER_NAMES +RUN if [ ! -z ${SERVER_NAMES} ]; then \ + sed -i "s/server_name _;/server_name $SERVER_NAMES;/g" /etc/nginx/sites-enabled/static.conf ;\ + fi + +#set certificate file name if arg not empty +ARG CERT_FILE +RUN if [ ! -z ${CERT_FILE} ]; then \ + sed -i "s/ssl_certificate \/etc\/nginx\/ssl\/cert.pem;/ssl_certificate \/etc\/nginx\/ssl\/$CERT_FILE;/g" /etc/nginx/sites-enabled/static.conf ;\ + fi + +#set certificate key file name if arg not empty +ARG CERT_KEY_FILE +RUN if [ ! -z ${CERT_KEY_FILE} ]; then \ + sed -i "s/ssl_certificate_key \/etc\/nginx\/ssl\/key.pem;/ssl_certificate_key \/etc\/nginx\/ssl\/$CERT_KEY_FILE;/g" /etc/nginx/sites-enabled/static.conf ;\ + fi + +#set container image version if arg not empty else 1.0.0 +ARG CONT_IMG_VER +ENV CONT_IMG_VER=${CONT_IMG_VER:-v1.0.0} + +#copy project files +COPY ./project /var/www/html/ + +CMD ["nginx", "-g", "daemon off;"] + +#build string example +#docker build -f Dockerfiles/Dockerfile_staticsite -t static_site --no-cache --build-arg SERVER_NAMES=softsols.ru . +#check server_name in image +#docker run --rm -it -p 8084:443 -p 8083:80 static_site sh -c "cat /etc/nginx/sites-enabled/static.conf" \ No newline at end of file diff --git a/docker_image_configs/static.conf.tmpl b/docker_image_configs/static.conf.tmpl new file mode 100644 index 0000000..4a73ca1 --- /dev/null +++ b/docker_image_configs/static.conf.tmpl @@ -0,0 +1,20 @@ +server { + listen 443 ssl; + listen [::]:443 ssl; + http2 on; + + server_name _; + + ssl_certificate /etc/nginx/ssl/cert.pem; + ssl_certificate_key /etc/nginx/ssl/key.pem; + ssl_protocols TLSv1.2 TLSv1.3; + ssl_ciphers HIGH:!aNULL:!MD5; + ssl_prefer_server_ciphers on; + include configuration/_includes.conf; + + location / { + root /var/www/html/; + index index.html; + try_files $uri $uri/ =404; + } +} \ No newline at end of file