-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-docker-image.sh
More file actions
117 lines (93 loc) · 3.6 KB
/
Copy pathbuild-docker-image.sh
File metadata and controls
117 lines (93 loc) · 3.6 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/bash
# This basic script runs a docker build, then builds the public folder with hugo.
# WARNING, this will wipe the contents for the NGINX_BLOG_DIR folder.
# DO NOT keep anything needed in that folder, it is automatically generated.
#------
# Variables
#------
# Set this to true to run the docker compose image for the nginx server and start the project.
runDockerImage=true
# Set this to true to build this image, which builds the public directory for hugo
BUILD_DOCKER_IMAGE=true
# Set this to true to reset the cache when building.
# Should be useful for when I don't change much.
BUILD_NO_CACHE=false
# If this should restart the nginx container.
# Seems to break my blog on the VPS if i don't do this
RESTART_NGINX_CONTAINER=true
# If this is true, it should set the variables to my local environment
# If false, it will run off the variables for my VPS.
LOCAL_SITE=true
if [ $LOCAL_SITE = true ]; then
baseURL=https://blog.local.kelsoncraft.net
# KCNet Hugo blog folder
BLOG_DIR="$HOME/Documents/docker_misc/kcnet-blog"
# KCNet Blog Nginx folder, and nginx data folder
NGINX_BLOG_DIR="$HOME/Documents/docker_misc/kcnet-blog-nginx"
NGINX_BLOG_DATA_DIR="$HOME/Documents/docker_misc/kcnet-blog-nginx/data"
NGINX_BLOG_DATA_DIR_TEST="$NGINX_BLOG_DIR/data"
echo "$NGINX_BLOG_DATA_DIR_TEST"
else
baseURL=https://blog.kelsoncraft.net
# KCNet Hugo blog folder
BLOG_DIR="$HOME/docker/kcnet-blog"
# KCNet Blog Nginx folder, and nginx data folder
NGINX_BLOG_DIR="$HOME/docker/kcnet-blog-nginx"
NGINX_BLOG_DATA_DIR="$HOME/docker/kcnet-blog-nginx/data"
fi
#------
# Functions
#------
# Make this run the docker compose image if enabled
if [ $BUILD_DOCKER_IMAGE = true ]; then
if [ $BUILD_NO_CACHE = true ]; then
docker build --no-cache -t kcnet-blog .
else
docker build -t kcnet-blog .
fi
# This now makes the build output smaller.
docker run --rm -v "$(pwd):/src" kcnet-blog hugo --destination public --baseURL "$baseURL" --minify
fi
read -p "WARNING this will wipe the contents of the $NGINX_BLOG_DIR folder, would you like to continue? " -n 1 -r
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
echo "Not wiping the $NGINX_BLOG_DIR folder, exiting."
exit 0
fi
# Delete old nginx data directory, copy new files to the nginx data directory
if [ $runDockerImage = true ]; then
# Remove the old data files.
cd "$NGINX_BLOG_DIR/" || exit
if [ -d "$NGINX_BLOG_DATA_DIR" ]; then
echo "Deleting and re-creating nginx blog data dir."
rm -r "$NGINX_BLOG_DATA_DIR"
mkdir "$NGINX_BLOG_DATA_DIR"
else
mkdir "$NGINX_BLOG_DATA_DIR"
fi
# Attempt to copy files from Nginx container into NGINX_BLOG_DIR
if [ -d "$NGINX_BLOG_DATA_DIR" ]; then
cp "$BLOG_DIR"/data/nginx/kcnet-blog-nginx/* "$NGINX_BLOG_DIR/" -r
echo "Copied Nginx data files for blog into $NGINX_BLOG_DIR"
fi
# Copy new files into the public folder
if [ ! -d "$BLOG_DIR/public" ]; then
echo "The public directory does not exist."
exit 1
fi
echo "Copying files from public folder to nginx blog data dir."
# shellcheck disable=SC2086
cp $BLOG_DIR/public/* "$NGINX_BLOG_DATA_DIR/" -r
# Check if index.html exists
if [ -f "$NGINX_BLOG_DATA_DIR/index.html" ]; then
echo "Copied files, index.html was in the nginx data dir."
else
echo "File copy failed! Check the script, index.html does not exist in the data dir."
fi
fi
# Restart nginx container.
if [ $RESTART_NGINX_CONTAINER = true ]; then
cd "$NGINX_BLOG_DIR" || exit 1
docker compose down
docker compose up -d
fi