From 92510c38d016aeacb258d1dc76d87b8de5e6e25f Mon Sep 17 00:00:00 2001 From: OpenVisor Date: Fri, 28 Jun 2024 23:05:30 +0200 Subject: [PATCH] =?UTF-8?q?Add=20dockerization=C2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 17 +++++++++++++++ Dockerfile | 44 +++++++++++++++++++++++++++++++++++++ default.conf | 54 ++++++++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 20 +++++++++++++++++ post-receive | 19 ++++++++++++++++ 5 files changed, 154 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 default.conf create mode 100644 docker-compose.yml create mode 100644 post-receive diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..63e6ab6 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,17 @@ +# geschichtenfabio-dockerized/.dockerignore +# https://git.openvisor.ch/Rider/geschichtenfabio + +# docker files +Dockerfile +docker-compose.yml +.env + +# git files +branches +config +descriptiom +HEAD +hooks +info +objects +refs \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c2df18a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,44 @@ +# geschichtenfabio-dockerized/Dockerfile +# https://git.openvisor.ch/Rider/geschichtenfabio + +# BUILD STAGE +#FROM node:22.1.0-alpine3.19 as build-stage + +#WORKDIR /app + +# add resources required to build the web application +#COPY . . + +# PRODUCTION STAGE +FROM nginx:1.26.0-alpine3.19 as production-stage + +WORKDIR /usr/share/nginx/html + +# use custom error code websites instead +#RUN rm -f /usr/share/nginx/html/50x.html + +# update default.conf nginx file with necessary try_files statement +RUN rm -f /etc/nginx/conf.d/default.conf + +RUN mkdir ./geschichten +RUN mkdir ./images + +# enable the nginx user to be able to launch the web application, so root is not required +RUN touch /var/run/nginx.pid && \ + chown -R nginx:nginx /var/cache/nginx /var/run/nginx.pid +USER nginx +COPY --chown=nginx:nginx ./default.conf /etc/nginx/conf.d/default.conf + +# add the previously built web application +COPY --chown=www-data:www-data ./app/geschichten/ ./geschichten/ +COPY --chown=www-data:www-data ./app/images/ ./images/ +COPY --chown=www-data:www-data ./app/style.css ./style.css +COPY --chown=www-data:www-data ./app/index.html ./index.html + +EXPOSE 80 + +# check every minute whether the website is still locally reachable; if not, the docker process displays "unhealthy" +HEALTHCHECK --interval=1m CMD wget --no-verbose --tries=1 http://localhost:80 -q -O /dev/null || exit 1 + +# runs nginx in the foreground which means the docker container only runs as long as nginx is running (good practice) +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/default.conf b/default.conf new file mode 100644 index 0000000..799868b --- /dev/null +++ b/default.conf @@ -0,0 +1,54 @@ +server { + listen 80; + listen [::]:80; + server_name localhost; + + #access_log /var/log/nginx/host.access.log main; + + root /usr/share/nginx/html; + index index.html index.htm; + + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + # Added try_files to ensure that one can link or type a specific URI + try_files $uri $uri/ /index.html; + } + + # Added charset utf-8; to ensure UTF-8 is supported + charset utf-8; + + # TODO: Add custom error pages (for now they're commented out) + #error_page 404 /404.html; + + # redirect server error pages to the static page /50x.html + # + #error_page 500 502 503 504 /50x.html; + #location = /50x.html { + # root /usr/share/nginx/html; + #} + + # proxy the PHP scripts to Apache listening on 127.0.0.1:80 + # + #location ~ \.php$ { + # proxy_pass http://127.0.0.1; + #} + + # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 + # + #location ~ \.php$ { + # root html; + # fastcgi_pass 127.0.0.1:9000; + # fastcgi_index index.php; + # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; + # include fastcgi_params; + #} + + # deny access to .htaccess files, if Apache's document root + # concurs with nginx's one + # + #location ~ /\.ht { + # deny all; + #} +} \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..e35d19e --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,20 @@ +# geschichtenfabio-dockerized/docker-compose.yml +# https://git.openvisor.ch/Rider/geschichtenfabio +networks: + geschichtenfabio-network: + name: geschichtenfabio-network + driver: bridge + external: false + attachable: false + +services: + geschichtenfabio-app: + container_name: geschichtenfabio-app + restart: unless-stopped + build: . + # ensure that web application is not run by root + user: nginx:nginx + ports: + - 2443:80 + networks: + - geschichtenfabio-network diff --git a/post-receive b/post-receive new file mode 100644 index 0000000..6cc7590 --- /dev/null +++ b/post-receive @@ -0,0 +1,19 @@ +# geschichtenfabio-dockerized/hooks/post-receive +# https://git.openvisor.ch/Rider/geschichtenfabio + +#!/bin/bash +REPOSITORY=/opt/geschichtenfabio-dockerized +git --work-tree=${REPOSITORY} --git-dir=${REPOSITORY} -f +touch ${REPOSITORY}/FLAG-FOR-CRONJOB-DOCKER-AUTOMATION + +# content of /etc/cron.daily/geschichtenfabio-docker-automation +##!/bin/sh +#REPOSITORY=/opt/geschichtenfabio-dockerized +#if [ -f ${REPOSITORY}/FLAG-FOR-CRONJOB-DOCKER-AUTOMATION ]; +# then +# docker compose build +# docker compose stop +# docker rm openvisorwebsite-app +# docker compose up -d +# rm ${REPOSITORY}/FLAG-FOR-CRONJOB-DOCKER-AUTOMATION +#fi