mirror of
https://github.com/casjaysdevdocker/deno
synced 2025-01-18 00:34:23 -05:00
🗃️ Committing everything that changed 🗃️
This commit is contained in:
parent
d0050822ad
commit
ce5f843b32
@ -17,8 +17,10 @@ ENV TZ="$TIMEZONE" \
|
||||
|
||||
RUN set -ex; \
|
||||
rm -Rf "/etc/apk/repositories"; \
|
||||
mkdir -p "/usr/local/share/template-files/data/htdocs/www" && \
|
||||
apt-get update && apt-get upgrade -yy && apt-get install -yy \
|
||||
unzip
|
||||
unzip && \
|
||||
git clone -q "https://github.com/casjay-templates/bunjs" "/usr/local/share/template-files/data/htdocs/www"
|
||||
|
||||
COPY ./bin/. /usr/local/bin/
|
||||
COPY ./data/. /usr/local/share/template-files/data/
|
||||
@ -26,7 +28,7 @@ COPY ./config/. /usr/local/share/template-files/config/
|
||||
|
||||
RUN chmod -Rf 755 /usr/local/bin/get-deno.sh && \
|
||||
/usr/local/bin/get-deno.sh && \
|
||||
rm -Rf /usr/local/bin/get-deno.sh /tmp/* /bin/.gitkeep /config /data /var/lib/apt/lists/*
|
||||
rm -Rf /usr/local/bin/get-deno.sh /tmp/* /bin/.gitkeep /config /data /var/lib/apt/lists/* /usr/local/share/template-files/data/htdocs/www/.git
|
||||
|
||||
FROM scratch
|
||||
|
||||
|
@ -1,81 +1,181 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck shell=bash
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
##@Version : 202207101005-git
|
||||
# @Author : Jason Hempstead
|
||||
# @Contact : jason@casjaysdev.com
|
||||
# @License : WTFPL
|
||||
# @ReadME : entrypoint-deno.sh --help
|
||||
# @Copyright : Copyright: (c) 2022 Jason Hempstead, Casjays Developments
|
||||
# @Created : Sunday, Jul 10, 2022 10:05 EDT
|
||||
# @File : entrypoint-deno.sh
|
||||
# @Description :
|
||||
# @TODO :
|
||||
# @Other :
|
||||
# @Resource :
|
||||
# @sudo/root : no
|
||||
##@Version : 202210121546-git
|
||||
# @@Author : Jason Hempstead
|
||||
# @@Contact : jason@casjaysdev.com
|
||||
# @@License : WTFPL
|
||||
# @@ReadME : entrypoint-deno.sh --help
|
||||
# @@Copyright : Copyright: (c) 2022 Jason Hempstead, Casjays Developments
|
||||
# @@Created : Wednesday, Oct 12, 2022 15:46 EDT
|
||||
# @@File : entrypoint-deno.sh
|
||||
# @@Description :
|
||||
# @@Changelog : New script
|
||||
# @@TODO : Better documentation
|
||||
# @@Other :
|
||||
# @@Resource :
|
||||
# @@Terminal App : no
|
||||
# @@sudo/root : no
|
||||
# @@Template : other/docker-entrypoint
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set bash options
|
||||
[ -n "$DEBUG" ] && set -x
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
APPNAME="$(basename "$0" 2>/dev/null)"
|
||||
VERSION="202207101005-git"
|
||||
VERSION="202210121546-git"
|
||||
HOME="${USER_HOME:-$HOME}"
|
||||
USER="${SUDO_USER:-$USER}"
|
||||
RUN_USER="${SUDO_USER:-$USER}"
|
||||
SRC_DIR="${BASH_SOURCE%/*}"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
|
||||
__exec_bash() { [ $# -ne 0 ] && exec "${*:-bash -l}" || exec /bin/bash -l; }
|
||||
__find() { ls -A "$*" 2>/dev/null; }
|
||||
SCRIPT_SRC_DIR="${BASH_SOURCE%/*}"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
DATA_DIR="$(__find /data/ 2>/dev/null | grep '^' || false)"
|
||||
CONFIG_DIR="$(__find /config/ 2>/dev/null | grep '^' || false)"
|
||||
# Set functions
|
||||
__find() { ls -A "$*" 2>/dev/null || return 10; }
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
__exec_command() {
|
||||
local cmd="${*:-/bin/bash -l}"
|
||||
local exitCode=0
|
||||
echo "Executing command: $cmd"
|
||||
eval "$cmd" || exitCode=10
|
||||
[ "$exitCode" = 0 ] || exitCode=10
|
||||
return ${exitCode:-$?}
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Functions
|
||||
__heath_check() {
|
||||
local status=0
|
||||
#curl -q -LSsf -o /dev/null -s -w "200" "http://localhost/server-health" || status=$(($status + 1))
|
||||
echo "$(uname -s) $(uname -m) is running"
|
||||
return ${status:-$?}
|
||||
}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Define default variables - don not change these
|
||||
export TZ="${TZ:-America/New_York}"
|
||||
export LOCAL_BIN_DIR="${LOCAL_BIN_DIR:-/usr/local/bin}"
|
||||
export HOSTNAME="${HOSTNAME:-casjaysdev-bin}"
|
||||
export SSL="${SSL:-false}"
|
||||
export SSL_DIR="${SSL_DIR:-/config/ssl}"
|
||||
export SSL_CA="${SSL_CA:-$SSL_DIR/ca.crt}"
|
||||
export SSL_KEY="${SSL_KEY:-$SSL_DIR/server.key}"
|
||||
export SSL_CERT="${SSL_CERT:-$SSL_DIR/server.crt}"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
if [[ -n "${TZ}" ]]; then
|
||||
echo "${TZ}" >/etc/timezone
|
||||
# Additional variables and variable overrides
|
||||
export HTTP_PORT="${HTTP_PORT:-80}"
|
||||
export HTTPS_PORT="${HTTPS_PORT:-443}"
|
||||
export SERVICE_PORT="${SERVICE_PORT:-}"
|
||||
export DEFAULT_CONF_DIR="${DEFAULT_CONF_DIR:-/usr/local/share/template-files/config/defaults}"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# import variables from file
|
||||
[ -f "/root/env.sh" ] && . "/root/env.sh"
|
||||
[ -f "/config/env.sh" ] && "/config/env.sh"
|
||||
[ -f "/config/.env.sh" ] && . "/config/.env.sh"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set timezone
|
||||
[ -n "${TZ}" ] && echo "${TZ}" >"/etc/timezone"
|
||||
[ -f "/usr/share/zoneinfo/${TZ}" ] && ln -sf "/usr/share/zoneinfo/${TZ}" "/etc/localtime"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Set hostname
|
||||
if [ -n "${HOSTNAME}" ]; then
|
||||
echo "${HOSTNAME}" >"/etc/hostname"
|
||||
echo "127.0.0.1 ${HOSTNAME} localhost ${HOSTNAME}.local" >"/etc/hosts"
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
if [[ -f "/usr/share/zoneinfo/${TZ}" ]]; then
|
||||
ln -sf "/usr/share/zoneinfo/${TZ}" "/etc/localtime"
|
||||
# Delete any gitkeep files
|
||||
[ -d "/data" ] && rm -Rf "/data/.gitkeep" "/data"/*/*.gitkeep
|
||||
[ -d "/config" ] && rm -Rf "/config/.gitkeep" "/data"/*/*.gitkeep
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Setup bin directory
|
||||
if [ -d "/config/bin" ]; then
|
||||
for bin in /config/bin/*; do
|
||||
name="$(basename "$bin")"
|
||||
ln -sf "$bin" "/usr/local/bin/$name"
|
||||
done
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
if [[ -n "${HOSTNAME}" ]]; then
|
||||
echo "${HOSTNAME}" >/etc/hostname
|
||||
echo "127.0.0.1 $HOSTNAME localhost" >/etc/hosts
|
||||
# Create directories
|
||||
[ -d "/etc/ssl" ] || mkdir -p "/etc/ssl"
|
||||
[ -d "/usr/local/bin" ] && rm -Rf "/usr/local/bin/.gitkeep"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
if [ "$SSL" = "true" ] || [ "$SSL" = "yes" ]; then
|
||||
if [ -f "/config/ssl/server.crt" ] && [ -f "/config/ssl/server.key" ]; then
|
||||
export SSL="true"
|
||||
if [ -n "$SSL_CA" ] && [ -f "$SSL_CA" ]; then
|
||||
mkdir -p "/etc/ssl/certs"
|
||||
cat "$SSL_CA" >>"/etc/ssl/certs/ca-certificates.crt"
|
||||
fi
|
||||
else
|
||||
[ -d "$SSL_DIR" ] || mkdir -p "$SSL_DIR"
|
||||
create-ssl-cert
|
||||
fi
|
||||
type update-ca-certificates &>/dev/null && update-ca-certificates
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
[[ -f "/config/.env" ]] && source /config/.env
|
||||
[ -f "$SSL_CA" ] && cp -Rfv "$SSL_CA" "/etc/ssl/ca.crt"
|
||||
[ -f "$SSL_KEY" ] && cp -Rfv "$SSL_KEY" "/etc/ssl/server.key"
|
||||
[ -f "$SSL_CERT" ] && cp -Rfv "$SSL_CERT" "/etc/ssl/server.crt"
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Create default config
|
||||
if [ ! -e "/config/$APPNAME" ] && [ -e "$DEFAULT_CONF_DIR/$APPNAME" ]; then
|
||||
cp -Rf "$DEFAULT_CONF_DIR/$APPNAME" "/config/$APPNAME"
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Setup deno
|
||||
mkdir -p "/data/htdocs/www" && cd "/data/htdocs/www" || exit 10
|
||||
if [ -z "$1" ] && [ -z "$(ls -A "/data/htdocs/www"/* 2>/dev/null)" ]; then
|
||||
cp -Rf "/usr/local/share/template-files/data/htdocs/www/." "/data/htdocs/www/"
|
||||
RUN_SCRIPT="src/index.ts"
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
# Additional commands
|
||||
|
||||
if [ -z "$1" ] && [ -z "$(ls -A "/data/htdocs/www" 2>/dev/null)" ]; then
|
||||
FRESH_INSTALL="true"
|
||||
deno run -A -r https://fresh.deno "/data/htdocs/www"
|
||||
fi
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
case "$1" in
|
||||
--help)
|
||||
--help) # Help message
|
||||
echo 'Docker container for '$APPNAME''
|
||||
echo "Usage: $APPNAME [healthcheck, bash, command]"
|
||||
exit
|
||||
echo "Failed command will have exit code 10"
|
||||
echo ""
|
||||
exit ${exitCode:-$?}
|
||||
;;
|
||||
healthcheck)
|
||||
type -P deno &>/dev/null && echo 'OK' || exit 1
|
||||
|
||||
healthcheck) # Docker healthcheck
|
||||
__heath_check || exitCode=10
|
||||
exit ${exitCode:-$?}
|
||||
;;
|
||||
sh | bash | shell | /bin/sh | /bin/bash)
|
||||
|
||||
*/bin/sh | */bin/bash | bash | shell | sh) # Launch shell
|
||||
shift 1
|
||||
__exec_bash "$@"
|
||||
__exec_command "${@:-/bin/bash}"
|
||||
exit ${exitCode:-$?}
|
||||
;;
|
||||
|
||||
deno)
|
||||
shift 1
|
||||
deno run --allow-net "${@:-/data/htdocs/www/sample.ts}"
|
||||
deno "$@"
|
||||
;;
|
||||
*)
|
||||
if [ "$FRESH_INSTALL" = "true" ]; then
|
||||
deno --allow-all task start
|
||||
|
||||
*) # Execute primary command
|
||||
if [ $# -eq 0 ]; then
|
||||
if [ -n "$RUN_SCRIPT" ]; then
|
||||
START_SCRIPT="$RUN_SCRIPT"
|
||||
elif [ -f "src/index.ts" ]; then
|
||||
RUN_SCRIPT="index.ts"
|
||||
elif [ -f "index.ts" ]; then
|
||||
RUN_SCRIPT="index.ts"
|
||||
elif [ -f "app.ts" ]; then
|
||||
RUN_SCRIPT="app.ts"
|
||||
elif [ -f "server.ts" ]; then
|
||||
RUN_SCRIPT="server.ts"
|
||||
fi
|
||||
deno --allow-all task start ||
|
||||
deno run --watch --allow-all "${@:-}"
|
||||
exit ${exitCode:-$?}
|
||||
else
|
||||
deno run --watch --allow-all "${@:-/data/htdocs/www/sample.ts}"
|
||||
__exec_command "$@"
|
||||
exitCode=$?
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
#end
|
||||
# end of entrypoint
|
||||
exit ${exitCode:-$?}
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -1,10 +0,0 @@
|
||||
import { serve } from 'https://deno.land/std@0.77.0/http/server.ts';
|
||||
|
||||
const PORT = 1993;
|
||||
const s = serve(`0.0.0.0:${PORT}`);
|
||||
const body = new TextEncoder().encode('Hello World\n');
|
||||
|
||||
console.log(`Server started on port ${PORT}`);
|
||||
for await (const req of s) {
|
||||
req.respond({ body });
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user