From 8dfea0993b3a68b3d78f44e4282ddcf73fea56cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Thu, 28 Sep 2023 10:01:31 +0200 Subject: [PATCH 01/14] add nodejs installer script --- docker/scripts/install-nodejs.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100755 docker/scripts/install-nodejs.sh diff --git a/docker/scripts/install-nodejs.sh b/docker/scripts/install-nodejs.sh new file mode 100755 index 0000000..f206a4f --- /dev/null +++ b/docker/scripts/install-nodejs.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +set -e + +apt update +apt install -y ca-certificates curl gnupg +mkdir -p /etc/apt/keyrings +curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg + +NODE_MAJOR=18 +echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list + +apt update +apt install -y nodejs -- 2.45.2 From 832170b1e1ea097e1838623dbce9fc30b79bd0bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Thu, 28 Sep 2023 10:01:38 +0200 Subject: [PATCH 02/14] add release generator script --- docker/scripts/release.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 docker/scripts/release.sh diff --git a/docker/scripts/release.sh b/docker/scripts/release.sh new file mode 100755 index 0000000..de54210 --- /dev/null +++ b/docker/scripts/release.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +set -e + +echo "Installing Composer packages..." +composer create-project --no-dev + +echo "Installing Yarn packages..." +(cd public/static && yarn install) + +echo "Updating version info..." +VERSION=$(git describe --tags --always --match "Release_*" HEAD) +REVISION=$(git rev-parse --short HEAD) +REVISION_DATE=$(git show -s --format=%aI HEAD) +sed -i -E "s/const VERSION = '(.*)';/const VERSION = '${VERSION}';/" app.php +sed -i -E "s/const REVISION = '(.*)';/const REVISION = '${REVISION}';/" app.php +sed -i -E "s/const REVISION_DATE = '(.*)';/const REVISION_DATE = '${REVISION_DATE}';/" app.php + +echo "Minifying JS, CSS and SVG files..." +find public/static/js -type f -iname '*.js' -exec uglifyjs {} -c -m -o {} \; +find public/static/css -type f -iname '*.css' -exec cleancss {} -o {} \; +find public/static/img -type f -iname '*.svg' -exec svgo {} -o {} \; + +echo "Linking view files..." +./rvr view:link + +rm .env -- 2.45.2 From eba674bfbc29d98943f26178e33981e6d73c90d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Thu, 28 Sep 2023 10:01:50 +0200 Subject: [PATCH 03/14] add cron for db:maintain --- docker/scripts/cron | 1 + 1 file changed, 1 insertion(+) create mode 100644 docker/scripts/cron diff --git a/docker/scripts/cron b/docker/scripts/cron new file mode 100644 index 0000000..b5a3ffa --- /dev/null +++ b/docker/scripts/cron @@ -0,0 +1 @@ +0 * * * * /var/www/rvr/rvr db:maintain -- 2.45.2 From 6870d08c21d5e0c5ad8ccf1611fafcd69f2b5bf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Thu, 28 Sep 2023 12:16:55 +0200 Subject: [PATCH 04/14] remove deprecated scripts --- scripts/deploy-to-multiple-worktrees.py | 162 ------------------------ scripts/install.sh | 32 ----- scripts/minify.sh | 11 -- scripts/update-version.sh | 17 --- scripts/update.sh | 26 ---- 5 files changed, 248 deletions(-) delete mode 100755 scripts/deploy-to-multiple-worktrees.py delete mode 100755 scripts/install.sh delete mode 100755 scripts/minify.sh delete mode 100755 scripts/update-version.sh delete mode 100755 scripts/update.sh diff --git a/scripts/deploy-to-multiple-worktrees.py b/scripts/deploy-to-multiple-worktrees.py deleted file mode 100755 index 4d7d7b2..0000000 --- a/scripts/deploy-to-multiple-worktrees.py +++ /dev/null @@ -1,162 +0,0 @@ -#!/usr/bin/python3 - -# Usage: ./deploy-to-multiple-worktrees.py REPO_PATH WORKTREE_DEVELOPMENT_PATH WORKTREE_PRODUCTION_PATH - -import sys -import os -import subprocess -import re - -WORKTREE_REGEX = r"^worktree (.*)\nHEAD ([a-f0-9]*)\n(?:branch refs\/heads\/(.*)|detached)$" - -if len(sys.argv) < 4: - print("Usage: ./deploy-to-multiple-worktrees.py REPO_PATH WORKTREE_DEVELOPMENT_PATH WORKTREE_PRODUCTION_PATH") - exit(1) - -REPO = os.path.abspath(sys.argv[1]) -WORKTREE_DEVELOPMENT = os.path.abspath(sys.argv[2]) -WORKTREE_PRODUCTION = os.path.abspath(sys.argv[3]) - -class Worktree: - def __init__(self, path, branch, revision, version): - self.path = path - self.branch = branch - self.revision = revision - self.version = version - self.newRevision = None - self.newVersion = None - -def getDataForWorktrees(): - ret = subprocess.check_output(["git", "worktree", "list", "--porcelain"], cwd=REPO).decode().strip() - blocks = ret.split("\n\n") - - worktrees = [] - - for block in blocks: - matches = re.search(WORKTREE_REGEX, block) - - if matches: - path = matches.group(1) - revision = matches.group(2) - branch = matches.group(3) - version = getVersion(revision) - - worktrees.append(Worktree(path, branch, revision, version)) - - return worktrees - -def findWorktree(path): - for worktree in worktrees: - if worktree.path == path: - return worktree - - return None - -def getVersion(branch): - return subprocess.check_output(["git", "describe", "--tags", "--always", "--match", "Release_*", branch], cwd=REPO).decode().strip() - -def getRevisionForRef(ref): - return subprocess.check_output(["git", "rev-list", "-1", ref], cwd=REPO).decode().strip() - -def getLatestReleaseTag(): - process = subprocess.Popen(["git", "for-each-ref", "refs/tags/Release*", "--sort=-creatordate", "--format=%(refname:short)"], stdout=subprocess.PIPE, cwd=REPO) - - for line in process.stdout: - tag = line.decode().rstrip() - - if isTagVerified(tag): - return tag - - print(f"[WARNING] Tag '{tag}' is not verified, skipping.") - - raise Exception("No verified 'Release*' tag found!") - -def isTagVerified(tag): - process = subprocess.run(["git", "tag", "--verify", tag], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=REPO) - - return process.returncode == 0 - -def updateRepoFromRemote(): - subprocess.call(["git", "fetch", "origin", "--prune", "--prune-tags"], cwd=REPO) - -def checkoutWorktree(worktreePath, ref): - subprocess.call(["git", "checkout", "-f", ref], cwd=worktreePath) - -def cleanWorktree(worktreePath): - subprocess.call(["git", "clean", "-f", "-d"], cwd=worktreePath) - -def updateAppInWorktree(worktreePath): - subprocess.call([worktreePath + "/scripts/update.sh"], cwd=worktreePath) - -def updateAppVersionInWorktree(worktreePath): - subprocess.call([worktreePath + "/scripts/update-version.sh"], cwd=worktreePath) - -worktrees = getDataForWorktrees() - -updateRepoFromRemote() - -print("Repo is updated from origin") - -print("----------------------------------------------") -print("----------------------------------------------") - -developmentWorktree = findWorktree(WORKTREE_DEVELOPMENT) - -developmentWorktree.newRevision = getRevisionForRef(developmentWorktree.branch) -developmentWorktree.newVersion = getVersion(developmentWorktree.revision) - -print("DEVELOPMENT (" + developmentWorktree.path + ") is on branch " + developmentWorktree.branch) -print(developmentWorktree.revision + " = " + developmentWorktree.branch + " (" + developmentWorktree.version + ")") -print(developmentWorktree.newRevision + " = origin/" + developmentWorktree.branch + " (" + developmentWorktree.newVersion + ")") - -if developmentWorktree.revision != developmentWorktree.newRevision: - print("-> DEVELOPMENT (" + developmentWorktree.path + ") will be UPDATED") - print("----------------------------------------------") - - checkoutWorktree(developmentWorktree.path, developmentWorktree.branch) - cleanWorktree(developmentWorktree.path) - - print(developmentWorktree.path + " is checked out to " + developmentWorktree.branch + " and cleaned") - - updateAppInWorktree(developmentWorktree.path) - updateAppVersionInWorktree(developmentWorktree.path) - - print("RVR is updated in " + developmentWorktree.path) -elif developmentWorktree.version != developmentWorktree.newVersion: - print("-> DEVELOPMENT " + developmentWorktree.path + "'s version info will be UPDATED") - - updateAppVersionInWorktree(developmentWorktree.path) - - print("RVR version is updated in " + developmentWorktree.path) -else: - print("-> DEVELOPMENT (" + developmentWorktree.path + ") WON'T be updated") - -print("----------------------------------------------") -print("----------------------------------------------") - -productionWorktree = findWorktree(WORKTREE_PRODUCTION) - -productionWorktree.newVersion = getLatestReleaseTag() -productionWorktree.newRevision = getRevisionForRef(productionWorktree.newVersion) - -print("PRODUCTION (" + productionWorktree.path + ")") -print(productionWorktree.revision + " = " + productionWorktree.version) -print(productionWorktree.newRevision + " = " + productionWorktree.newVersion) - -if productionWorktree.revision != productionWorktree.newRevision: - print("-> PRODUCTION (" + productionWorktree.path + ") will be UPDATED") - - checkoutWorktree(productionWorktree.path, productionWorktree.newRevision) - cleanWorktree(productionWorktree.path) - - print(productionWorktree.path + " is checked out to " + productionWorktree.newRevision + " and cleaned") - - updateAppInWorktree(productionWorktree.path) - updateAppVersionInWorktree(productionWorktree.path) - - print("RVR is updated in " + productionWorktree.path) -else: - print("-> PRODUCTION (" + productionWorktree.path + ") WON'T be updated") - -print("----------------------------------------------") -print("----------------------------------------------") diff --git a/scripts/install.sh b/scripts/install.sh deleted file mode 100755 index bd1bf30..0000000 --- a/scripts/install.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash - -ROOT_DIR=$(dirname $(readlink -f "$0"))/.. - -. ${ROOT_DIR}/.env - -if [ -f ${ROOT_DIR}/installed ]; then - echo "RVR is already installed! To force reinstall, delete file 'installed' from the root directory!" - exit 1 -fi - -echo "Installing Yarn packages..." -(cd ${ROOT_DIR}/public/static && yarn install) - -echo "Installing RVR DB..." -mysql --host=${DB_HOST} --user=${DB_USER} --password=${DB_PASSWORD} ${DB_NAME} < ${ROOT_DIR}/database/rvr.sql - -echo "Migrating DB..." -(cd ${ROOT_DIR} && ./rvr db:migrate) - -if [ -z "${DEV}" ] || [ "${DEV}" -eq "0" ]; then - echo "Minifying JS, CSS and SVG files..." - ${ROOT_DIR}/scripts/minify.sh - - echo "Linking view files..." - (cd ${ROOT_DIR} && ./rvr view:link) -else - echo "Creating the first user..." - (cd ${ROOT_DIR} && ./rvr user:add rvr@rvr.dev 123456 admin) -fi - -touch ${ROOT_DIR}/installed diff --git a/scripts/minify.sh b/scripts/minify.sh deleted file mode 100755 index bcf6a6a..0000000 --- a/scripts/minify.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -ROOT_DIR=$(dirname $(readlink -f "$0"))/.. - -. ${ROOT_DIR}/.env - -find ${ROOT_DIR}/public/static/js -type f -iname '*.js' -exec uglifyjs {} -c -m -o {} \; - -find ${ROOT_DIR}/public/static/css -type f -iname '*.css' -exec cleancss {} -o {} \; - -find ${ROOT_DIR}/public/static/img -type f -iname '*.svg' -exec svgo {} -o {} \; diff --git a/scripts/update-version.sh b/scripts/update-version.sh deleted file mode 100755 index 817579d..0000000 --- a/scripts/update-version.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -ROOT_DIR=$(dirname $(readlink -f "$0"))/.. - -. ${ROOT_DIR}/.env - -cd ${ROOT_DIR} - -echo "Updating version info..." - -VERSION=$(git describe --tags --always --match "Release_*" HEAD) -REVISION=$(git rev-parse --short HEAD) -REVISION_DATE=$(git show -s --format=%aI HEAD) - -sed -i -E "s/const VERSION = '(.*)';/const VERSION = '${VERSION}';/" app.php -sed -i -E "s/const REVISION = '(.*)';/const REVISION = '${REVISION}';/" app.php -sed -i -E "s/const REVISION_DATE = '(.*)';/const REVISION_DATE = '${REVISION_DATE}';/" app.php diff --git a/scripts/update.sh b/scripts/update.sh deleted file mode 100755 index bdaffb4..0000000 --- a/scripts/update.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -ROOT_DIR=$(dirname $(readlink -f "$0"))/.. - -. ${ROOT_DIR}/.env - -echo "Installing Composer packages..." -if [ -z "${DEV}" ] || [ "${DEV}" -eq "0" ]; then - (cd ${ROOT_DIR} && composer install --no-dev) -else - (cd ${ROOT_DIR} && composer install --dev) -fi - -echo "Installing Yarn packages..." -(cd ${ROOT_DIR}/public/static && yarn install) - -echo "Migrating DB..." -(cd ${ROOT_DIR} && ./rvr db:migrate) - -if [ -z "${DEV}" ] || [ "${DEV}" -eq "0" ]; then - echo "Minifying JS, CSS and SVG files..." - ${ROOT_DIR}/scripts/minify.sh - - echo "Linking view files..." - (cd ${ROOT_DIR} && ./rvr view:link) -fi -- 2.45.2 From 1718dfca9edb97e906a4e30a38bdd61f5725492e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Sat, 16 Sep 2023 20:29:55 +0200 Subject: [PATCH 05/14] install base database in MigrateDatabaseCommand --- src/Cli/MigrateDatabaseCommand.php | 31 +++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/Cli/MigrateDatabaseCommand.php b/src/Cli/MigrateDatabaseCommand.php index f784736..40209eb 100644 --- a/src/Cli/MigrateDatabaseCommand.php +++ b/src/Cli/MigrateDatabaseCommand.php @@ -19,6 +19,8 @@ class MigrateDatabaseCommand extends Command { $db = \Container::$dbConnection; + $this->createBaseDb(); + $db->startTransaction(); $success = []; @@ -62,10 +64,8 @@ class MigrateDatabaseCommand extends Command return 0; } - private function readDir(string $type): array + private function createBaseDb() { - $done = []; - $migrationTableExists = \Container::$dbConnection->query('SELECT count(*) FROM information_schema.tables WHERE table_schema = \'' . $_ENV['DB_NAME'] . '\' @@ -73,16 +73,25 @@ class MigrateDatabaseCommand extends Command ->fetch(IResultSet::FETCH_NUM)[0]; if ($migrationTableExists != 0) { - $select = new Select(\Container::$dbConnection, 'migrations'); - $select->columns(['migration']); - $select->where('type', '=', $type); - $select->orderBy('migration'); + return; + } - $result = $select->execute(); + \Container::$dbConnection->multiQuery(file_get_contents(ROOT . '/database/rvr.sql')); + } - while ($migration = $result->fetch(IResultSet::FETCH_ASSOC)) { - $done[] = $migration['migration']; - } + private function readDir(string $type): array + { + $done = []; + + $select = new Select(\Container::$dbConnection, 'migrations'); + $select->columns(['migration']); + $select->where('type', '=', $type); + $select->orderBy('migration'); + + $result = $select->execute(); + + while ($migration = $result->fetch(IResultSet::FETCH_ASSOC)) { + $done[] = $migration['migration']; } $path = ROOT . '/database/migrations/' . $type; -- 2.45.2 From 27fe883f5991eed043732fd9cd29902cc66614d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Thu, 28 Sep 2023 10:02:00 +0200 Subject: [PATCH 06/14] add entry point for release docker --- docker/scripts/entry-point.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 docker/scripts/entry-point.sh diff --git a/docker/scripts/entry-point.sh b/docker/scripts/entry-point.sh new file mode 100755 index 0000000..f9dfa54 --- /dev/null +++ b/docker/scripts/entry-point.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +set -e + +echo "Migrating DB..." +./rvr db:migrate + +echo "Installing crontab..." +/usr/bin/crontab docker/scripts/cron + +echo "Set runner user based on owner of .env..." +USER_UID=$(stat -c "%u" .env) +USER_GID=$(stat -c "%g" .env) +groupadd --gid $USER_GID rvr +useradd --uid $USER_UID --gid $USER_GID rvr +chown -R rvr:rvr cache +sed -i -e "s/^user = .*$/user = rvr/g" -e "s/^group = .*$/group = rvr/g" /etc/php/7.4/fpm/pool.d/www.conf + +set +e + +/usr/sbin/cron -f & +/usr/sbin/php-fpm7.4 -F & +/usr/sbin/nginx -g 'daemon off;' & + +wait -n + +exit $? -- 2.45.2 From bdfa46b838998a461b786019b3de1b5703074958 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Thu, 28 Sep 2023 10:02:06 +0200 Subject: [PATCH 07/14] add entry point for dev docker --- docker/scripts/entry-point-dev.sh | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 docker/scripts/entry-point-dev.sh diff --git a/docker/scripts/entry-point-dev.sh b/docker/scripts/entry-point-dev.sh new file mode 100755 index 0000000..0d5fe81 --- /dev/null +++ b/docker/scripts/entry-point-dev.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +set -e + +echo "Installing Composer packages..." +if [ -f .env ]; then + composer install +else + composer create-project +fi + +echo "Installing Yarn packages..." +(cd public/static && yarn install) + +echo "Migrating DB..." +./rvr db:migrate + +echo "Set runner user based on owner of .env..." +USER_UID=$(stat -c "%u" .env) +USER_GID=$(stat -c "%g" .env) +groupadd --gid $USER_GID rvr +useradd --uid $USER_UID --gid $USER_GID rvr +sed -i -e "s/^user = .*$/user = rvr/g" -e "s/^group = .*$/group = rvr/g" /etc/php/7.4/fpm/pool.d/www.conf + +set +e + +/usr/sbin/php-fpm7.4 -F & +/usr/sbin/nginx -g 'daemon off;' & + +wait -n + +exit $? -- 2.45.2 From 147b7690ac7c57beb6324cf6b481678c82285344 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Thu, 28 Sep 2023 10:02:18 +0200 Subject: [PATCH 08/14] add new dockerfile with dev and release stages --- docker/Dockerfile | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 docker/Dockerfile diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..f511e28 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,44 @@ +FROM ubuntu:focal AS rvr_base + +ENV DEBIAN_FRONTEND noninteractive + +RUN apt update --fix-missing && apt install -y sudo curl git unzip mariadb-client nginx \ + php-apcu php7.4-cli php7.4-curl php7.4-fpm php7.4-mbstring php7.4-mysql php7.4-zip php7.4-xml + +RUN mkdir -p /run/php +COPY docker/configs/nginx.conf /etc/nginx/sites-available/default + +COPY docker/scripts/install-composer.sh install-composer.sh +RUN ./install-composer.sh + +COPY docker/scripts/install-nodejs.sh install-nodejs.sh +RUN ./install-nodejs.sh +RUN npm install -g uglify-js clean-css-cli svgo yarn + + +FROM rvr_base AS rvr_dev + +RUN apt update --fix-missing && apt install -y php-xdebug + +RUN echo "xdebug.remote_enable = 1" >> /etc/php/7.4/mods-available/xdebug.ini &&\ + echo "xdebug.remote_autostart = 1" >> /etc/php/7.4/mods-available/xdebug.ini &&\ + echo "xdebug.remote_connect_back = 1" >> /etc/php/7.4/mods-available/xdebug.ini + +EXPOSE 80 +EXPOSE 5000 +EXPOSE 8090 +EXPOSE 9229 +ENTRYPOINT docker/scripts/entry-point-dev.sh + + +FROM rvr_base AS rvr_release + +RUN apt update --fix-missing && apt install -y cron + +WORKDIR /var/www/rvr +COPY ./ /var/www/rvr +RUN rm -rf /var/www/rvr/.git + +EXPOSE 80 +EXPOSE 8090 +ENTRYPOINT docker/scripts/entry-point.sh -- 2.45.2 From c4dce94f5e9f5ed0ae0ab9515f5b547eca008811 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Thu, 28 Sep 2023 12:17:23 +0200 Subject: [PATCH 09/14] delete deprecated dockerfiles --- docker/Dockerfile-app | 30 ------------------------------ docker/Dockerfile-test | 6 ------ 2 files changed, 36 deletions(-) delete mode 100644 docker/Dockerfile-app delete mode 100644 docker/Dockerfile-test diff --git a/docker/Dockerfile-app b/docker/Dockerfile-app deleted file mode 100644 index b053a86..0000000 --- a/docker/Dockerfile-app +++ /dev/null @@ -1,30 +0,0 @@ -FROM ubuntu:focal - -ENV DEBIAN_FRONTEND noninteractive - -# Install Nginx, PHP and further necessary packages -RUN apt update --fix-missing -RUN apt install -y curl git unzip mariadb-client nginx \ - php-apcu php-xdebug php7.4-cli php7.4-curl php7.4-fpm php7.4-mbstring php7.4-mysql php7.4-zip php7.4-xml - -# Configure Nginx with PHP -RUN mkdir -p /run/php -COPY configs/nginx.conf /etc/nginx/sites-available/default -RUN echo "xdebug.remote_enable = 1" >> /etc/php/7.4/mods-available/xdebug.ini -RUN echo "xdebug.remote_autostart = 1" >> /etc/php/7.4/mods-available/xdebug.ini -RUN echo "xdebug.remote_connect_back = 1" >> /etc/php/7.4/mods-available/xdebug.ini - -# Install Composer -COPY scripts/install-composer.sh install-composer.sh -RUN ./install-composer.sh - -# Install Node.js and required packages -RUN curl -sL https://deb.nodesource.com/setup_14.x | bash - -RUN apt install -y nodejs -RUN npm install -g uglify-js clean-css-cli svgo yarn - -EXPOSE 80 -VOLUME /var/www/rvr -WORKDIR /var/www/rvr - -ENTRYPOINT /usr/sbin/php-fpm7.4 -F & /usr/sbin/nginx -g 'daemon off;' diff --git a/docker/Dockerfile-test b/docker/Dockerfile-test deleted file mode 100644 index 915d332..0000000 --- a/docker/Dockerfile-test +++ /dev/null @@ -1,6 +0,0 @@ -FROM ubuntu:focal - -ENV DEBIAN_FRONTEND noninteractive - -RUN apt update && apt install -y curl git unzip php7.4-cli php7.4-mbstring php7.4-xml -RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer -- 2.45.2 From 5eeac18b4c86a028b0cadac06699a5c9274b7249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Thu, 28 Sep 2023 12:03:23 +0200 Subject: [PATCH 10/14] use the new dockerfile in pipeline --- Jenkinsfile | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index e3e225c..8a53b66 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -13,8 +13,9 @@ pipeline { } agent { dockerfile { - filename 'docker/Dockerfile-test' + filename 'docker/Dockerfile' dir '.' + additionalBuildArgs '--target rvr_base' reuseNode true } } @@ -26,8 +27,9 @@ pipeline { stage('Unit Testing') { agent { dockerfile { - filename 'docker/Dockerfile-test' + filename 'docker/Dockerfile' dir '.' + additionalBuildArgs '--target rvr_base' reuseNode true } } @@ -44,8 +46,9 @@ pipeline { stage('Static Code Analysis') { agent { dockerfile { - filename 'docker/Dockerfile-test' + filename 'docker/Dockerfile' dir '.' + additionalBuildArgs '--target rvr_base' reuseNode true } } -- 2.45.2 From cbf62d1c4a0aeefbb222da3d479725b36def693a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Thu, 28 Sep 2023 12:04:49 +0200 Subject: [PATCH 11/14] add docker release stage to pipeline --- Jenkinsfile | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 8a53b66..41211b4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -61,5 +61,46 @@ pipeline { } } } + + stage('Prepare Docker release') { + environment { + COMPOSER_HOME="${WORKSPACE}/.composer" + npm_config_cache="${WORKSPACE}/.npm" + } + agent { + dockerfile { + filename 'docker/Dockerfile' + dir '.' + additionalBuildArgs '--target rvr_base' + reuseNode true + } + } + steps { + script { + sh script: 'git clean -ffdx', label: 'Clean repository' + env.VERSION = sh(script: 'git describe --tags --always --match "Release_*" HEAD', returnStdout: true).trim() + sh script: 'docker/scripts/release.sh', label: 'Release script' + sh script: "rm -rf ${env.COMPOSER_HOME} ${env.npm_config_cache}" + } + } + } + + stage('Release Docker image') { + steps { + script { + withDockerRegistry([credentialsId: 'gitea-system-user', url: 'https://git.esoko.eu/']) { + sh script: 'docker buildx create --use --bootstrap --platform=linux/arm64,linux/amd64 --name multi-platform-builder' + sh script: """docker buildx build \ + --platform linux/amd64,linux/arm64 \ + -f docker/Dockerfile \ + --target rvr_release \ + -t git.esoko.eu/esoko/rvr:${env.VERSION} \ + --push \ + .""", + label: 'Build Docker image' + } + } + } + } } } -- 2.45.2 From 0d1e4a3d1cf0d1ab5c41e1162d52e0a7def2c8bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Thu, 28 Sep 2023 10:02:55 +0200 Subject: [PATCH 12/14] update docker-compose --- docker-compose.yml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 6b40c33..4a43d3e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,12 +2,17 @@ version: '3' services: app: build: - context: ./docker - dockerfile: Dockerfile-app + context: . + dockerfile: docker/Dockerfile + target: rvr_dev + depends_on: + mariadb: + condition: service_healthy ports: - 80:80 volumes: - .:/var/www/rvr + working_dir: /var/www/rvr mariadb: image: mariadb:10.3 ports: @@ -19,6 +24,13 @@ services: MYSQL_DATABASE: 'rvr' MYSQL_USER: 'rvr' MYSQL_PASSWORD: 'rvr' + healthcheck: + test: ["CMD-SHELL", "mysqladmin -u $$MYSQL_USER -p$$MYSQL_PASSWORD ping -h localhost || exit 1"] + start_period: 5s + start_interval: 1s + interval: 5s + timeout: 5s + retries: 5 adminer: image: adminer:4.8.1-standalone ports: -- 2.45.2 From 0ce1c4f28a284e57ff2ee34346788ac407d17946 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Thu, 28 Sep 2023 11:33:37 +0200 Subject: [PATCH 13/14] update soko-web --- composer.json | 2 +- composer.lock | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 2a5b307..434b111 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ } ], "require": { - "esoko/soko-web": "0.13.1", + "esoko/soko-web": "0.14.1", "firebase/php-jwt": "^6.4" }, "require-dev": { diff --git a/composer.lock b/composer.lock index ed3b648..b7bc91f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "59130fbd82b1c81275666b16adb0c1a1", + "content-hash": "2fdc479615518ac79d67b0a3f72ea2cb", "packages": [ { "name": "cocur/slugify", @@ -82,11 +82,11 @@ }, { "name": "esoko/soko-web", - "version": "v0.13.1", + "version": "v0.14.1", "source": { "type": "git", "url": "https://git.esoko.eu/esoko/soko-web.git", - "reference": "8bf495c89b4ce1456da1133adc285003e544dd48" + "reference": "7210b24aa31f47a55125a7c1f74267313f372559" }, "require": { "cocur/slugify": "^4.3", @@ -108,7 +108,7 @@ "GNU GPL 3.0" ], "description": "Lightweight web framework", - "time": "2023-07-08T12:38:40+00:00" + "time": "2023-09-26T22:26:55+00:00" }, { "name": "firebase/php-jwt", @@ -3152,5 +3152,5 @@ "prefer-lowest": false, "platform": [], "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } -- 2.45.2 From 9ffde6bccbd24570d298336102f2a8a4ec78296f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Thu, 28 Sep 2023 13:31:26 +0200 Subject: [PATCH 14/14] update readme --- README.md | 118 +++++++++++++++++++++++++++--------------------------- 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/README.md b/README.md index e9d25ba..345b8f7 100644 --- a/README.md +++ b/README.md @@ -2,81 +2,81 @@ [![Build Status](https://ci.esoko.eu/job/rvr-nextgen/job/master/badge/icon)](https://ci.esoko.eu/job/rvr-nextgen/job/master/) -This is the RVR Application project. This is a game about guessing where you are based on a street view panorama - inspired by existing applications. +This is the RVR Application project. ## Installation -### Clone the Git repository +### Set environment variables -The first step is obviously cloning the repository to your machine: +The `.env` file contains several environment variables that are needed by the application to work properly. These should be configured for your environment. Check `.env.example` for reference. + +**Important: `DEV` should NOT be set for production! See section Development if you want to use the application in development mode.** + +### Docker Compose + +Create a `docker-compose.yml` file. The example code below assumes that `.env` is placed in the same folder. + +```yml +version: '3' +services: + app: + image: git.esoko.eu/esoko/rvr:latest + depends_on: + mariadb: + condition: service_healthy + ports: + - 80:80 + volumes: + - .env:/var/www/rvr/.env + mariadb: + image: mariadb:10.3 + volumes: + - mysql:/var/lib/mysql + environment: + MYSQL_ROOT_PASSWORD: 'root' + MYSQL_DATABASE: 'rvr' + MYSQL_USER: 'rvr' + MYSQL_PASSWORD: 'rvr' + healthcheck: + test: ["CMD-SHELL", "mysqladmin -u $$MYSQL_USER -p$$MYSQL_PASSWORD ping -h localhost || exit 1"] + start_period: 5s + start_interval: 1s + interval: 5s + timeout: 5s + retries: 5 +volumes: + mysql: -``` -git clone https://git.esoko.eu/esoko/rvr-nextgen.git ``` -All the commands listed here should be executed from the repository root. - -### Setup Docker stack (recommended) - -The easiest way to build up a fully working application with web server and database is to use Docker Compose with the included `docker-compose.yml`. - -All you have to do is executing the following command: - -``` +Execute the following command: +```bash docker compose up -d ``` -Attach shell to the container of `rvr-nextgen-app`: -``` -docker exec -it rvr-nextgen-app bash -``` - -All of the following commands should be executed there. - -### Manual setup (alternative) - -If you don't use the Docker stack you need to install your environment manually. Check `docker-compose.yml` and `docker/Dockerfile` to see the system requirements. - -### Initialize project - -This command installes all of the Composer requirements and creates a copy of the example `.env` file. - -``` -composer create-project -``` - -### Set environment variables - -The `.env` file contains several environment variables that are needed by the application to work properly. These should be configured for your environment. - -One very important variable is `DEV`. This indicates that the application operates in development (staging) and not in production mode. - -**Hint:** If you install the application in the Docker stack for development (staging) environment, only the variables for external dependencies (API keys, map attribution, etc.) should be adapted. All other variables (for DB connection, static root, mailing, multiplayer, etc.) are fine with the default value. - -### (Production only) Create cron job - -To maintain database (delete inactive users, old sessions etc.), the command `db:maintain` should be regularly executed. It is recommended to create a cron job that runs every hour: - -``` -0 * * * * /path/to/your/installation/rvr db:maintain >>/var/log/cron-rvr.log 2>&1 -``` - -### Finalize installation - -After you followed the above steps, execute the following command: - -``` -scripts/install.sh -``` - -**And you are done!** The application is ready to use and develop. In development mode an administrative user is also created by the installation script, email is **rvr@rvr.dev**, password is **123456**. In production mode you should create the first administrative user with the following command: +**And you are done!** The application is ready to use. You can create the first administrative user with the following command after attaching to the `app` container: ``` ./rvr user:add EMAIL PASSWORD admin ``` -If you installed it in the Docker stack, you can reach it on http://localhost. The mails that are sent by the application can be found on http://localhost:8080/. If needed, the database server can be directly reached on localhost:3306. +## Development + +### Set environment variables + +`.env.example` should be copied to `.env` into the repo root. Only the variables for external dependencies (API keys, map attribution, etc.) should be adapted. All other variables (for DB connection, static root, mailing, multiplayer, etc.) are fine with the default value. **`DEV=1` should be set for development!** + +### Docker Compose + +Execute the following command from the repo root: +```bash +docker compose up -d +``` + +**And you are done!** You can reach the application on http://localhost. The mails that are sent by the application can be found on http://localhost:8080. If needed, the database server can be directly reached on localhost:3306, or you can use Adminer web interface on http://localhost:9090 + +You might have to attach to the `app` container, e.g. for creating users, `composer update`, etc. --- -- 2.45.2