initial commit
This commit is contained in:
commit
e0ad92c9be
4
.env.example
Normal file
4
.env.example
Normal file
@ -0,0 +1,4 @@
|
||||
BLOG_NAME=
|
||||
LIVERELOAD_PORT=
|
||||
HOST_URL=
|
||||
WWW_PORT=
|
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
.env
|
||||
jekyll/**
|
16
Dockerfile
Normal file
16
Dockerfile
Normal file
@ -0,0 +1,16 @@
|
||||
FROM ruby:3.2.2
|
||||
|
||||
ARG BLOG_NAME
|
||||
RUN useradd -ms /bin/bash --uid 1000 jekyll
|
||||
RUN mkdir -p -m 0755 /app/jekyll
|
||||
RUN mkdir -p -m 0755 /opt/jekyll
|
||||
VOLUME $PWD/data:/opt/jekyll
|
||||
RUN chmod +x /opt/jekyll/ && \
|
||||
chown -R 1000:1000 /opt/jekyll && \
|
||||
chown -R 1000:1000 /app
|
||||
|
||||
USER 1000
|
||||
|
||||
WORKDIR /app/jekyll
|
||||
|
||||
ENTRYPOINT ["/opt/jekyll/entrypoint.sh"]
|
77
data/entrypoint.sh
Executable file
77
data/entrypoint.sh
Executable file
@ -0,0 +1,77 @@
|
||||
#!/bin/bash
|
||||
source /opt/jekyll/.env
|
||||
export AUTHOR_EMAIL=$AUTHOR_EMAIL
|
||||
export BLOG_NAME=$BLOG_NAME
|
||||
export BASE_URL=$BASE_URL
|
||||
export URL=$URL
|
||||
export GITHUB_USERNAME=$GITHUB_USERNAME
|
||||
export LIVERELOAD_PORT=$LIVERELOAD_PORT
|
||||
export HOST_URL=$HOST_URL
|
||||
export SITE_TITLE=$SITE_TITLE
|
||||
export THEME=$THEME
|
||||
export TWITTER_USERNAME=$TWITTER_USERNAME
|
||||
export WWW_PORT=$WWW_PORT
|
||||
export GEM_HOME="/usr/local/bundle"
|
||||
export PATH="$GEM_HOME/bin:$GEM_HOME/gems/bin:$PATH"
|
||||
export SITE_PATH="/app/jekyll/$BLOG_NAME"
|
||||
|
||||
update_config() {
|
||||
for ENV_VAR in 'AUTHOR_EMAIL' 'BASE_URL' 'GITHUB_USERNAME' \
|
||||
'SITE_TITLE' 'THEME' 'TWITTER_USERNAME' 'URL'; do
|
||||
case $ENV_VAR in
|
||||
"AUTHOR_EMAIL") param="email" ;;
|
||||
"BASE_URL") param="baseurl" ;;
|
||||
"GITHUB_USERNAME") param="github_username" ;;
|
||||
"SITE_TITLE") param="title" ;;
|
||||
"THEME") param="theme" ;;
|
||||
"TWITTER_USERNAME") param="twitter_username" ;;
|
||||
"URL") param="url" ;;
|
||||
esac
|
||||
initial_config=$(grep -E "^${param}: " ${SITE_PATH}/_config.yml)
|
||||
[[ "$initial_config" != "$param: ${!ENV_VAR}" && ! -z ${!ENV_VAR} ]] && {
|
||||
echo "Config change detected on $param: updating _config.yml"
|
||||
echo "New $param: ${!ENV_VAR}"
|
||||
[[ $ENV_VAR == "BASE_URL" || $ENV_VAR == "URL" ]] && {
|
||||
sed -i "s/\(${param}: \).*/\1\"${!ENV_VAR}\"/g" ${SITE_PATH}/_config.yml
|
||||
} || {
|
||||
sed -i "s/\(${param}: \).*/\1${!ENV_VAR}/g" ${SITE_PATH}/_config.yml
|
||||
}
|
||||
} || {
|
||||
echo "No change or empty variable for $param, continuing..."
|
||||
}
|
||||
done
|
||||
}
|
||||
|
||||
update_description() {
|
||||
initial_description=$(sed -n '/^description/,/^baseurl/p' ${SITE_PATH}/_config.yml | sed '/^description/d' |
|
||||
sed '/^baseurl: ""/d' | sed 's/^[[:space:]]*//' | sed '/^description:/,/^baseurl:/ { /^description:/n; /^baseurl:/! { /^$/d; } }')
|
||||
current_description=$(sed 's/^[[:space:]]*//' /opt/jekyll/${BLOG_NAME}_description.txt)
|
||||
[[ "$initial_description" != "$current_description" && ! -z $current_description ]] && {
|
||||
echo "Config change detected on site description: updating _config.yml"
|
||||
sed -i "/^description/,/^baseurl:/!b;//!d;/^description/r /opt/jekyll/${BLOG_NAME}_description.txt" ${SITE_PATH}/_config.yml
|
||||
sed -i '/^description:/,/^baseurl:/ { /^description:/n; /^baseurl:/! s/^[^[:space:]]/ &/; }' ${SITE_PATH}/_config.yml
|
||||
} || {
|
||||
echo "No change or empty variable for site $BLOG_NAME description, continuing..."
|
||||
sed -i '/^description:/,/^baseurl:/ { /^description:/n; /^baseurl:/! s/^[^[:space:]]/ &/; }' ${SITE_PATH}/_config.yml
|
||||
sed '/^description:/,/^baseurl:/ { /^description:/n; /^baseurl:/! { /^$/d; } }'
|
||||
}
|
||||
}
|
||||
|
||||
cd /app/jekyll &&
|
||||
gem install jekyll jekyll-docs jekyll-compose bundler webrick
|
||||
|
||||
[[ -f ${SITE_PATH}/_config.yml ]] &&
|
||||
{
|
||||
cd $SITE_PATH
|
||||
bundle install
|
||||
update_config
|
||||
update_description
|
||||
bundle exec jekyll serve --host $HOST_URL
|
||||
} || {
|
||||
jekyll new $SITE_PATH
|
||||
cd $SITE_PATH
|
||||
bundle install
|
||||
update_config
|
||||
update_description
|
||||
bundle exec jekyll serve --host $HOST_URL
|
||||
}
|
15
docker-compose.yml
Normal file
15
docker-compose.yml
Normal file
@ -0,0 +1,15 @@
|
||||
version: "3"
|
||||
services:
|
||||
jekyll:
|
||||
container_name: jekyll
|
||||
build:
|
||||
context: ${PWD}
|
||||
args:
|
||||
BLOG_NAME: ${BLOG_NAME}
|
||||
env_file: ${PWD}/data/.env
|
||||
ports:
|
||||
- ${LIVERELOAD_PORT}:10000
|
||||
- ${WWW_PORT}:4000
|
||||
volumes:
|
||||
- ${PWD}/jekyll:/app/jekyll
|
||||
- ${PWD}/data:/opt/jekyll
|
Loading…
Reference in New Issue
Block a user