aboutsummaryrefslogtreecommitdiff
path: root/template
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-10-30 22:44:26 +0800
committercrupest <crupest@outlook.com>2022-10-30 22:44:26 +0800
commit31367d9feb0dc8ea759a41eb9b0179b3aee65f67 (patch)
tree54352395daf743185d88c6e9540b690e95f7e5d0 /template
parentef1340f8a5143f9a266197426234ac1c1607974f (diff)
downloadcrupest-31367d9feb0dc8ea759a41eb9b0179b3aee65f67.tar.gz
crupest-31367d9feb0dc8ea759a41eb9b0179b3aee65f67.tar.bz2
crupest-31367d9feb0dc8ea759a41eb9b0179b3aee65f67.zip
...
Diffstat (limited to 'template')
-rw-r--r--template/docker-compose.yaml.template13
-rwxr-xr-xtemplate/generate.py23
2 files changed, 23 insertions, 13 deletions
diff --git a/template/docker-compose.yaml.template b/template/docker-compose.yaml.template
index 0367605..5cc6d10 100644
--- a/template/docker-compose.yaml.template
+++ b/template/docker-compose.yaml.template
@@ -32,17 +32,20 @@ services:
- internal
code-server:
- image: codercom/code-server:latest
+ build:
+ context: ./docker/code-server
+ dockerfile: Dockerfile
+ args:
+ - CRUPEST_USER={{CRUPEST_USER}}
+ - CRUPEST_GROUP={{CRUPEST_GROUP}}
+ - CRUPEST_UID={{CRUPEST_UID}}
+ - CRUPEST_GID={{CRUPEST_GID}}
container_name: code_server
restart: on-failure:3
volumes:
- ./data/code-server:/data
- - ./data/code-server-config.yaml:/home/coder/.config/code-server/config.yaml
ports:
- "8080:8080"
- environment:
- - "DOCKER_USER=$USER"
- user: "{{CRUPEST_UID}}:{{CRUPEST_GID}}"
networks:
- internal
diff --git a/template/generate.py b/template/generate.py
index d00a84f..1c94cda 100755
--- a/template/generate.py
+++ b/template/generate.py
@@ -3,9 +3,11 @@
import os
import os.path
import re
-from sys import argv
+import pwd
+import grp
+import sys
-required_config_keys = set(["CRUPEST_DOMAIN", "CRUPEST_UID",
+required_config_keys = set(["CRUPEST_DOMAIN", "CRUPEST_USER", "CRUPEST_GROUP", "CRUPEST_UID",
"CRUPEST_GID", "CRUPEST_HALO_DB_PASSWORD"])
print("It's happy to see you!\n")
@@ -28,7 +30,7 @@ for filename in filenames:
print("")
# if command is 'clean'
-if len(argv) > 1 and argv[1] == "clean":
+if len(sys.argv) > 1 and sys.argv[1] == "clean":
print("Are you sure you want to delete all generated files? (y/N)")
if input() == "y":
print("Deleting all generated files...")
@@ -88,12 +90,17 @@ config_path = os.path.join(project_dir, "data/config")
# check if there exists a config file
if not os.path.exists(config_path):
+ config = {}
print("No existing config file found. Don't worry. Let's create one! Just tell me your domain name:")
- domain = input()
- my_uid = os.getuid()
- my_gid = os.getgid()
- halo_db_password = os.urandom(8).hex()
- config_content = f"CRUPEST_DOMAIN={domain}\nCRUPEST_UID={my_uid}\nCRUPEST_GID={my_gid}\nCRUPEST_HALO_DB_PASSWORD={halo_db_password}\n"
+ config["CRUPEST_DOMAIN"] = input()
+ config["CRUPEST_USER"] = pwd.getpwuid(os.getuid()).pw_name
+ config["CRUPEST_GROUP"] = grp.getgrgid(os.getgid()).gr_name
+ config["CRUPEST_UID"] = str(os.getuid())
+ config["CRUPEST_GID"] = str(os.getgid())
+ config["CRUPEST_HALO_DB_PASSWORD"] = os.urandom(8).hex()
+ config_content = ""
+ for key in config:
+ config_content += f"{key}={config[key]}\n"
# create data dir if not exist
if not os.path.exists(os.path.join(project_dir, "data")):
os.mkdir(os.path.join(project_dir, "data"))