Add dockerizationƒ

This commit is contained in:
OpenVisor 2024-06-28 23:05:30 +02:00
parent b389d1c363
commit 92510c38d0
5 changed files with 154 additions and 0 deletions

17
.dockerignore Normal file
View file

@ -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

44
Dockerfile Normal file
View file

@ -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;"]

54
default.conf Normal file
View file

@ -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;
#}
}

20
docker-compose.yml Normal file
View file

@ -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

19
post-receive Normal file
View file

@ -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