Compare commits
	
		
			4 Commits
		
	
	
		
			dbb54b6f81
			...
			4dd0661e1e
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 4dd0661e1e | |||
| d6e1186d86 | |||
| 57ade9f67d | |||
| ddeadcf723 | 
| @@ -11,17 +11,20 @@ RUN apt-get update && apt-get install -y git hugo nginx cron curl bash sudo htop | ||||
| RUN groupadd -r hugo && useradd -r -g hugo hugo | ||||
|  | ||||
| # Hugo Directory Tree | ||||
| RUN mkdir -pv /var/www/hugo && chown -Rv hugo:hugo /var/www/hugo | ||||
| RUN mkdir -pv /var/www/hugo/ | ||||
|  | ||||
| # NGINX Directory Tree | ||||
| RUN mkdir -pv /var/www/html/ && chown -Rv hugo:hugo /var/www/html/ | ||||
| RUN mkdir -pv /var/www/html/ | ||||
|  | ||||
| # Copy Cron Job to Update Git Repo | ||||
| COPY files/hugo.crontab /etc/cron.d/hugo | ||||
| COPY files/hugo.cronjob.sh /var/www/hugo/cronjob.sh | ||||
| RUN chmod +x /var/www/hugo/cronjob.sh | ||||
| RUN crontab /etc/cron.d/hugo | ||||
|  | ||||
| # Hugo User Permissions | ||||
| RUN chown -Rv hugo:hugo /var/www/ | ||||
| RUN chmod +x /var/www/hugo/cronjob.sh | ||||
|  | ||||
| # Copy Start Script | ||||
| COPY files/main.sh /root/main.sh | ||||
| RUN chmod +x /root/main.sh | ||||
|   | ||||
| @@ -2,9 +2,25 @@ | ||||
|  | ||||
| cd /var/www/hugo/site | ||||
|  | ||||
| git pull | ||||
| echo "*** Running cronjob @ `date` ***" | ||||
|  | ||||
| # Pull any updates, and if the project is already up to date, exit successfully. | ||||
| git pull | grep -v "up to date" | ||||
| status="$?" | ||||
| echo "* Pull status is '$status'." | ||||
| if [[ $status != 0 && -e /var/www/html/index.html ]]; then | ||||
| 	echo "* Site is already up to date and copied, exiting." | ||||
| 	exit 0 | ||||
| fi | ||||
|  | ||||
| # If the project was not already up to date, build the new files for NGINX. | ||||
| hugo --gc --minify | ||||
| status="$?" | ||||
| echo "* Hugo status is '$status'." | ||||
| if [[ $status == 0 && -e public/index.html ]]; then | ||||
| 	echo "* Copying files..." | ||||
| 	rm -rfv /var/www/html/* | ||||
| 	mv -v public/* /var/www/html/ | ||||
| fi | ||||
|  | ||||
| rm -rfv /var/www/html/* | ||||
| cp -rfv public/* /var/www/html/ | ||||
| exit 0 | ||||
|   | ||||
| @@ -21,21 +21,27 @@ if [[ $status != 0 || ! -d /var/www/hugo/site/.git ]]; then | ||||
| 	echo "Aborting." | ||||
| 	exit 1 | ||||
| fi | ||||
| echo "* Site exists!" | ||||
|  | ||||
| echo "*** Copying Static Files to NGINX ***" | ||||
| rm -rfv /var/www/html/* | ||||
| sudo -u hugo /var/www/hugo/cronjob.sh | ||||
|  | ||||
| echo "*** Starting Cron ***" | ||||
| service cron start | ||||
| service cron status | ||||
|  | ||||
| if [[ "$PROD" == "Y"* || "$PROD" == "T"*  ]]; then | ||||
| 	echo "*** Starting Production Server Loop ***" | ||||
|  | ||||
| 	while true; do | ||||
| 		curl -sS http://localhost:80 > /dev/null || { | ||||
| 		http_code="`curl -sS http://localhost:80 -o /dev/null -w "%{http_code}"`" | ||||
| 		if [[ $http_code != 200 ]]; then | ||||
| 			echo "* Prod server not detected, starting..." | ||||
| 			service nginx status | ||||
| 			service nginx start | ||||
| 		} | ||||
| 			service nginx status | ||||
| 		fi | ||||
| 		sleep 15 | ||||
| 	done & | ||||
|  | ||||
| @@ -47,19 +53,20 @@ if [[ "$DEV" == "Y"* || "$DEV" == "T"* ]]; then | ||||
| 	echo "*** Starting Development Server Loop ***" | ||||
|  | ||||
| 	while true; do | ||||
| 		curl -sS http://localhost:1380 > /dev/null || { | ||||
| 		http_code="`curl -sS http://localhost:1380 -o /dev/null -w "%{http_code}"`" | ||||
| 		if [[ $http_code != 200 ]]; then | ||||
| 			echo "* Dev server not detected, starting..." | ||||
| 			cd /var/www/hugo/site | ||||
| 			killall hugo 2>/dev/null | ||||
| 			sudo -u hugo hugo server -D --noBuildLock --bind 0.0.0.0 -p 1380 & | ||||
| 		} | ||||
| 		fi | ||||
| 		sleep 30 | ||||
| 	done & | ||||
| fi | ||||
|  | ||||
| cd | ||||
|  | ||||
| echo "*** Finished $0 ***" | ||||
| echo "*** Finished $0 @ `date` ***" | ||||
|  | ||||
| wait -n | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user