WIP: dockerize the website

This commit is contained in:
marko
2024-12-01 16:04:51 +01:00
parent d3fbd61b0f
commit 27a96f0cf0
9 changed files with 196 additions and 41 deletions

View File

@@ -45,12 +45,14 @@ echo:
.PHONY: ampTest
ampTest: $(ampFiles)
.PHONY: INSTALL_DEPENDENCIES
INSTALL_DEPENDENCIES:
npm install csso
npm install --save-dev --save-exact prettier
build/css/cwsvJudo.css: $(cssFiles)
mkdir -p $(dir $@)
cat $^ > $@
# cat $(cssFiles) | cleancss -o $@
# cat $^ | ./node_modules/.bin/csso -o $@
# cat $^ | $(CSSO) -o $@
npx csso --input $^ --output $@
build/%.php: src/md/%.md build/yaml/%.yaml pandocTemplate/cwsvJudo.html5.pandocTemplate
mkdir -p build

View File

@@ -1,4 +1,4 @@
CSSO = node_modules/csso-cli/bin/csso
#!/usr/bin/env make -f
RES_LIST = 64 128 256 512
@@ -9,6 +9,9 @@ ampFiles = $(patsubst src/md/%.md, build/amp/%.php, $(mdFiles))
phpLibFiles = $(wildcard phpLib/cwsvJudo/*.php) phpLib/phpcount/phpcount.php
configFiles = $(wildcard config/*.php)
distDir=./build/dist/heliohost
LN = cp -r
.PHONY: all
all: $(phpFiles)
@@ -20,8 +23,44 @@ all: $(phpFiles)
clean:
$(RM) -rf build
# copy/link all together to get a distributable package
.PHONY: dist
dist: all
mkdir -p $(distDir)
# page data
mkdir -p $(distDir)/httpdocs/pages/
$(LN) ./build/materialize $(distDir)/httpdocs/pages/responsive
$(LN) ./src/shared/ $(distDir)/httpdocs/pages/shared
# php lib
mkdir -p $(distDir)/httpdocs/ressourcen/phpLib
$(LN) ./phpLib/cwsvJudo $(distDir)/httpdocs/ressourcen/phpLib/cwsvJudo
$(LN) ./phpLib/phpqrcode $(distDir)/httpdocs/ressourcen/phpLib/phpqrcode
# graphics
mkdir -p $(distDir)/httpdocs/ressourcen/graphiken
$(LN) ./build/graphiken/cwsvJudoLogoWappen $(distDir)/httpdocs/ressourcen/graphiken/logos
$(LN) ./graphiken/banner $(distDir)/httpdocs/ressourcen/graphiken/banner
$(LN) ./build/graphiken/favIcons/favicon.ico $(distDir)/httpdocs/favicon.ico
$(LN) ./res/videos.d $(distDir)/httpdocs/videos.d
# css
mkdir -p $(distDir)/httpdocs/ressourcen/css
$(LN) ./build/css/cwsvJudo.css $(distDir)/httpdocs/ressourcen/css/cwsvJudo.css
# fonts
$(LN) ./res/fonts $(distDir)/httpdocs/ressourcen/fonts
# htaccess
$(LN) ./src/htaccess/heliohost/.htaccess $(distDir)/httpdocs/.htaccess
# @todo Link is into the build directory breaking the above pattern.
$(LN) ./src/htaccess/heliohost/pages/responsive/.htaccess ./build/materialize/.htaccess
# config files
# @todo Link is into the build directory breaking the above pattern.
$(LN) ./configs/heliohost/pages.config.inc.php ./build/materialize/config.inc.php
# @todo shouldn't be used any more
mkdir -p $(distDir)/.local
$(LN) configs/heliohost/db.config.php $(distDir)/.local/db.config.php
# build the materialize version of the page
build/materialize/%.php: src/md/%.md build/yaml/%.yaml pandocTemplate/materialize.pandocTemplate
mkdir -p build/materialize
# create html/php code
pandoc \
--standalone \
--css="ressourcen/css/cwsvJudo.css" \
@@ -30,6 +69,7 @@ build/materialize/%.php: src/md/%.md build/yaml/%.yaml pandocTemplate/materializ
--wrap=preserve \
--output=$@ \
$< $(word 2,$^)
# npx prettier --check $@
# @toDo: Verzeichnisstruktur überdenken
build/yaml/%.yaml: src/yaml/images.yaml src/yaml/navTargets.yaml src/yaml/mainNav.yaml src/yaml/%.subNav.yaml

View File

@@ -0,0 +1,11 @@
# select base image
FROM php:fpm
# startup scripts for the image
# - docker-php-ext-install -- install helper script from PHP
RUN docker-php-ext-install pdo pdo_mysql
# install and add xdebug extension
# @todo What is pecl?
# @todo What is xdebug and how do I use it?
RUN pecl install xdebug && docker-php-ext-enable xdebug

View File

@@ -0,0 +1,8 @@
#! /usr/bin/env bash
# stop all containers
docker-compose down --remove-orphans
# delete all containers
docker rm -f $(docker ps -a -q)
# delete all volumes
docker volume rm $(docker volume ls -q)

View File

@@ -0,0 +1,77 @@
# version for the docker compose file to use
version: "3"
# a dict of services running in the container label: {<service>} label is a self defined name for the service
services:
# the webserver service
web:
image: nginx:latest
# port forwarding
ports:
# forward port 80 top port 80 in the container
- "8080:80"
# files and directories to be available in the container
# - localPath:pathInContainer
volumes:
# nginx config file
# - ./nginx.conf:/etc/nginx/conf.d/nginx.conf
# the www-data
# - ./build/dist/heliohost:/home/cwsvjudo/httpdocs
- ./build/dist/heliohost:/usr/share/nginx/html:Z
# php and extensions
php:
# use pre-build image from docker..
# image: php:fpm
# .. or build your own image
build:
context: .
dockerfile: PHP.dockerfile
# files and directories to be available in the container
# @todo Except from better structuring: Is there a reason for not having the volumes as one central list?
volumes:
# the www-data
# - ./build/dist/heliohost:/home/cwsvjudo
- ./build/dist/heliohost:/usr/share/nginx/html:ro
# # @todo Maybe use postgre instead?
database:
image: mariadb:latest
restart: always
# define environment variables
# @todo Should credentials be placed here? Even if it is just a test environment
environment:
# MYSQL_TCP_PORT: 1433
MYSQL_USER: "cwsvjudo"
MYSQL_DATABASE: "cwsvjudo"
MYSQL_ROOT_PASSWORD_FILE: /run/secrets/db_root_password
MYSQL_PASSWORD_FILE: /run/secrets/db_password
volumes:
- mysqldata:/var/lib/mysql
# initial database
# - has to be created first, e.g., by dumping the database from the productive system
- ./cwsvjudo.sql:/docker-entrypoint-initdb.d/cwsvjudo.sql
secrets:
- db_root_password
- db_password
# phpmyadmin
# phpmyadmin:
# image: phpmyadmin:latest
# restart: always
# depends_on:
# - database
# - php
# ports:
# - 8080:80
# environment:
# # name of the host is the name of the db service started above! Why? I don't know!
# - PMA_HOST=database
# - PMA_PORT=1433
volumes:
# data storage for the db
mysqldata: {}
secrets:
db_root_password:
file: db_root_password.txt
db_password:
file: db_password.txt

View File

@@ -0,0 +1,24 @@
# @todo Needs helpfull comments.
server {
listen 80 default_server;
# root /users/cwsvjudo/www;
# root /home/cwsvjudo/httpdocs;
root /usr/share/nginx/html;
index index.php index.html index.htm;
location / {
# rewrite rules
# - add php to requested filename if it exists
if (-e $request_filename.php) {
rewrite ^/(.*)$ /$1.php last;
break;
}
}
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

View File

@@ -1,62 +1,53 @@
<?php
/// Einbinden der Konfiguration, insbesondere Basisvariablen,
/// relative Pfadangabe
/// - jedes Verzeichnis sollte seine eigene haben
/// - theoretisch sollte es bereits von der aufrufenden Datei
/// eingebunden sein
// server specific variables:
require_once("./config.inc.php");
// require_once($$basePath."/config/phpcount.config.php");
// database specific variables
require_once($$home."/.local/db.config.php");
require_once($$basePath."/ressourcen/phpLib/cwsvJudo/miscAssis.php");
require_once($$basePath."/ressourcen/phpLib/cwsvJudo/newsLib.php");
require_once($$basePath."/ressourcen/phpLib/cwsvJudo/wkKalender.php");
require_once($$basePath."/ressourcen/phpLib/cwsvJudo/galTable.php");
require_once($$basePath."/ressourcen/phpLib/cwsvJudo/newsTableHtml.php");
require_once($$basePath."/ressourcen/phpLib/cwsvJudo/newsLib.php");
require_once($$basePath."/ressourcen/phpLib/cwsvJudo/galleryRedirector.php");
// require_once($$basePath."/ressourcen/phpLib/phpcount/phpcount.php");
// cwsvJudo lib
foreach(["miscAssis", "newsLib", "wkKalender", "galTable", "newsTableHtml", "newsLib", "galleryRedirector"] as $$sublib){
require_once($$basePath."/ressourcen/phpLib/cwsvJudo/".$$sublib.".php");
}
// @todo remove galleries
galleryRedirector();
$if(phpTitleString)$
// PHPCount::AddHit($phpTitleString$);
$else$
// PHPCount::AddHit("$title$");
$endif$
?>
<!DOCTYPE html>
<html$if(lang)$ lang="$lang$" $endif$$if(dir)$ dir="$dir$" $endif$>
<html $if(lang)$lang="$lang$"$endif$ $if(dir)$dir="$dir$"$endif$>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
$for(author-meta)$
<meta name="author" content="$author-meta$">
<meta name="author" content="$author-meta$">
$endfor$
$if(date-meta)$
<meta name="dcterms.date" content="$date-meta$">
<meta name="dcterms.date" content="$date-meta$">
$endif$
$if(keywords)$
<meta name="keywords" content="$for(keywords)$$keywords$$sep$, $endfor$">
<meta
name="keywords"
content="$for(keywords)$$keywords$$sep$, $endfor$"
>
$endif$
$if(canonicalPath)$
<link rel="canonical" href="<?php echo($$canonicalBaseUrl);?>/$canonicalPath$">
<link rel="canonical" href="<?php echo($$canonicalBaseUrl);?>/$canonicalPath$">
$endif$
$if(ampVersionLink)$
<link rel="amphtml" href="$ampVersionLink$">
<link rel="amphtml" href="$ampVersionLink$">
$endif$
$if(phpTitleString)$
<title>
<?php echo( $phpTitleString$ );?>
<title><?php echo( $phpTitleString$ );?>
</title>
$else$$if(title)$
<title>$if(title-prefix)$$title-prefix$ $endif$$pagetitle$</title>
$endif$$endif$
<title>$if(title-prefix)$$title-prefix$ $endif$$pagetitle$</title>
$endif$
$endif$
$if(phpDescriptionString)$
<meta name="description" content="<?php echo( $phpDescriptionString$ );?>">
<meta name="description" content="<?php echo( $phpDescriptionString$ );?>">
$else$$if(description)$
<meta name="description" content="$description$">
<meta name="description" content="$description$">
$endif$$endif$
<style>
@@ -69,8 +60,9 @@ $endif$
$if(css)$
<style>
$for(css)$ <?php include_once($$basePath."/$css$");
?>$endfor$
$for(css)$
<?php include_once($$basePath."/$css$");?>
$endfor$
</style>
$endif$
<style>
@@ -91,10 +83,10 @@ $endif$
</style>
$endif$
$for(extraCss)$
<link rel="stylesheet" href="$extraCss$">
<link rel="stylesheet" href="$extraCss$">
$endfor$
$if(math)$
$math$
$math$
$endif$
<script type='application/ld+json'>
{

View File

@@ -2,6 +2,7 @@
// Umleiten auf eine per query galId im $_GET gegebene Galerie
function galleryRedirector(){
global $cwsvJudoConfig;
$baseDomain = $GLOBALS["baseDomain"];
// require_once($_SERVER['DOCUMENT_ROOT']."/bonus/db.inc");
if(isset($_GET['galId'])){

View File