diff options
-rw-r--r-- | docker/arch-code-server/Dockerfile | 25 | ||||
-rwxr-xr-x | docker/arch-code-server/archlinux-setup-user.bash | 35 | ||||
-rwxr-xr-x | docker/arch-code-server/archlinux-setup.bash | 61 | ||||
-rwxr-xr-x | docker/arch-code-server/china-magic-for-pkgbuild.py | 21 | ||||
-rwxr-xr-x | docker/arch-code-server/restore-pacman-conf.py | 47 | ||||
-rw-r--r-- | docker/crupest-nginx/Dockerfile | 2 | ||||
-rw-r--r-- | template/docker-compose.yaml.template | 6 | ||||
-rwxr-xr-x | tool/aio.py | 3 | ||||
-rw-r--r-- | tool/modules/config.py | 10 | ||||
-rw-r--r-- | tool/modules/setup.py | 24 |
10 files changed, 8 insertions, 226 deletions
diff --git a/docker/arch-code-server/Dockerfile b/docker/arch-code-server/Dockerfile index 6471fac..fe810cd 100644 --- a/docker/arch-code-server/Dockerfile +++ b/docker/arch-code-server/Dockerfile @@ -1,25 +1,8 @@ -FROM archlinux:latest +FROM alpine:latest -ARG CRUPEST_USER -ARG CRUPEST_GROUP -ARG CRUPEST_UID=1000 -ARG CRUPEST_GID=1000 -ARG CRUPEST_PACKAGES="" -ARG CRUPEST_AUR_PACKAGES="" -ARG USE_CHINA_MIRROR="false" -ARG CHINA_MIRROR_URL="https://mirrors.ustc.edu.cn/archlinux/\$repo/os/\$arch" - -ADD ./archlinux-setup.bash ./archlinux-setup-user.bash ./china-magic-for-pkgbuild.py ./restore-pacman-conf.py /tmp/ - -ENV CRUPEST_IN_DOCKER="true" -WORKDIR /tmp -RUN /tmp/archlinux-setup.bash -USER ${CRUPEST_UID}:${CRUPEST_GID} -WORKDIR /home/${CRUPEST_USER} -RUN /tmp/archlinux-setup-user.bash - -VOLUME [ "/data" ] +RUN apk add --no-cache alpine-sdk bash libstdc++ libc6-compat && npm config set python python3 && npm install --global code-server --unsafe-perm +WORKDIR /root EXPOSE 8080 - +VOLUME [ "/data" ] ENV CODE_SERVER_CONFIG="/data/code-server-config.yaml" ENTRYPOINT [ "code-server", "--bind-addr", "0.0.0.0:8080" ] diff --git a/docker/arch-code-server/archlinux-setup-user.bash b/docker/arch-code-server/archlinux-setup-user.bash deleted file mode 100755 index 6b30b28..0000000 --- a/docker/arch-code-server/archlinux-setup-user.bash +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env bash - -# check if we are in docker by CRUPEST_IN_DOCKER -if [ "${CRUPEST_IN_DOCKER}" != "true" ]; then - echo "This script is intended to be run in a docker container." - exit 1 -fi - -# don't allow any error -set -e - -cd ~ - -mkdir aur -cd aur - -# install all aur packages -for aur_package in code-server ${CRUPEST_AUR_PACKAGES} ; do - echo "Installing ${aur_package} from AUR..." - git clone "https://aur.archlinux.org/${aur_package}.git" --depth 1 - pushd "${aur_package}" - - # do some magic thing for China - if [ "${USE_CHINA_MIRROR}" = "true" ]; then - mv PKGBUILD PKGBUILD.old - /tmp/china-magic-for-pkgbuild.py < PKGBUILD.old > PKGBUILD - fi - - makepkg -sr --noconfirm - makepkg --packagelist | sudo pacman -U --noconfirm - - popd -done - -# finnally, test code-server -code-server --version diff --git a/docker/arch-code-server/archlinux-setup.bash b/docker/arch-code-server/archlinux-setup.bash deleted file mode 100755 index c926384..0000000 --- a/docker/arch-code-server/archlinux-setup.bash +++ /dev/null @@ -1,61 +0,0 @@ -#!/usr/bin/env bash - -# check if we are in docker by CRUPEST_IN_DOCKER -if [ "${CRUPEST_IN_DOCKER}" != "true" ]; then - echo "This script is intended to be run in a docker container." - exit 1 -fi - -# check if we are root -if [ "$(id -u)" != "0" ]; then - echo "This script must be run as root." - exit 1 -fi - -# CRUPEST_USER, CRUPEST_UID, CRUPEST_GID must be defined -if [ -z "$CRUPEST_USER" ] || [ -z "$CRUPEST_UID" ] || [ -z "$CRUPEST_GID" ]; then - echo "CRUPEST_USER, CRUPEST_UID, CRUPEST_GID must be defined." - exit 1 -fi - -# if we are in China (by checking USE_CHINA_MIRROR), use the mirror in China -if [ "$USE_CHINA_MIRROR" = "true" ]; then - echo "You have set USE_CHINA_MIRROR to true, using mirror ${CHINA_MIRROR_URL} (set by CHINA_MIRROR_URL) in China." - echo "Server = ${CHINA_MIRROR_URL}" > /etc/pacman.d/mirrorlist -fi - -# from now on, we don't allow error -set -e - -# Update the system and I need python3 -pacman -Syu --noconfirm python - -# execute the restore pacman config script -python3 ./restore-pacman-conf.py - -# reinstall all installed packages -pacman -Qnq | pacman -S --noconfirm --overwrite=* - - -# install new packages -echo "base-devel git ${CRUPEST_PACKAGES}" | tr " " "\n" | pacman -S --noconfirm --needed - - -# if GROUP not defined, set it the same to USER -if [ -z "$CRUPEST_GROUP" ]; then - CRUPEST_GROUP="$CRUPEST_USER" -fi - -# check if GROUP exists. if not create it with GID -if ! grep -q "^${CRUPEST_GROUP}:" /etc/group; then - groupadd -g "$CRUPEST_GID" "$CRUPEST_GROUP" -fi - -# create user for UID and GID -useradd -m -u "${CRUPEST_UID}" -g "${CRUPEST_GID}" "${CRUPEST_USER}" - -# add the user to sudo -echo "${CRUPEST_USER} ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers - -# create data directory and change the permission -mkdir -p /data -chown "${CRUPEST_USER}":"${CRUPEST_GROUP}" /data -chmod 700 /data diff --git a/docker/arch-code-server/china-magic-for-pkgbuild.py b/docker/arch-code-server/china-magic-for-pkgbuild.py deleted file mode 100755 index 43a4d89..0000000 --- a/docker/arch-code-server/china-magic-for-pkgbuild.py +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env python3 - -# In China? Good for you! - -import sys -import re - -# read STDIN until EOF -content = sys.stdin.read() - -url = re.search(r"url=(.+)", content).group(1) -if url.startswith('"') and url.endswith('"'): - url = url[1:-1] - -if url.startswith("https://github.com"): # yah, it's github! - content = re.sub(r"\$\{\s*url\s*\}|\$url", url, content) - content = content.replace("https://raw.githubusercontent.com", "https://gh.api.99988866.xyz/https://raw.githubusercontent.com") - content = re.sub(r'https://github\.com/(.+)/(.+)/releases/download', lambda match: f'https://gh.api.99988866.xyz/{match.group(0)}', content) - -# now print the result -print(content) diff --git a/docker/arch-code-server/restore-pacman-conf.py b/docker/arch-code-server/restore-pacman-conf.py deleted file mode 100755 index 3486dd3..0000000 --- a/docker/arch-code-server/restore-pacman-conf.py +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env python3 - -# Fxxk damn shit bash script and linux tools. They just don't work well with text processing, which took me a long time to discover the stupid fact. - -import os -import os.path -import sys -import urllib.request -from http.client import HTTPResponse - -PACMAN_NO_EXTRACT_URL = 'https://gitlab.archlinux.org/archlinux/archlinux-docker/-/raw/master/pacman-conf.d-noextract.conf' - -# check if this is in docker by CRUPEST_IN_DOCKER env -if not os.environ.get('CRUPEST_IN_DOCKER'): - print("Not in docker, exiting!", file=sys.stderr) - exit(1) - -# check if I'm root -if os.geteuid() != 0: - print("Not root, exiting!", file=sys.stderr) - exit(1) - -# check if pacman.conf exists -if not os.path.exists('/etc/pacman.conf'): - print("/etc/pacman.conf does not exist, are you running this in Arch Linux? Exiting!", file=sys.stderr) - exit(2) - -# Download pacman-no-extract file from url -res: HTTPResponse = urllib.request.urlopen(PACMAN_NO_EXTRACT_URL) -if res.status != 200: - print( - f"Failed to download pacman-no-extract file from url: {PACMAN_NO_EXTRACT_URL}, exiting!", file=sys.stderr) - exit(3) - -# Read the content of pacman-no-extract file -pacman_no_extract_content = res.read().decode('utf-8') - -# Read the content of pacman.conf -with open('/etc/pacman.conf', 'r') as f: - pacman_conf_content = f.read() - # remove pacman_no_extract_content from pacman_conf_content - pacman_conf_content = pacman_conf_content.replace( - pacman_no_extract_content, '') - -# Write the content of pacman.conf -with open('/etc/pacman.conf', 'w') as f: - f.write(pacman_conf_content) diff --git a/docker/crupest-nginx/Dockerfile b/docker/crupest-nginx/Dockerfile index cf08ee5..046031b 100644 --- a/docker/crupest-nginx/Dockerfile +++ b/docker/crupest-nginx/Dockerfile @@ -12,6 +12,6 @@ RUN git clone https://github.com/crupest/blog.git && cd blog && git submodule up WORKDIR /blog RUN hugo -FROM nginx:latest +FROM nginx:mainline-alpine COPY --from=build-www /sites/www/dist /srv/www COPY --from=build-blog /blog/public /srv/blog diff --git a/template/docker-compose.yaml.template b/template/docker-compose.yaml.template index 9c0c1a1..a9d5a2b 100644 --- a/template/docker-compose.yaml.template +++ b/template/docker-compose.yaml.template @@ -18,12 +18,6 @@ services: context: ./docker/arch-code-server dockerfile: Dockerfile pull: true - args: - - CRUPEST_USER=$CRUPEST_USER - - CRUPEST_GROUP=$CRUPEST_GROUP - - CRUPEST_UID=$CRUPEST_UID - - CRUPEST_GID=$CRUPEST_GID - - USE_CHINA_MIRROR=$CRUPEST_IN_CHINA tags: - "crupest/arch-code-server:latest" container_name: code-server diff --git a/tool/aio.py b/tool/aio.py index 467b7ca..3d44310 100755 --- a/tool/aio.py +++ b/tool/aio.py @@ -186,6 +186,7 @@ def run(): install_docker() console.print( "Succeeded to install docker. Please re-login to take effect.", style="green") + case "docker": docker_action = args.docker_action @@ -226,6 +227,7 @@ def run(): domains = list_domains(domain) for domain in domains: console.print(domain) + case "nginx": domain = check_domain_is_defined() nginx(domain, console) @@ -265,6 +267,7 @@ def run(): test_crupest_api(console) case _: console.print("Test action invalid.", style="red") + case "dns": domain = check_domain_is_defined() if domain is not None: diff --git a/tool/modules/config.py b/tool/modules/config.py index 937a870..534ce30 100644 --- a/tool/modules/config.py +++ b/tool/modules/config.py @@ -32,16 +32,6 @@ config_var_list: list = [ "Please input your domain name"), ConfigVar("CRUPEST_EMAIL", "admin email address", "Please input your email address"), - ConfigVar("CRUPEST_USER", "your system account username", - lambda: pwd.getpwuid(os.getuid()).pw_name), - ConfigVar("CRUPEST_GROUP", "your system account group name", - lambda: grp.getgrgid(os.getgid()).gr_name), - ConfigVar("CRUPEST_UID", "your system account uid", - lambda: str(os.getuid())), - ConfigVar("CRUPEST_GID", "your system account gid", - lambda: str(os.getgid())), - ConfigVar("CRUPEST_IN_CHINA", - "set to true if you are in China, some network optimization will be applied", lambda: "false"), ConfigVar("CRUPEST_AUTO_BACKUP_COS_SECRET_ID", "access key id for Tencent COS, used for auto backup", "Please input your Tencent COS access key id for backup"), ConfigVar("CRUPEST_AUTO_BACKUP_COS_SECRET_KEY", diff --git a/tool/modules/setup.py b/tool/modules/setup.py index f9c23f8..0e802c4 100644 --- a/tool/modules/setup.py +++ b/tool/modules/setup.py @@ -22,14 +22,6 @@ def get_template_name_list(console) -> list[str]: def data_dir_check(domain, console): - if not exists(data_dir): - console.print( - "Looks like you haven't generated data dir. I'll create it for you.", style="green") - os.mkdir(data_dir) - elif not isdir(data_dir): - console.print( - "ERROR: data dir is not a dir! Everything will be broken! Please delete it manually", style="red") - if isdir(data_dir): if not exists(join(data_dir, "certbot")): print_create_cert_message(domain, console) @@ -39,22 +31,6 @@ def data_dir_check(domain, console): if to_check: check_ssl_cert(domain, console) - if not exists(join(data_dir, "code-server")): - os.mkdir(join(data_dir, "code-server")) - console.print( - "I also create data dir for code-server. Because letting docker create it would result in permission problem.", style="green") - else: - code_server_stat = os.stat( - join(data_dir, "code-server")) - if code_server_stat.st_uid == 0 or code_server_stat.st_gid == 0: - console.print( - "WARNING: The owner of data dir for code-server is root. This may cause permission problem. You had better change it.", style="yellow") - to_fix = Confirm.ask( - "Do you want me to help you fix it?", console=console, default=True) - if to_fix: - subprocess.run( - ["sudo", "chown", "-R", f"{os.getuid()}:{os.getgid()}", join(data_dir, 'code-server')], check=True) - def template_generate(console): template_name_list = get_template_name_list(console) |