From c2dd16ebebfbe9be99a08226fa70edf411e875b6 Mon Sep 17 00:00:00 2001 From: Nick Yeoman Date: Tue, 14 Apr 2020 19:20:25 -0700 Subject: [PATCH] added bookstack --- bookstack/ImportFromText.py | 48 +++++++++++++++++++++++++ bookstack/docker-compose.yml | 70 ++++++++++++++++++++++++++++++++++++ bookstack/env-sample | 4 +++ joomla/docker-compose.yml | 7 ++-- 4 files changed, 126 insertions(+), 3 deletions(-) create mode 100644 bookstack/ImportFromText.py create mode 100644 bookstack/docker-compose.yml create mode 100644 bookstack/env-sample diff --git a/bookstack/ImportFromText.py b/bookstack/ImportFromText.py new file mode 100644 index 0000000..2b8bb0e --- /dev/null +++ b/bookstack/ImportFromText.py @@ -0,0 +1,48 @@ +################################################################################ +# use like this: python3 run.py > test.sql +################################################################################ + +import os +import html +directory = '/home/nick/tmp/emails' + +# The insert statement to insert a page +print("INSERT INTO `pages` (`id`, `book_id`, `chapter_id`, `name`, `slug`, `html`, `text`, `priority`, `created_at`, `updated_at`, `created_by`, `updated_by`, `restricted`, `draft`, `markdown`, `revision_count`, `template`) VALUES" ) + +for filename in os.listdir(directory): + if filename.endswith(".txt"): + f = open(filename) + + #print filename + #print(filename) + + #print filenmae with no extension + base=os.path.basename(filename) + filenoext=os.path.splitext(base) + filenoext=str(filenoext[0]) + #print(filenoext[0]) + + # print file contents html safe + lines = f.read() + htmlcontentdirty=str(html.escape(lines)) + htmlcontentspaces=htmlcontentdirty.replace('\r', '
').replace('\n', '
') + htmlcontent=' '.join(htmlcontentspaces.split()) + + #generate slug + slugnospace=str(filenoext[0]).replace(" ", "_") + slug=slugnospace.lower() + + # now write the sql query + print("(NULL, '2', '0', '", end = '') + print(filenoext, end = '') + print("', '", end = '') + print(slug, end = '') + print("', '", end = '') + print(htmlcontent, end = '') + print("', 'text_var', '0', NOW(), NOW(), '1', '1', '0', '0', 'markdown_var', '0', '0'),") + + continue + else: + continue + +# TODO: you need to change the last comma to a semi colon for it to work in mysql diff --git a/bookstack/docker-compose.yml b/bookstack/docker-compose.yml new file mode 100644 index 0000000..5b8ce0f --- /dev/null +++ b/bookstack/docker-compose.yml @@ -0,0 +1,70 @@ +################################################################################ +# make sure you use the $PREFIX from .env for project_name +# docker-compose -p project_name up -d +# +# If you are importing directly using the db you have to do the following in the container: +# php artisan bookstack:regenerate-permissions +################################################################################ + +version: '2' + +volumes: + bookstack-db: + bookstack-uploads: + bookstack-storage: + +networks: + traefik_web: + external: + name: traefik_web + +services: + + bookstack-db: + image: mariadb:10.4.11 + restart: always + volumes: + - bookstack-db:/var/lib/mysql + networks: + - traefik_web + environment: + MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} + MYSQL_USER: bookstack + MYSQL_PASSWORD: ${MYSQL_PASSWORD} + MYSQL_DATABASE: bookstack + + # It's only exposed if someone knows the ip + bookstack-phpdb: + #https://hub.docker.com/r/phpmyadmin/phpmyadmin/tags + image: phpmyadmin/phpmyadmin:5.0 + environment: + - PMA_ARBITRARY=1 + external_links: + - bookstack-db + depends_on: + - bookstack-db + networks: + - traefik_web + + # https://hub.docker.com/r/solidnerd/bookstack + bookstack: + image: solidnerd/bookstack:0.29.0 + depends_on: + - bookstack-db + environment: + - DB_HOST=${PREFIX}_bookstack-db_1:3306 + - DB_DATABASE=bookstack + - DB_USERNAME=bookstack + - DB_PASSWORD=${MYSQL_PASSWORD} + - APP_URL=https://${DOMAIN_NAME} + networks: + - traefik_web + volumes: + - bookstack-uploads:/var/www/bookstack/public/uploads + - bookstack-storage:/var/www/bookstack/storage/uploads + labels: + - "traefik.enable=true" + - "traefik.http.routers.${PREFIX}_bookstack.rule=Host(`${DOMAIN_NAME}`)" + - "traefik.http.routers.${PREFIX}_bookstack.entrypoints=websecure" + - "traefik.http.routers.${PREFIX}_bookstack.tls=true" + - "traefik.http.services.${PREFIX}_bookstack.loadbalancer.server.port=8080" diff --git a/bookstack/env-sample b/bookstack/env-sample new file mode 100644 index 0000000..b44f89a --- /dev/null +++ b/bookstack/env-sample @@ -0,0 +1,4 @@ +MYSQL_ROOT_PASSWORD=ChangeMe2ASecurepass! +MYSQL_PASSWORD=Again2ASecurepass! +DOMAIN_NAME=bookstack.nickyeoman.com +PREFIX=p1 diff --git a/joomla/docker-compose.yml b/joomla/docker-compose.yml index 04ea5f1..bacbb5e 100644 --- a/joomla/docker-compose.yml +++ b/joomla/docker-compose.yml @@ -1,9 +1,10 @@ ---- -version: '3.3' - +################################################################################ # Update the .env file # make sure you use the $PREFIX from .env for project_name # docker-compose -p project_name up -d +################################################################################ +version: '3.3' + volumes: mariadb: joomla: