diff options
| -rw-r--r-- | .gitlab-ci-local/.gitignore | 2 | ||||
| -rw-r--r-- | .gitlab-ci.yml | 34 | ||||
| -rw-r--r-- | .gitlab-ci.yml.bkp | 54 | ||||
| -rw-r--r-- | Dockerfile | 32 | ||||
| -rw-r--r-- | build.py | 13 | ||||
| -rw-r--r-- | publish.el | 11 |
6 files changed, 138 insertions, 8 deletions
diff --git a/.gitlab-ci-local/.gitignore b/.gitlab-ci-local/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/.gitlab-ci-local/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..d6326b4 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,34 @@ +image: registry.gitlab.com/ccleberg/cleberg-net:latest + +stages: + - build + - deploy + +build-job: + stage: build + script: + - echo "Environment is ready. Running build..." + - ENV=prod uv run build.py <<< "r" + artifacts: + paths: + - .build/ + +deploy-job: + stage: deploy + environment: production + before_script: + - 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )' + - eval $(ssh-agent -s) + - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - + - mkdir -p ~/.ssh + - chmod 700 ~/.ssh + - ssh-keyscan $SERVER_IP >> ~/.ssh/known_hosts + - chmod 644 ~/.ssh/known_hosts + - | + echo "Host homelab-remote + HostName $SERVER_IP + User $SERVER_USER + Port 2169" > ~/.ssh/config + script: + - echo "Deploying via Python script..." + - ENV=prod uv run build.py <<< "r" diff --git a/.gitlab-ci.yml.bkp b/.gitlab-ci.yml.bkp new file mode 100644 index 0000000..d427c5b --- /dev/null +++ b/.gitlab-ci.yml.bkp @@ -0,0 +1,54 @@ +image: python:latest + +stages: + - build + - deploy + +variables: + TERM: xterm + HOMEBREW_NO_AUTO_UPDATE: "1" + +build-job: + stage: build + before_script: + # 1. Restore Homebrew if it was cached + - if [ -d ".linuxbrew/bin" ]; then + echo "Restoring Homebrew from cache..."; + mv .linuxbrew /home/linuxbrew; + fi + + # 2. Install Homebrew only if missing + - if [ ! -f "/home/linuxbrew/.linuxbrew/bin/brew" ]; then + apt-get update -qy && apt-get install -y curl git procps; + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"; + fi + + - eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv bash)" + + # 3. Only install tools if they aren't already there + - command -v emacs >/dev/null 2>&1 || brew install emacs rsync uv minify + + # 4. Handle Emacs Repos (using a local project folder for easier caching) + - mkdir -p .emacs_repos + - "[ -d .emacs_repos/htmlize ] || git clone https://github.com/emacsorphanage/htmlize.git .emacs_repos/htmlize" + - "[ -d .emacs_repos/templatel ] || git clone https://github.com/emacs-love/templatel.git .emacs_repos/templatel" + - "[ -d .emacs_repos/weblorg ] || git clone https://github.com/emacs-love/weblorg.git .emacs_repos/weblorg" + script: + - echo "Compiling the site with Emacs and Weblorg..." + - yes r | ENV="prod" uv run build.py + - echo "Compile complete." + after_script: + - cp -r /home/linuxbrew/.linuxbrew .linuxbrew + artifacts: + paths: + - public/ + +deploy-job: + stage: deploy + environment: production + before_script: + - apt-get update -qy && apt-get install -y rsync + script: + - echo "Deploying application via rsync..." + # Example: rsync -azP public/ user@server:/var/www/html + - echo "Application successfully deployed." diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8e0b16e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +FROM python:3.12-slim + +ENV DEBIAN_FRONTEND=noninteractive \ + HOMEBREW_NO_AUTO_UPDATE=1 \ + PATH="/home/linuxbrew/.linuxbrew/bin:${PATH}" + +RUN apt-get update && apt-get install -y --no-install-recommends \ + curl \ + git \ + procps \ + build-essential \ + ca-certificates \ + && rm -rf /var/lib/apt/lists/* + +RUN useradd -m -s /bin/bash linuxbrew && \ + echo "linuxbrew:linuxbrew" | chpasswd && \ + adduser linuxbrew sudo + +USER linuxbrew +WORKDIR /home/linuxbrew + +RUN /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + +RUN brew install emacs rsync uv minify + +RUN mkdir -p ~/.config/emacs/.local/straight/repos && \ + git clone https://github.com/emacsorphanage/htmlize.git ~/.config/emacs/.local/straight/repos/htmlize && \ + git clone https://github.com/emacs-love/templatel.git ~/.config/emacs/.local/straight/repos/templatel && \ + git clone https://github.com/emacs-love/weblorg.git ~/.config/emacs/.local/straight/repos/weblorg + +USER root +WORKDIR /builds @@ -253,19 +253,22 @@ def run_emacs_publish(dev_mode=True): print("Running Emacs publish script (production)...") result = subprocess.run( ["emacs", "--script", "publish.el"], - stdout=subprocess.DEVNULL, - stderr=subprocess.DEVNULL, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, text=True, ) - # Fix to remove annoying cleberg-net.html file - os.remove(".build/cleberg-net.html") - if result.returncode != 0: print("Error running publish.el:") print(result.stderr, file=sys.stderr) sys.exit(1) + annoying_file = Path(".build/cleberg-net.html") + if annoying_file.exists(): + os.remove(annoying_file) + else: + print("Warning: .build/cleberg-net.html not found, but Emacs exited successfully.") + def generate_sitemap(build_dir=".build", base_url="https://cleberg.net"): """ @@ -1,8 +1,13 @@ ;;; -*- lexical-binding: t -*- ;; Explicitly load packages for Doom Emacs -(add-to-list 'load-path "~/.config/emacs/.local/straight/repos/htmlize") -(add-to-list 'load-path "~/.config/emacs/.local/straight/repos/weblorg") -(add-to-list 'load-path "~/.config/emacs/.local/straight/repos/templatel") +(defvar site-lisp-base + (if (eq system-type 'darwin) + "~/.config/emacs/.local/straight/repos" ; macOS path + "/home/linuxbrew/.config/emacs/.local/straight/repos")) ; CI/Linux path + +(add-to-list 'load-path (expand-file-name "htmlize" site-lisp-base)) +(add-to-list 'load-path (expand-file-name "weblorg" site-lisp-base)) +(add-to-list 'load-path (expand-file-name "templatel" site-lisp-base)) (require 'htmlize) (require 'weblorg) |
