updated documentation and scripts.

This commit is contained in:
Violet Ash
2024-11-01 14:50:14 -06:00
parent cdac0e0ec8
commit 0a40a0f472
6 changed files with 136 additions and 116 deletions
+57 -54
View File
@@ -11,7 +11,7 @@ VERBOSE=0
while getopts "d:p:n?s?c?v?h?" opt; do
case "$opt" in
h|\?)
echo "A utility script for quickly getting up and started with self-hosted applicaitons."
echo "A utility script for quickly getting up and started with self-hosted applications."
echo "This script assumes the following:"
echo "- You have already signed in to the cloudflared CLI application;"
echo "- You own a domain through Cloudflare;"
@@ -40,63 +40,66 @@ done
shift $((OPTIND-1))
[ "${1:-}" = "--" ] && shift
# TODO: Install dependencies.
# TODO: Add CLI option to enable cloudflared
# TODO: Connect with cross-platform package manager from quaxlyqueen/scripts
# TODO: Setup ollama (pull LLM best fitting hardware).
createTunnel
# Initialize cloudflared
#cloudflared tunnel login
if [[ "$VERBOSE" -eq 1 ]]; then
echo "Creating cloudflared tunnel..."
fi
output=$(cloudflared tunnel create $TUNNEL_NAME)
TUNNEL_ID=$(echo "$output" | grep -o 'id [^ ]*' | awk -F ' ' '{print $2}')
if [[ "$VERBOSE" -eq 1 ]]; then
echo "Created cloudflared tunnel, ID $TUNNEL_ID"
fi
createTunnel() {
if [[ "$VERBOSE" -eq 1 ]]; then
echo "Creating cloudflared tunnel..."
fi
output=$(cloudflared tunnel create $TUNNEL_NAME)
TUNNEL_ID=$(echo "$output" | grep -o 'id [^ ]*' | awk -F ' ' '{print $2}')
if [[ "$VERBOSE" -eq 1 ]]; then
echo "Created cloudflared tunnel, ID $TUNNEL_ID"
fi
if [[ "$VERBOSE" -eq 1 ]]; then
echo "Creating cloudflared tunnel credentials file..."
fi
echo "tunnel: $TUNNEL_ID" > $CLOUDFLARE_CONFIG
echo "credentials-file: $HOME/.cloudflared/$TUNNEL_ID.json" >> $CLOUDFLARE_CONFIG
echo "ingress:" >> $CLOUDFLARE_CONFIG
if [[ "$VERBOSE" -eq 1 ]]; then
echo "Creating cloudflared tunnel credentials file..."
fi
echo "tunnel: $TUNNEL_ID" > $CLOUDFLARE_CONFIG
echo "credentials-file: $HOME/.cloudflared/$TUNNEL_ID.json" >> $CLOUDFLARE_CONFIG
echo "ingress:" >> $CLOUDFLARE_CONFIG
# Add subdomain and associated ports
len=${#SUBDOMAINS[@]}
for (( i=0; i<${len}; i++ ));
do
echo ${SUBDOMAINS[$i]}
echo ${PORTS[$i]}
done
echo $SUBDOMAINS
for (( i=0; i<${len}; i++ ));
do
echo " - hostname: ${SUBDOMAINS[$i]}.$DOMAIN" >> $CLOUDFLARE_CONFIG
echo " service: http://127.0.0.1:${PORTS[$i]}" >> $CLOUDFLARE_CONFIG
if [[ "$VERBOSE" -eq 1 ]]; then
echo "Associated ${SUBDOMAINS[$i]}.$DOMAIN to port ${PORTS[$i]}"
fi
done
# Add subdomain and associated ports
len=${#SUBDOMAINS[@]}
for (( i=0; i<${len}; i++ ));
do
echo ${SUBDOMAINS[$i]}
echo ${PORTS[$i]}
done
echo $SUBDOMAINS
for (( i=0; i<${len}; i++ ));
do
echo " - hostname: ${SUBDOMAINS[$i]}.$DOMAIN" >> $CLOUDFLARE_CONFIG
echo " service: http://127.0.0.1:${PORTS[$i]}" >> $CLOUDFLARE_CONFIG
if [[ "$VERBOSE" -eq 1 ]]; then
echo "Associated ${SUBDOMAINS[$i]}.$DOMAIN to port ${PORTS[$i]}"
fi
done
echo " - hostname: $DOMAIN" >> $CLOUDFLARE_CONFIG
echo " service: http://127.0.0.1:$PORT" >> $CLOUDFLARE_CONFIG
echo " - service: http_status:404" >> $CLOUDFLARE_CONFIG
echo "Associated $DOMAIN to port $PORT"
if [[ "$VERBOSE" -eq 1 ]]; then
echo "Created cloudflared tunnel credentials file"
cat $CLOUDFLARE_CONFIG
fi
echo " - hostname: $DOMAIN" >> $CLOUDFLARE_CONFIG
echo " service: http://127.0.0.1:$PORT" >> $CLOUDFLARE_CONFIG
echo " - service: http_status:404" >> $CLOUDFLARE_CONFIG
echo "Associated $DOMAIN to port $PORT"
if [[ "$VERBOSE" -eq 1 ]]; then
echo "Created cloudflared tunnel credentials file"
cat $CLOUDFLARE_CONFIG
fi
if [[ "$VERBOSE" -eq 1 ]]; then
echo "Routing domains and sub-domains to the tunnel..."
fi
for (( i=0; i<${len}; i++ ));
do
cloudflared tunnel route dns $TUNNEL_ID ${SUBDOMAINS[$i]}.$DOMAIN
done
cloudflared tunnel route dns $TUNNEL_ID $DOMAIN
cloudflared tunnel run $TUNNEL_NAME
if [[ "$VERBOSE" -eq 1 ]]; then
echo "Routing domains and sub-domains to the tunnel..."
fi
for (( i=0; i<${len}; i++ ));
do
cloudflared tunnel route dns $TUNNEL_ID ${SUBDOMAINS[$i]}.$DOMAIN
done
cloudflared tunnel route dns $TUNNEL_ID $DOMAIN
bg cloudflared tunnel run $TUNNEL_NAME
if [[ "$VERBOSE" -eq 1 ]]; then
echo "Complete!"
fi
if [[ "$VERBOSE" -eq 1 ]]; then
echo "Complete!"
fi
}
+5 -1
View File
@@ -21,7 +21,11 @@ RUN CGO_ENABLED=0 GOOS=linux go build -o /security-layer
# But we can document in the Dockerfile what ports
# the application is going to listen on by default.
# https://docs.docker.com/reference/dockerfile/#expose
EXPOSE 8000
# TODO: Need to dynamically expose ports based upon ~/.config/one-ai/test.json
EXPOSE 1111
EXPOSE 1112
EXPOSE 1113
EXPOSE 1114
# Run
CMD ["/security-layer"]
Binary file not shown.
+2 -2
View File
@@ -5,5 +5,5 @@ sudo docker rm -f security-layer
# Build the Docker image.
sudo docker build --tag security-layer:latest .
# Create a Docker container from the image and connect host port 8000 to container port 8000.
sudo docker run --name security-layer -d -p 8000:8000 security-layer:latest
# Create a Docker container from the image and connect host port 1111 to container port 1111, and 1114 to 1114.
sudo docker run --name security-layer -d -p 1111:1111 -p 1114:1114 security-layer:latest
-9
View File
@@ -1,9 +0,0 @@
SUB=("api=1" "test=2" "portfolio=3")
arraylength=${#SUB[@]}
for (( i=0; i<${arraylength}; i++ ));
do
test="$(echo ${SUB[$i]} | cut -f1 -d=)"
test2="$(echo ${SUB[$i]} | cut -f2 -d=)"
echo $test $test2
done