This repository has been archived by the owner on Jun 19, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker-entrypoint.sh
86 lines (65 loc) · 1.98 KB
/
docker-entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/sh
set -eo pipefail
error()
{
echo -e "\033[0;31m[ ERROR ] $1\033[0m" 1>&2
exit 1
}
info()
{
echo -e "\033[1;32m$1\033[0m" 1>&2
}
if [ "$GITHUB_WORKSPACE" ]; then
SOURCE=$GITHUB_WORKSPACE
else
SOURCE=/src
fi
if [ ! -d "$SOURCE/docs" ]; then
error "Missing docs dir '$SOURCE/docs'"
fi
if [ ! -d "$SOURCE/.git" ]; then
error "Missing .git dir '$SOURCE/.git'"
fi
info "Detected source location '$SOURCE'"
info "Mounting source paths to workspace..."
ln -sf $SOURCE/.git /workspace/.git
ln -sf $SOURCE/docs /workspace/docs
cd /workspace
info "Copying project configuration..."
cp $SOURCE/docs/config.yaml /workspace/config/production/config.yaml
cp $SOURCE/docs/params.yaml /workspace/config/production/params.yaml
cp $SOURCE/docs/params.yaml /workspace/config/staging/params.yaml
if [ "$1" == 'server' ]; then
info "Hugo configuration..."
hugo config --environment production
info "Starting production server..."
hugo server --environment production --bind 0.0.0.0 --baseURL http://localhost:1313/
exit 0
fi
if [ "$1" == 'preview' ]; then
info "Hugo configuration..."
hugo config --environment staging
info "Starting staging preview server, including drafts and future content"
hugo server --environment staging --bind 0.0.0.0 --baseURL http://localhost:1313/ --buildDrafts --buildFuture
exit 0
fi
if [ "$1" == 'build' ]; then
if [ -d "$SOURCE/build" ]; then
info "Cleaning up build path..."
rm -rf $SOURCE/build/*
else
info "Creating build path..."
mkdir $SOURCE/build
fi
info "Mounting build path..."
ln -sf $SOURCE/build /workspace/build
info "Hugo configuration..."
hugo config --environment production
info "Building documents..."
hugo --environment production --minify
info "Setting ownership for build output..."
chown -R `stat -c "%u:%g" $SOURCE` $SOURCE/build
exit 0
fi
error "Invalid command arguments. Use one of 'server', 'preview' or 'build'."
exit 1