Skip to content

Commit

Permalink
remove rich from docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
zaanposni committed Jan 2, 2024
1 parent d7e8089 commit dfaa2c1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
1 change: 0 additions & 1 deletion nginx/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ RUN npm install
RUN npm run build

RUN apt update && apt install -y python3-pip
RUN python3 -m pip install rich
RUN python3 hashbuild.py

FROM nginx:alpine
Expand Down
28 changes: 12 additions & 16 deletions nginx/masz-svelte/hashbuild.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import hashlib
import shutil

from rich.console import Console


# generate hash based on file content above
def generate_hash(file_content: str):
return hashlib.sha256(file_content.encode("utf-8")).hexdigest()

console = Console()

with open("public/index.html") as fh:
index_html = fh.read()

Expand All @@ -25,7 +21,7 @@ def generate_hash(file_content: str):
with open("public/build/bundle.css") as fh:
bundle_css = fh.read()

console.log("Generating hashes...")
print("Generating hashes...")

LANGUAGES = [
"en",
Expand All @@ -48,15 +44,15 @@ def generate_hash(file_content: str):
main_js_map_hash = generate_hash(main_js_map)
bundle_css_hash = generate_hash(bundle_css)

console.log("Generated hashes:")
console.log(f"global_css: {global_css_hash}")
console.log(f"main_js: {main_js_hash}")
console.log(f"main_js_map: {main_js_map_hash}")
console.log(f"bundle_css: {bundle_css_hash}")
print("Generated hashes:")
print(f"global_css: {global_css_hash}")
print(f"main_js: {main_js_hash}")
print(f"main_js_map: {main_js_map_hash}")
print(f"bundle_css: {bundle_css_hash}")
for lang in languages_hashes:
console.log(f"{lang}.json: {languages_hashes[lang]}")
print(f"{lang}.json: {languages_hashes[lang]}")

console.log("Writing hashes to index.html...")
print("Writing hashes to index.html...")

index_html = index_html.replace(
"global.css", f"global-{global_css_hash}.css"
Expand All @@ -71,7 +67,7 @@ def generate_hash(file_content: str):
with open("public/index.html", "w") as fh:
fh.write(index_html)

console.log("Writing hashes to bundle.js and bundle.js.map ...")
print("Writing hashes to bundle.js and bundle.js.map ...")
for lang in languages_hashes:
main_js = main_js.replace(
f"/i18n/{lang}.json", f"/i18n/{lang}-{languages_hashes[lang]}.json"
Expand All @@ -89,7 +85,7 @@ def generate_hash(file_content: str):
with open("public/build/bundle.js.map", "w") as fh:
fh.write(main_js_map)

console.log("Moving files...")
print("Moving files...")

shutil.move("public/global.css", f"public/global-{global_css_hash}.css")
shutil.move("public/build/bundle.js", f"public/build/bundle-{main_js_hash}.js")
Expand All @@ -98,6 +94,6 @@ def generate_hash(file_content: str):
for lang in languages_hashes:
shutil.move(f"public/i18n/{lang}.json", f"public/i18n/{lang}-{languages_hashes[lang]}.json")

console.log("Moved files.")
print("Moved files.")

console.log("Done!")
print("Done!")

0 comments on commit dfaa2c1

Please sign in to comment.