From 132354931675e992f3189e8929d619626dacdaea Mon Sep 17 00:00:00 2001 From: David Bailey Date: Sat, 14 Oct 2023 15:29:56 +0200 Subject: [PATCH 1/8] ci: :construction_worker: test out Forgejo CI --- .forgejo/workflows/phplint.yaml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .forgejo/workflows/phplint.yaml diff --git a/.forgejo/workflows/phplint.yaml b/.forgejo/workflows/phplint.yaml new file mode 100644 index 0000000..1d23cd2 --- /dev/null +++ b/.forgejo/workflows/phplint.yaml @@ -0,0 +1,11 @@ +on: [push] + +jobs: + phplint: + runs-on: docker + container: + image: cytopia/phplint:debian + entrypoint: sh + steps: + - uses: actions/checkout@v4 + - ./docker-entrypoint.sh -i ./vendor/.* *.php \ No newline at end of file From cc75b4a98b0a7c803332e9c7041841320bc235ce Mon Sep 17 00:00:00 2001 From: David Bailey Date: Sat, 14 Oct 2023 15:31:46 +0200 Subject: [PATCH 2/8] ci: :pencil2: properly use run step --- .forgejo/workflows/phplint.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.forgejo/workflows/phplint.yaml b/.forgejo/workflows/phplint.yaml index 1d23cd2..b1e3b82 100644 --- a/.forgejo/workflows/phplint.yaml +++ b/.forgejo/workflows/phplint.yaml @@ -8,4 +8,4 @@ jobs: entrypoint: sh steps: - uses: actions/checkout@v4 - - ./docker-entrypoint.sh -i ./vendor/.* *.php \ No newline at end of file + - run: ./docker-entrypoint.sh -i ./vendor/.* *.php \ No newline at end of file From 472dfcd834c876b04791aad456f4e625c2be670d Mon Sep 17 00:00:00 2001 From: David Bailey Date: Sat, 14 Oct 2023 15:38:28 +0200 Subject: [PATCH 3/8] ci: :pushpin: adjust checkout version to v3 (Node20 issues <.<) --- .forgejo/workflows/phplint.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.forgejo/workflows/phplint.yaml b/.forgejo/workflows/phplint.yaml index b1e3b82..4f2bade 100644 --- a/.forgejo/workflows/phplint.yaml +++ b/.forgejo/workflows/phplint.yaml @@ -7,5 +7,5 @@ jobs: image: cytopia/phplint:debian entrypoint: sh steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v3 - run: ./docker-entrypoint.sh -i ./vendor/.* *.php \ No newline at end of file From 472ec104965d42f93eab110d5ada37495e2531c4 Mon Sep 17 00:00:00 2001 From: David Bailey Date: Sat, 14 Oct 2023 15:54:44 +0200 Subject: [PATCH 4/8] ci: :construction_worker: mess with CI more, trying to run docker images --- .forgejo/workflows/phplint.yaml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.forgejo/workflows/phplint.yaml b/.forgejo/workflows/phplint.yaml index 4f2bade..e2d7069 100644 --- a/.forgejo/workflows/phplint.yaml +++ b/.forgejo/workflows/phplint.yaml @@ -3,9 +3,8 @@ on: [push] jobs: phplint: runs-on: docker - container: - image: cytopia/phplint:debian - entrypoint: sh steps: - uses: actions/checkout@v3 - - run: ./docker-entrypoint.sh -i ./vendor/.* *.php \ No newline at end of file + - uses: docker://cytopia/phplint:alpine + with: + cmd: -i ./vendor/.* *.php \ No newline at end of file From 1862ccbbb69a3e4cffe087a54abf3754bde19b47 Mon Sep 17 00:00:00 2001 From: David Bailey Date: Mon, 16 Oct 2023 16:15:24 +0200 Subject: [PATCH 5/8] feat: :sparkles: [first attempt at using MySQLi in the docker dev env] --- docker_dev/Dockerfile | 1 + docker_dev/MysqlDockerfile | 4 ++++ docker_dev/compose.yaml | 7 +++++-- docker_dev/mysql_schema.sql | 0 router.php | 11 +++++++++++ 5 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 docker_dev/MysqlDockerfile create mode 100644 docker_dev/mysql_schema.sql diff --git a/docker_dev/Dockerfile b/docker_dev/Dockerfile index 60a6a66..ba72d62 100644 --- a/docker_dev/Dockerfile +++ b/docker_dev/Dockerfile @@ -12,6 +12,7 @@ RUN chmod -R a+r ./vendor RUN a2enmod rewrite RUN a2enmod headers +RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli COPY . . RUN chmod -R a+r $(ls -I vendor) diff --git a/docker_dev/MysqlDockerfile b/docker_dev/MysqlDockerfile new file mode 100644 index 0000000..be3c855 --- /dev/null +++ b/docker_dev/MysqlDockerfile @@ -0,0 +1,4 @@ +FROM mysql:8.0-debian + +WORKDIR /docker-entrypoint-initdb.d +COPY mysql_schema.sql ./ \ No newline at end of file diff --git a/docker_dev/compose.yaml b/docker_dev/compose.yaml index 5e8c99b..4ab1353 100644 --- a/docker_dev/compose.yaml +++ b/docker_dev/compose.yaml @@ -11,9 +11,12 @@ services: action: rebuild - path: ../. action: sync - target: /usr/local/apache2/htdocs/ + target: /var/www/html + ignore: + - ../.git mysql: - image: mysql:8.0-debian + build: + dockerfile: MysqlDockerfile # NOTE: use of "mysql_native_password" is not recommended: https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password # (this is just an example, not intended to be a production configuration) command: --default-authentication-plugin=mysql_native_password diff --git a/docker_dev/mysql_schema.sql b/docker_dev/mysql_schema.sql new file mode 100644 index 0000000..e69de29 diff --git a/router.php b/router.php index 9e2c99d..57a3318 100644 --- a/router.php +++ b/router.php @@ -2,6 +2,17 @@ require_once 'vendor/autoload.php'; + +$sql = mysqli_connect('mysql', 'root', 'example', 'mysql'); + +if (!$sql) +{ + echo 'Connection failed
'; + echo 'Error number: ' . mysqli_connect_errno() . '
'; + echo 'Error message: ' . mysqli_connect_error() . '
'; + die(); +} + $loader = new \Twig\Loader\FilesystemLoader(['./templates', './user_content']); $twig = new \Twig\Environment($loader,['debug' => true]); From 57d6d82be93a50af40802d130983463f7ae86272 Mon Sep 17 00:00:00 2001 From: David Bailey Date: Thu, 19 Oct 2023 21:53:14 +0200 Subject: [PATCH 6/8] ci: add first draft of MySQL data schema --- docker_dev/Dockerfile | 4 ++-- docker_dev/compose.yaml | 13 +++++++--- docker_dev/mysql_schema.sql | 48 +++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 5 deletions(-) diff --git a/docker_dev/Dockerfile b/docker_dev/Dockerfile index ba72d62..4f96be7 100644 --- a/docker_dev/Dockerfile +++ b/docker_dev/Dockerfile @@ -1,7 +1,7 @@ FROM composer WORKDIR /app -COPY composer.* . +COPY www/composer.* . RUN composer install FROM php:apache @@ -14,5 +14,5 @@ RUN a2enmod rewrite RUN a2enmod headers RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli -COPY . . +COPY www/ . RUN chmod -R a+r $(ls -I vendor) diff --git a/docker_dev/compose.yaml b/docker_dev/compose.yaml index 4ab1353..e1a79b0 100644 --- a/docker_dev/compose.yaml +++ b/docker_dev/compose.yaml @@ -9,11 +9,12 @@ services: watch: - path: ./ action: rebuild - - path: ../. + - path: ../www/ action: sync target: /var/www/html ignore: - ../.git + - mysql_schema.sql mysql: build: dockerfile: MysqlDockerfile @@ -23,7 +24,13 @@ services: restart: always environment: MYSQL_ROOT_PASSWORD: example - volumes: - - sqlvolume:/var/lib/mysql + ports: + - 3306:3306 + develop: + watch: + - path: mysql_schema.sql + action: rebuild +# volumes: +# - sqlvolume:/var/lib/mysql volumes: sqlvolume: {} diff --git a/docker_dev/mysql_schema.sql b/docker_dev/mysql_schema.sql index e69de29..6b954b7 100644 --- a/docker_dev/mysql_schema.sql +++ b/docker_dev/mysql_schema.sql @@ -0,0 +1,48 @@ + +CREATE DATABASE dragon_fire; + +USE dragon_fire; + +CREATE TABLE posts ( + post_id INTEGER AUTO_INCREMENT, + + post_path VARCHAR(255) NOT NULL, + post_path_depth INTEGER NOT NULL DEFAULT 0, + + post_title TEXT, + post_description TEXT, + post_brief TEXT, + + post_content MEDIUMTEXT, + post_content_type TEXT, + + PRIMARY KEY(post_id), + CONSTRAINT unique_post_path UNIQUE (post_path), + + INDEX(post_path), + INDEX(post_path_depth, post_path) +); + +CREATE TABLE post_tags ( + post_id INTEGER, + tag VARCHAR(255), + + CONSTRAINT post_fkey + FOREIGN KEY(post_id) REFERENCES posts(post_id) + ON DELETE CASCADE, + + INDEX(post_id), + INDEX(tag) +); + + +INSERT INTO posts (post_path, post_title, post_content) +VALUES ( + '/about', + 'About the Dergs', +' +# About the dergs indeed + +This is just a simple test. Might be nice, though! +' +); \ No newline at end of file From 502ddd1ad9382ee1b2e9b2e7308a8a1f541089be Mon Sep 17 00:00:00 2001 From: David Bailey Date: Thu, 19 Oct 2023 21:53:41 +0200 Subject: [PATCH 7/8] ci: moved lint file name --- .forgejo/workflows/lint.yaml | 14 ++++++++++++++ .forgejo/workflows/phplint.yaml | 10 ---------- 2 files changed, 14 insertions(+), 10 deletions(-) create mode 100644 .forgejo/workflows/lint.yaml delete mode 100644 .forgejo/workflows/phplint.yaml diff --git a/.forgejo/workflows/lint.yaml b/.forgejo/workflows/lint.yaml new file mode 100644 index 0000000..46a5a88 --- /dev/null +++ b/.forgejo/workflows/lint.yaml @@ -0,0 +1,14 @@ +on: [push] + +jobs: + phplint: + runs-on: docker + steps: + - uses: actions/checkout@v3 + - uses: docker://cytopia/phplint:alpine + with: + cmd: -i ./vendor/.* *.php + - uses: github.com/DavidAnson/markdownlint-cli2-action@v13 + with: + globs: '**/*.md' + continue-on-error: true \ No newline at end of file diff --git a/.forgejo/workflows/phplint.yaml b/.forgejo/workflows/phplint.yaml deleted file mode 100644 index e2d7069..0000000 --- a/.forgejo/workflows/phplint.yaml +++ /dev/null @@ -1,10 +0,0 @@ -on: [push] - -jobs: - phplint: - runs-on: docker - steps: - - uses: actions/checkout@v3 - - uses: docker://cytopia/phplint:alpine - with: - cmd: -i ./vendor/.* *.php \ No newline at end of file From 5bcba0b6896b5278492894a7b0a11ce71b429aa1 Mon Sep 17 00:00:00 2001 From: David Bailey Date: Thu, 19 Oct 2023 21:54:37 +0200 Subject: [PATCH 8/8] refactor: move all HTTP-Website code into www subdirectory --- .htaccess | 6 --- www/.gitignore | 1 + www/.htaccess | 7 ++- composer.json => www/composer.json | 0 composer.lock => www/composer.lock | 0 www/dergstyle.css | 42 ------------------ www/index.php | 11 ----- router.php => www/router.php | 33 +++++++++++--- {static => www/static}/.htaccess | 0 {static => www/static}/banner.js | 0 {static => www/static}/banner/0.png | Bin {static => www/static}/banner/1.png | Bin {static => www/static}/banner/banner0.jpeg | Bin {static => www/static}/dergstyle.css | 0 {static => www/static}/gallerystyle.css | 0 {static => www/static}/icon.jpeg | Bin {static => www/static}/rrrorstyle.css | 0 {templates => www/templates}/about.html | 0 .../templates}/gallery/gallery_entry.html | 0 .../templates}/gallery/gallery_overview.html | 0 {templates => www/templates}/index.html | 0 {templates => www/templates}/root.dergplate | 0 {templates => www/templates}/root.html | 0 {templates => www/templates}/rrror.html | 0 {user_content => www/user_content}/about.md | 0 25 files changed, 33 insertions(+), 67 deletions(-) delete mode 100644 .htaccess create mode 100644 www/.gitignore rename composer.json => www/composer.json (100%) rename composer.lock => www/composer.lock (100%) delete mode 100644 www/dergstyle.css delete mode 100644 www/index.php rename router.php => www/router.php (66%) rename {static => www/static}/.htaccess (100%) rename {static => www/static}/banner.js (100%) rename {static => www/static}/banner/0.png (100%) rename {static => www/static}/banner/1.png (100%) rename {static => www/static}/banner/banner0.jpeg (100%) rename {static => www/static}/dergstyle.css (100%) rename {static => www/static}/gallerystyle.css (100%) rename {static => www/static}/icon.jpeg (100%) rename {static => www/static}/rrrorstyle.css (100%) rename {templates => www/templates}/about.html (100%) rename {templates => www/templates}/gallery/gallery_entry.html (100%) rename {templates => www/templates}/gallery/gallery_overview.html (100%) rename {templates => www/templates}/index.html (100%) rename {templates => www/templates}/root.dergplate (100%) rename {templates => www/templates}/root.html (100%) rename {templates => www/templates}/rrror.html (100%) rename {user_content => www/user_content}/about.md (100%) diff --git a/.htaccess b/.htaccess deleted file mode 100644 index 094dd6c..0000000 --- a/.htaccess +++ /dev/null @@ -1,6 +0,0 @@ - -RewriteEngine On -RewriteBase / - -RewriteCond %{REQUEST_URI} !^/?static/.* -RewriteRule (.*) router.php diff --git a/www/.gitignore b/www/.gitignore new file mode 100644 index 0000000..a725465 --- /dev/null +++ b/www/.gitignore @@ -0,0 +1 @@ +vendor/ \ No newline at end of file diff --git a/www/.htaccess b/www/.htaccess index 605d2f4..094dd6c 100644 --- a/www/.htaccess +++ b/www/.htaccess @@ -1 +1,6 @@ -Allow from all + +RewriteEngine On +RewriteBase / + +RewriteCond %{REQUEST_URI} !^/?static/.* +RewriteRule (.*) router.php diff --git a/composer.json b/www/composer.json similarity index 100% rename from composer.json rename to www/composer.json diff --git a/composer.lock b/www/composer.lock similarity index 100% rename from composer.lock rename to www/composer.lock diff --git a/www/dergstyle.css b/www/dergstyle.css deleted file mode 100644 index 1c31397..0000000 --- a/www/dergstyle.css +++ /dev/null @@ -1,42 +0,0 @@ - -body { - color: #B0B0B0; - background: #302A3F; -} - -:link { - color: cyan; - font-style: italic; - text-decoration: none; - - transition: color 0.2s; -} -:link:hover { - color: lightblue; -} - -ul { - display: flex; - flex-direction: row; - justify-content: center; - - list-style-type: none; - margin-top: 1em; - padding: 0px; -} -ul li { - padding: 0em 0.3em 0em 0.3em; -} - -#big_title { - text-align: center; - font-size: 2.5em; - margin-bottom: 0.2em; -} -#title_separator { - height: 1.5px; - background-color: #ddd; - opacity: 0.5; - margin-left: 2em; - margin-right: 2em; -} diff --git a/www/index.php b/www/index.php deleted file mode 100644 index 6084dcf..0000000 --- a/www/index.php +++ /dev/null @@ -1,11 +0,0 @@ -render('index.html',[ - "a_variable" => "is very spicy. In a good way." -]); -?> diff --git a/router.php b/www/router.php similarity index 66% rename from router.php rename to www/router.php index 57a3318..7d76a83 100644 --- a/router.php +++ b/www/router.php @@ -3,16 +3,30 @@ require_once 'vendor/autoload.php'; -$sql = mysqli_connect('mysql', 'root', 'example', 'mysql'); +$sql = mysqli_connect('mysql', 'root', 'example', 'dragon_fire'); -if (!$sql) -{ - echo 'Connection failed
'; - echo 'Error number: ' . mysqli_connect_errno() . '
'; - echo 'Error message: ' . mysqli_connect_error() . '
'; - die(); +function get_post_by_path($path) { + global $sql; + + $qry = "SELECT * FROM posts WHERE post_path = ?"; + + $stmt = $sql->prepare($qry); + $stmt->bind_param("s", $path); + $stmt->execute(); + + // $result = $stmt->get_result(); + + return $stmt->get_result()->fetch_assoc(); } +//if (!$sql) +// { +// echo 'Connection failed
'; +// echo 'Error number: ' . mysqli_connect_errno() . '
'; +// echo 'Error message: ' . mysqli_connect_error() . '
'; +// die(); +// } + $loader = new \Twig\Loader\FilesystemLoader(['./templates', './user_content']); $twig = new \Twig\Environment($loader,['debug' => true]); @@ -32,6 +46,11 @@ $twig->addRuntimeLoader(new class implements RuntimeLoaderInterface { if($_SERVER['REQUEST_URI'] == '/') { echo $twig->render('root.html'); +} elseif(preg_match('/^\/api\/posts(.*)$/', $_SERVER['REQUEST_URI'], $match)) { + + header('Content-Type: application/json'); + echo json_encode(get_post_by_path($match[1])); + } elseif(preg_match('/^\/about(.html)?$/', $_SERVER['REQUEST_URI'])) { echo $twig->render('about.html'); } elseif(preg_match('/^\/gallery\/([^\?]+)/', $_SERVER['REQUEST_URI'])) { diff --git a/static/.htaccess b/www/static/.htaccess similarity index 100% rename from static/.htaccess rename to www/static/.htaccess diff --git a/static/banner.js b/www/static/banner.js similarity index 100% rename from static/banner.js rename to www/static/banner.js diff --git a/static/banner/0.png b/www/static/banner/0.png similarity index 100% rename from static/banner/0.png rename to www/static/banner/0.png diff --git a/static/banner/1.png b/www/static/banner/1.png similarity index 100% rename from static/banner/1.png rename to www/static/banner/1.png diff --git a/static/banner/banner0.jpeg b/www/static/banner/banner0.jpeg similarity index 100% rename from static/banner/banner0.jpeg rename to www/static/banner/banner0.jpeg diff --git a/static/dergstyle.css b/www/static/dergstyle.css similarity index 100% rename from static/dergstyle.css rename to www/static/dergstyle.css diff --git a/static/gallerystyle.css b/www/static/gallerystyle.css similarity index 100% rename from static/gallerystyle.css rename to www/static/gallerystyle.css diff --git a/static/icon.jpeg b/www/static/icon.jpeg similarity index 100% rename from static/icon.jpeg rename to www/static/icon.jpeg diff --git a/static/rrrorstyle.css b/www/static/rrrorstyle.css similarity index 100% rename from static/rrrorstyle.css rename to www/static/rrrorstyle.css diff --git a/templates/about.html b/www/templates/about.html similarity index 100% rename from templates/about.html rename to www/templates/about.html diff --git a/templates/gallery/gallery_entry.html b/www/templates/gallery/gallery_entry.html similarity index 100% rename from templates/gallery/gallery_entry.html rename to www/templates/gallery/gallery_entry.html diff --git a/templates/gallery/gallery_overview.html b/www/templates/gallery/gallery_overview.html similarity index 100% rename from templates/gallery/gallery_overview.html rename to www/templates/gallery/gallery_overview.html diff --git a/templates/index.html b/www/templates/index.html similarity index 100% rename from templates/index.html rename to www/templates/index.html diff --git a/templates/root.dergplate b/www/templates/root.dergplate similarity index 100% rename from templates/root.dergplate rename to www/templates/root.dergplate diff --git a/templates/root.html b/www/templates/root.html similarity index 100% rename from templates/root.html rename to www/templates/root.html diff --git a/templates/rrror.html b/www/templates/rrror.html similarity index 100% rename from templates/rrror.html rename to www/templates/rrror.html diff --git a/user_content/about.md b/www/user_content/about.md similarity index 100% rename from user_content/about.md rename to www/user_content/about.md