Skip to content

Commit

Permalink
Feature/render hugo for docker (#17)
Browse files Browse the repository at this point in the history
* Add learners config for docker deployment

* Add db files to gitignore

* Bind volumes

* Remove unused folders

* Add hugo render helper script

* Change mount dirs

Co-authored-by: Lenhard Reuter <lenhard.reuter@ait.ac.at>
  • Loading branch information
git-lreuter and Lenhard Reuter authored Aug 19, 2022
1 parent 2dec805 commit 335dd83
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ develop_config.yml
learners/static/gen
learners/static/documentation
learners/static/exercises
data/
learners_data/*.db
rendered_hugo_content/

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
19 changes: 11 additions & 8 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ services:
image: ghcr.io/ait-cs-iaas/learners
ports:
- "${LEARNERS_PORT:-8080}:8080"
environment:
- REMOVE_DB=${REMOVE_DB}
volumes:
- "learners_exercises:/opt/learners/webroot/exercises"
- "learners_documentation:/opt/learners/webroot/documentation"
- "learners_data:/opt/learners/data"

volumes:
learners_exercises:
learners_documentation:
learners_data:
- type: bind
source: ./rendered_hugo_content/exercises
target: /opt/learners/webroot/exercises
- type: bind
source: ./rendered_hugo_content/documentation
target: /opt/learners/webroot/documentation
- type: bind
source: ./learners_data
target: /opt/learners/data
Empty file added learners_data/.gitkeep
Empty file.
43 changes: 43 additions & 0 deletions learners_data/learners_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# learners:
# theme: "dark"

jwt:
jwt_secret_key: "53CR3T"
jwt_for_vnc_access: False

database:
db_uri: "sqlite:////opt/learners/data/learners_tracker.db"

documentation:
directory: "/opt/learners/webroot/documentation"
endpoint: "/documentation"

exercises:
directory: "/opt/learners/webroot/exercises"
endpoint: "/exercises"

callback:
endpoint: "http://localhost:8080/callback"

venjix:
auth_secret: "53CR3T"
url: "http://localhost:5001"

novnc:
server: "http://localhost:5002"

screenSharing: True

users:
test:
password: test
is_presenter: True
user1:
password: user1
user2:
password: user2
user3:
password: user3
admin:
is_admin: True
password: admin
79 changes: 79 additions & 0 deletions render_content.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env python3

import os
import yaml
import sys, getopt


def main(argv):
contentBaseDir = ""
outputDir = ""
config_file = ""

try:
opts, args = getopt.getopt(argv, "hi:o:c:", ["input=", "output=", "config="])
except getopt.GetoptError:
print("render_content.py -i <contentBaseDir> -o <outputDir> -c <configFile>")
sys.exit(2)
for opt, arg in opts:
if opt == "-h":
print("render_content.py -i <contentBaseDir> -o <outputDir> -c <configFile>")
sys.exit()
elif opt in ("-i", "--input"):
contentBaseDir = arg
elif opt in ("-o", "--output"):
outputDir = arg
elif opt in ("-c", "--config"):
config_file = arg

currentDir = os.getcwd()

if not outputDir:
outputDir = f"{currentDir}/rendered_hugo_content"

if not contentBaseDir:
print(
"Please specify the content base directory (directory of the hugo files)\nrender_content.py -i <absolute path> or\nrender_content.py --input <absolute path>"
)
return

if not config_file:
config_file = os.getenv("LEARNERS_CONFIG") or os.path.join(currentDir, "learners_config.yml")

learners_config = {}

try:
with open(config_file, "r") as stream:
learners_config = yaml.safe_load(stream)
except Exception as err:
print(err)

users = learners_config.get("users")

for user, _ in users.items():
for contentType in ["documentation", "exercises"]:

# render hugo content
command = "hugo"
baseUrl = f"-b /{contentType}"
publishDir = f"-d {outputDir}/{contentType}/{user}"
contentDir = f"-c {contentBaseDir}/content/{contentType}"
if contentType == "documentation":
config = f"--config {contentBaseDir}/base_config.yaml,{contentBaseDir}/docu_config.yaml"
else:
config = f"--config {contentBaseDir}/base_config.yaml,{contentBaseDir}/{contentType}_config.yaml"
themesDir = f"--themesDir {contentBaseDir}/themes/"
clean = "--cleanDestinationDir"

print("-" * 100)
print(f"Rendering hugo content for user: {user} ...")

command = f"{command} {config} {baseUrl} {publishDir} {contentDir} {themesDir} {clean}"
os.system(command)

print(f"Rendered content: {publishDir}")
print("-" * 100 + "\n")


if __name__ == "__main__":
main(sys.argv[1:])

0 comments on commit 335dd83

Please sign in to comment.