resolves #11, resolves #13, resolves #14, resolves #15, resolves #19, resolves #20, resolves #21, resolves #22; major changes to NPM
This commit is contained in:
parent
14d04aeaf2
commit
031320890f
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
test*
|
@ -1,41 +1,54 @@
|
|||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
set -e
|
set -euo pipefail
|
||||||
|
|
||||||
|
trap trapexit EXIT
|
||||||
|
|
||||||
|
GREPDIR=$(cd ${0%/*} && pwd -P)
|
||||||
|
TEMPDIR=$(mktemp -d)
|
||||||
|
TEMPLOG="$TEMPDIR/tmplog"
|
||||||
|
TEMPERR="$TEMPDIR/tmperr"
|
||||||
|
LASTCMD=""
|
||||||
|
WGETOPT="-t 1 -T 15 -q"
|
||||||
|
DEVDEPS="jq npm g++ make gcc git python3-dev musl-dev libffi-dev openssl-dev"
|
||||||
|
|
||||||
|
cd $TEMPDIR
|
||||||
|
touch $TEMPLOG
|
||||||
|
|
||||||
# Helpers
|
# Helpers
|
||||||
function info { echo -e "\e[32m[info] $*\e[39m"; }
|
log() { logs=$(cat $TEMPLOG | sed -e "s/34/32/g" | sed -e "s/info/success/g"); printf "\033c$logs\n\e[34m[info] $*\e[0m\n" | tee $TEMPLOG; }
|
||||||
|
runcmd() {
|
||||||
_temp_dir=$(mktemp -d)
|
LASTCMD=$(grep -n "$*" "$GREPDIR/$0" | sed "s/[[:blank:]]*runcmd//");
|
||||||
cd $_temp_dir
|
if [[ "$#" -eq 1 ]]; then
|
||||||
|
eval "$@" 2>$TEMPERR;
|
||||||
. /etc/os-release
|
else
|
||||||
_alpine_version=${VERSION_ID%.*}
|
$@ 2>$TEMPERR;
|
||||||
_npm_url="https://github.com/jc21/nginx-proxy-manager"
|
fi
|
||||||
|
}
|
||||||
# add openresty repo
|
trapexit() {
|
||||||
if [ ! -f /etc/apk/keys/admin@openresty.com-5ea678a6.rsa.pub ]; then
|
status=$?
|
||||||
wget -q -P /etc/apk/keys/ 'http://openresty.org/package/admin@openresty.com-5ea678a6.rsa.pub' &>/dev/null
|
if [[ $status -eq 0 ]]; then
|
||||||
echo "http://openresty.org/package/alpine/v$_alpine_version/main" >> /etc/apk/repositories
|
logs=$(cat $TEMPLOG | sed -e "s/34/32/g" | sed -e "s/info/success/g")
|
||||||
fi
|
printf "\033c$logs\n";
|
||||||
|
elif [[ -s $TEMPERR ]]; then
|
||||||
# Update container OS
|
logs=$(cat $TEMPLOG | sed -e "s/34/31/g" | sed -e "s/info/error/g")
|
||||||
info "Updating container OS..."
|
err=$(cat $TEMPERR | sed $'s,\x1b\\[[0-9;]*[a-zA-Z],,g' | rev | cut -d':' -f1 | rev | cut -d' ' -f2-)
|
||||||
apk update >/dev/null
|
printf "\033c$logs\e[33m\n$0: line $LASTCMD\n\e[33;2;3m$err\e[0m\n"
|
||||||
apk upgrade &>/dev/null
|
else
|
||||||
|
printf "\e[33muncaught error occurred\n\e[0m"
|
||||||
echo "fs.file-max = 65535" > /etc/sysctl.conf
|
fi
|
||||||
|
# Cleanup
|
||||||
# Install prerequisites
|
rm -rf $TEMPDIR
|
||||||
info "Installing prerequisites..."
|
apk del $DEVDEPS &>/dev/null
|
||||||
apk add python3 git certbot jq openresty nodejs npm yarn openssl apache2-utils &>/dev/null
|
}
|
||||||
python3 -m ensurepip &>/dev/null
|
|
||||||
|
|
||||||
|
# Check for previous install
|
||||||
if [ -f /etc/init.d/npm ]; then
|
if [ -f /etc/init.d/npm ]; then
|
||||||
info "Stoping services..."
|
log "Stoping services"
|
||||||
rc-service npm stop &>/dev/null
|
rc-service npm stop &>/dev/null
|
||||||
rc-service openresty stop &>/dev/null
|
rc-service openresty stop &>/dev/null
|
||||||
sleep 2
|
sleep 2
|
||||||
|
|
||||||
info "Cleaning old files..."
|
log "Cleaning old files"
|
||||||
# Cleanup for new install
|
# Cleanup for new install
|
||||||
rm -rf /app \
|
rm -rf /app \
|
||||||
/var/www/html \
|
/var/www/html \
|
||||||
@ -43,21 +56,59 @@ if [ -f /etc/init.d/npm ]; then
|
|||||||
/var/log/nginx \
|
/var/log/nginx \
|
||||||
/var/lib/nginx \
|
/var/lib/nginx \
|
||||||
/var/cache/nginx &>/dev/null
|
/var/cache/nginx &>/dev/null
|
||||||
|
|
||||||
|
log "Removing old dependancies"
|
||||||
|
apk del certbot $DEVDEPS &>/dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get latest version information for nginx-proxy-manager
|
log "Checking for latest openresty repository"
|
||||||
#_latest_release=$(wget "$_npm_url/releases/latest" -q -O - | grep -wo "jc21/.*.tar.gz")
|
. /etc/os-release
|
||||||
#_latest_version=$(basename $_latest_release .tar.gz)
|
_alpine_version=${VERSION_ID%.*}
|
||||||
#_latest_version=${_latest_version#v*}
|
_npm_url="https://github.com/jc21/nginx-proxy-manager"
|
||||||
|
# add openresty public key
|
||||||
|
if [ ! -f /etc/apk/keys/admin@openresty.com-5ea678a6.rsa.pub ]; then
|
||||||
|
runcmd 'wget $WGETOPT -P /etc/apk/keys/ http://openresty.org/package/admin@openresty.com-5ea678a6.rsa.pub'
|
||||||
|
fi
|
||||||
|
|
||||||
# 2.8.1 is the last version that used alpine linux
|
# Get the latest openresty repository
|
||||||
_latest_version=2.8.1
|
_repository_version=$(wget $WGETOPT "http://openresty.org/package/alpine/" -O - | grep -Eo "[0-9]{1}\.[0-9]{1,2}" | sort -uVr | head -n1)
|
||||||
|
_repository_version=$(printf "$_repository_version\n$_alpine_version" | sort -V | head -n1)
|
||||||
|
_repository="http://openresty.org/package/alpine/v$_repository_version/main"
|
||||||
|
|
||||||
|
# Update/Insert openresty repository
|
||||||
|
grep -q 'openresty.org' /etc/apk/repositories &&
|
||||||
|
sed -i "/openresty.org/c\\$_repository/" /etc/apk/repositories || echo $_repository >> /etc/apk/repositories
|
||||||
|
|
||||||
|
# Update container OS
|
||||||
|
log "Updating container OS"
|
||||||
|
runcmd apk update
|
||||||
|
runcmd apk upgrade
|
||||||
|
echo "fs.file-max = 65535" > /etc/sysctl.conf
|
||||||
|
|
||||||
|
# Install dependancies
|
||||||
|
log "Installing dependancies"
|
||||||
|
runcmd 'apk add python3 openresty nodejs yarn openssl apache2-utils $DEVDEPS'
|
||||||
|
|
||||||
|
# Setup python env and PIP
|
||||||
|
log "Setting up python"
|
||||||
|
ln -sf /usr/bin/python3 /usr/bin/python
|
||||||
|
python -m venv /opt/certbot/
|
||||||
|
runcmd 'wget $WGETOPT -c https://bootstrap.pypa.io/get-pip.py -O - | python'
|
||||||
|
# Install certbot and python dependancies
|
||||||
|
runcmd pip install --no-cache-dir -U cryptography==3.3.2
|
||||||
|
runcmd pip install --no-cache-dir cffi certbot
|
||||||
|
ln -sf /usr/bin/certbot /opt/certbot/bin/certbot
|
||||||
|
|
||||||
|
log "Checking for latest NPM version"
|
||||||
|
# Get latest version information for nginx-proxy-manager
|
||||||
|
runcmd 'wget $WGETOPT -O ./_latest_release $_npm_url/releases/latest'
|
||||||
|
_latest_version=$(basename $(cat ./_latest_release | grep -wo "jc21/.*.tar.gz") .tar.gz | cut -d'v' -f2)
|
||||||
|
|
||||||
# Download nginx-proxy-manager source
|
# Download nginx-proxy-manager source
|
||||||
info "Downloading NPM v$_latest_version..."
|
log "Downloading NPM v$_latest_version"
|
||||||
wget -qc $_npm_url/archive/v$_latest_version.tar.gz -O - | tar -xz
|
runcmd 'wget $WGETOPT -c $_npm_url/archive/v$_latest_version.tar.gz -O - | tar -xz'
|
||||||
|
|
||||||
cd nginx-proxy-manager-$_latest_version
|
cd ./nginx-proxy-manager-$_latest_version
|
||||||
# Copy runtime files
|
# Copy runtime files
|
||||||
_rootfs=docker/rootfs
|
_rootfs=docker/rootfs
|
||||||
mkdir -p /var/www/html && cp -r $_rootfs/var/www/html/* /var/www/html
|
mkdir -p /var/www/html && cp -r $_rootfs/var/www/html/* /var/www/html
|
||||||
@ -98,16 +149,8 @@ echo resolver "$(awk 'BEGIN{ORS=" "} $1=="nameserver" {print ($2 ~ ":")? "["$2"]
|
|||||||
# Generate dummy self-signed certificate.
|
# Generate dummy self-signed certificate.
|
||||||
if [ ! -f /data/nginx/dummycert.pem ] || [ ! -f /data/nginx/dummykey.pem ]
|
if [ ! -f /data/nginx/dummycert.pem ] || [ ! -f /data/nginx/dummykey.pem ]
|
||||||
then
|
then
|
||||||
info "Generating dummy SSL certificate..."
|
log "Generating dummy SSL certificate"
|
||||||
openssl req \
|
runcmd openssl req -new -newkey rsa:2048 -days 3650 -nodes -x509 -subj '/O=Nginx Proxy Manager/OU=Dummy Certificate/CN=localhost' -keyout /data/nginx/dummykey.pem -out /data/nginx/dummycert.pem
|
||||||
-new \
|
|
||||||
-newkey rsa:2048 \
|
|
||||||
-days 3650 \
|
|
||||||
-nodes \
|
|
||||||
-x509 \
|
|
||||||
-subj '/O=Nginx Proxy Manager/OU=Dummy Certificate/CN=localhost' \
|
|
||||||
-keyout /data/nginx/dummykey.pem \
|
|
||||||
-out /data/nginx/dummycert.pem &>/dev/null
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Copy app files
|
# Copy app files
|
||||||
@ -116,16 +159,15 @@ cp -r backend/* /app
|
|||||||
cp -r global/* /app/global
|
cp -r global/* /app/global
|
||||||
|
|
||||||
# Build the frontend
|
# Build the frontend
|
||||||
info "Building frontend..."
|
log "Building frontend"
|
||||||
mkdir -p /app/frontend/images
|
mkdir -p /app/frontend/images
|
||||||
cd frontend
|
cd ./frontend
|
||||||
yarn install &>/dev/null
|
runcmd yarn install
|
||||||
yarn build &>/dev/null
|
runcmd yarn build
|
||||||
cp -r dist/* /app/frontend
|
cp -r dist/* /app/frontend
|
||||||
cp -r app-images/* /app/frontend/images
|
cp -r app-images/* /app/frontend/images
|
||||||
|
|
||||||
cd /app
|
log "Initalizing backend"
|
||||||
info "Initalizing backend..."
|
|
||||||
rm -rf /app/config/default.json &>/dev/null
|
rm -rf /app/config/default.json &>/dev/null
|
||||||
if [ ! -f /app/config/production.json ]; then
|
if [ ! -f /app/config/production.json ]; then
|
||||||
cat << 'EOF' > /app/config/production.json
|
cat << 'EOF' > /app/config/production.json
|
||||||
@ -142,13 +184,13 @@ cat << 'EOF' > /app/config/production.json
|
|||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
fi
|
fi
|
||||||
yarn install &>/dev/null
|
runcmd cd /app && yarn install
|
||||||
|
|
||||||
# Create required folders
|
# Create required folders
|
||||||
mkdir -p /data
|
mkdir -p /data
|
||||||
|
|
||||||
# Update openresty config
|
# Update openresty config
|
||||||
info "Configuring openresty..."
|
log "Configuring openresty"
|
||||||
cat << 'EOF' > /etc/conf.d/openresty
|
cat << 'EOF' > /etc/conf.d/openresty
|
||||||
# Configuration for /etc/init.d/openresty
|
# Configuration for /etc/init.d/openresty
|
||||||
|
|
||||||
@ -161,10 +203,10 @@ rc-service openresty stop &>/dev/null
|
|||||||
if [ -f /usr/sbin/nginx ]; then
|
if [ -f /usr/sbin/nginx ]; then
|
||||||
rm /usr/sbin/nginx
|
rm /usr/sbin/nginx
|
||||||
fi
|
fi
|
||||||
ln -s /usr/local/openresty/nginx/sbin/nginx /usr/sbin/nginx
|
ln -sf /usr/local/openresty/nginx/sbin/nginx /usr/sbin/nginx
|
||||||
|
|
||||||
# Create NPM service
|
# Create NPM service
|
||||||
info "Creating NPM service..."
|
log "Creating NPM service"
|
||||||
cat << 'EOF' > /etc/init.d/npm
|
cat << 'EOF' > /etc/init.d/npm
|
||||||
#!/sbin/openrc-run
|
#!/sbin/openrc-run
|
||||||
description="Nginx Proxy Manager"
|
description="Nginx Proxy Manager"
|
||||||
@ -203,11 +245,6 @@ chmod a+x /etc/init.d/npm
|
|||||||
rc-update add npm boot &>/dev/null
|
rc-update add npm boot &>/dev/null
|
||||||
|
|
||||||
# Start services
|
# Start services
|
||||||
info "Starting services..."
|
log "Starting services"
|
||||||
rc-service openresty start &>/dev/null
|
runcmd rc-service openresty start
|
||||||
rc-service npm start &>/dev/null
|
runcmd rc-service npm start
|
||||||
|
|
||||||
# Cleanup
|
|
||||||
info "Cleaning up..."
|
|
||||||
rm -rf $_temp_dir/nginx-proxy-manager-${_latest_version} &>/dev/null
|
|
||||||
apk del git jq npm &>/dev/null
|
|
Loading…
Reference in New Issue
Block a user