uncomplicated things
This commit is contained in:
parent
2c9bf01213
commit
9edb36665c
5 changed files with 64 additions and 56 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,2 +1,2 @@
|
||||||
config/
|
quartz/
|
||||||
.env
|
.env
|
||||||
|
|
31
Dockerfile
31
Dockerfile
|
@ -1,36 +1,15 @@
|
||||||
FROM node:alpine AS build
|
|
||||||
|
|
||||||
RUN apk --no-cache add git && \
|
|
||||||
git clone https://code.modernleft.org/gravityfargo/quartz.git && \
|
|
||||||
cd quartz && git switch json-config && cd .. && \
|
|
||||||
mkdir -p /usr/share/nginx/html && \
|
|
||||||
mv quartz/* /usr/share/nginx/html && \
|
|
||||||
cd /usr/share/nginx/html && \
|
|
||||||
npm ci && npx quartz build && \
|
|
||||||
rm -rf /usr/share/nginx/html/node_modules /usr/share/nginx/html/docs
|
|
||||||
|
|
||||||
FROM nginx:stable-alpine3.20
|
FROM nginx:stable-alpine3.20
|
||||||
COPY --from=build /usr/share/nginx/html /usr/share/nginx/html
|
|
||||||
COPY default.conf.template /etc/nginx/templates/default.conf.template
|
COPY default.conf.template /etc/nginx/templates/default.conf.template
|
||||||
COPY config.json /usr/share/nginx/html/default-config.json
|
|
||||||
|
|
||||||
WORKDIR /usr/share/nginx/html
|
RUN apk --no-cache add nodejs npm bash dumb-init git busybox-suid && \
|
||||||
|
rm -rf /var/cache/apk/*
|
||||||
|
|
||||||
RUN apk --no-cache add nodejs npm bash dumb-init git && \
|
WORKDIR /quartz
|
||||||
rm -rf /var/cache/apk/* && \
|
ENV CONTENT_REPO=""
|
||||||
echo "*/5 * * * * cd /usr/share/nginx/html/content && git pull >/dev/null 2>&1 && cd /usr/share/nginx/html && npx quartz build >/dev/null 2>&1" > /etc/crontabs/root
|
|
||||||
|
|
||||||
RUN mkdir /config && \
|
|
||||||
ln -s /usr/share/nginx/html/content / && \
|
|
||||||
chown -R nginx:nginx /usr/share/nginx/html && \
|
|
||||||
chown -R nginx:nginx /config
|
|
||||||
|
|
||||||
# REQUIRED
|
|
||||||
ENV NGINX_PORT=80
|
ENV NGINX_PORT=80
|
||||||
ENV SERVER_NAME="quartz.zhao.xyz"
|
ENV SERVER_NAME="quartz.zhao.xyz"
|
||||||
ENV ENABLE_CRON="false"
|
ENV ENABLE_CRON="false"
|
||||||
ENV BUILD_SCHEDULE="*/5 * * * *"
|
ENV BUILD_SCHEDULE="*/5 * * * *"
|
||||||
ENV QUARTZ_CONFIG_PATH="/config/config.json"
|
|
||||||
|
|
||||||
COPY entrypoint.sh /entrypoint.sh
|
COPY entrypoint.sh /entrypoint.sh
|
||||||
RUN chmod +x /entrypoint.sh
|
RUN chmod +x /entrypoint.sh
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
server {
|
server {
|
||||||
listen ${NGINX_PORT};
|
listen ${NGINX_PORT};
|
||||||
server_name ${SERVER_NAME};
|
server_name ${SERVER_NAME};
|
||||||
root /usr/share/nginx/html/public;
|
root /quartz/src/public;
|
||||||
index index.html;
|
index index.html;
|
||||||
error_page 404 /404.html;
|
error_page 404 /404.html;
|
||||||
|
|
||||||
|
|
|
@ -10,12 +10,7 @@ services:
|
||||||
NGINX_PORT: 8080
|
NGINX_PORT: 8080
|
||||||
SERVER_NAME: "localhost"
|
SERVER_NAME: "localhost"
|
||||||
ENABLE_CRON: "true"
|
ENABLE_CRON: "true"
|
||||||
BUILD_SCHEDULE: "*/10 * * * *"
|
BUILD_SCHEDULE: "*/1 * * * *"
|
||||||
|
CONTENT_REPO: "https://code.modernleft.org/gravityfargo/modernleft-docs.git"
|
||||||
volumes:
|
volumes:
|
||||||
- /home/nathan/Repositories/modernleft-docs:/content
|
- ./quartz:/quartz
|
||||||
- ./config:/config
|
|
||||||
- quartz-deps:/usr/share/nginx/html/node_modules
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
quartz-deps:
|
|
||||||
driver: local
|
|
||||||
|
|
|
@ -1,45 +1,79 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
verify_config_exist() {
|
setup_user() {
|
||||||
if [[ ! -f "/config/config.json" ]]; then
|
if ! getent group quartzgroup >/dev/null 2>&1; then
|
||||||
echo "Config file not found, copying default config..."
|
addgroup -g "$GROUP_ID" quartzgroup
|
||||||
cp /usr/share/nginx/html/config.json /config/config.json
|
fi
|
||||||
|
|
||||||
|
if ! id -u quartz >/dev/null 2>&1; then
|
||||||
|
adduser -D -u "$USER_ID" -G quartzgroup quartz
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
setup_cron() {
|
setup_cron() {
|
||||||
echo "${BUILD_SCHEDULE} cd /usr/share/nginx/html/content && git pull >/dev/null 2>&1 && cd /usr/share/nginx/html && npx quartz build >/dev/null 2>&1" >/etc/crontabs/root
|
# NEW_JOB="${BUILD_SCHEDULE} (cd /quartz/content && git pull) >/dev/null && echo && (cd /quartz/src && npx quartz build) >/dev/null 2>&1"
|
||||||
|
NEW_JOB="${BUILD_SCHEDULE} (cd /quartz/content && git restore . && git pull) >/dev/null && (cd /quartz/src && npx quartz build) >/dev/null && echo 'Content Updated.'"
|
||||||
if [[ "$ENABLE_CRON" == "true" ]]; then
|
if [[ "$ENABLE_CRON" == "true" ]]; then
|
||||||
echo "Cron is enabled"
|
echo "Cron is enabled..."
|
||||||
crond -b
|
echo "Setting up cron job..."
|
||||||
|
echo "$NEW_JOB" >/etc/crontabs/root
|
||||||
|
/usr/sbin/crond -f &
|
||||||
|
|
||||||
else
|
else
|
||||||
echo "Cron is disabled"
|
echo "Cron is disabled"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
verify_quartz() {
|
||||||
|
if [ ! -d "/quartz/src" ]; then
|
||||||
|
echo "Cloning Quartz..."
|
||||||
|
git clone https://github.com/jackyzha0/quartz.git /quartz/src
|
||||||
|
cd /quartz/src
|
||||||
|
rm -rf /quartz/src/content
|
||||||
|
ln -s /quartz/content /quartz/src
|
||||||
|
git config --global --add safe.directory /quartz/src
|
||||||
|
|
||||||
|
echo "Installing Quartz dependencies..."
|
||||||
|
npm install >/dev/null
|
||||||
|
|
||||||
|
echo "Building Quartz..."
|
||||||
|
npx quartz build >/dev/null
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
download_content() {
|
||||||
|
mkdir -p /quartz/content # Ensure directory exists
|
||||||
|
|
||||||
|
if [ -n "${CONTENT_REPO}" ] && [ -z "$(ls -A /quartz/content 2>/dev/null)" ]; then
|
||||||
|
echo "Downloading content..."
|
||||||
|
git clone "${CONTENT_REPO}" /quartz/content
|
||||||
|
fi
|
||||||
|
git config --global --add safe.directory /quartz/content
|
||||||
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
verify_config_exist
|
echo "Setting up Quartz environment..."
|
||||||
|
setup_user
|
||||||
setup_cron
|
setup_cron
|
||||||
|
verify_quartz
|
||||||
|
download_content
|
||||||
|
|
||||||
chown -R nginx:nginx /usr/share/nginx/html
|
rm -rf /quartz/src/content
|
||||||
chown -R "${USER_ID}":"${GROUP_ID}" /content
|
ln -s /quartz/content /quartz/src
|
||||||
chown -R "${USER_ID}":"${GROUP_ID}" /config
|
|
||||||
|
echo "Setting correct permissions..."
|
||||||
|
chown -R "${USER_ID}":"${GROUP_ID}" /quartz
|
||||||
|
chmod -R 755 /quartz
|
||||||
|
|
||||||
# NGINX script to sub variables in the template
|
|
||||||
echo "NGINX variable substitution..."
|
echo "NGINX variable substitution..."
|
||||||
/docker-entrypoint.d/20-envsubst-on-templates.sh
|
/docker-entrypoint.d/20-envsubst-on-templates.sh >/dev/null
|
||||||
|
|
||||||
echo "Starting Quartz..."
|
|
||||||
echo "Installing dependencies..."
|
|
||||||
npm i >/dev/null
|
|
||||||
|
|
||||||
echo "Building Quartz..."
|
echo "Building Quartz..."
|
||||||
npx quartz build >/dev/null
|
su quartz -c "bash -c 'cd /quartz/src && npx quartz build >/dev/null'"
|
||||||
|
|
||||||
echo "Starting Nginx..."
|
echo "Starting Nginx..."
|
||||||
exec nginx -g "daemon off;"
|
exec nginx -g "daemon off; error_log warn;"
|
||||||
}
|
}
|
||||||
|
|
||||||
main
|
main
|
||||||
|
|
Loading…
Reference in a new issue