From 26ce86d10eff0315630c465985e2e27915d76171 Mon Sep 17 00:00:00 2001 From: casjay Date: Wed, 12 Oct 2022 18:31:11 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=97=83=EF=B8=8F=20Committing=20everything?= =?UTF-8?q?=20that=20changed=20=F0=9F=97=83=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 55 ++++++++++++++++++++++++++++-------------- bin/entrypoint-deno.sh | 8 +++--- bin/get-deno.sh | 35 ++++++++++++++++++--------- 3 files changed, 65 insertions(+), 33 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3a65e8f..07319a0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,34 @@ #FROM casjaysdevdocker/debian:latest as build FROM casjaysdevdocker/alpine:latest AS build -ENV DENO_VERSION="v1.26.1" \ - DEBIAN_FRONTEND=noninteractive +ARG alpine_version="v3.16" \ + TIMEZONE="America/New_York" \ + IMAGE_NAME="alpine" \ + LICENSE="MIT" \ + PORTS="1-65535" -RUN apt update && \ - apt upgrade -yy && \ - apt install unzip -yy && \ - apt clean && \ - rm -rf /var/lib/apt/lists/* +ENV TZ="$TIMEZONE" \ + SHELL="/bin/bash" \ + ENV="$HOME/.bashrc" \ + TERM="xterm-256color" \ + HOSTNAME="${HOSTNAME:-casjaysdev-$IMAGE_NAME}" \ + DENO_VERSION="v1.26.1" + +RUN set -ex; \ + rm -Rf "/etc/apk/repositories"; \ + echo "http://dl-cdn.alpinelinux.org/alpine/$alpine_version/main" >> "/etc/apk/repositories"; \ + echo "http://dl-cdn.alpinelinux.org/alpine/$alpine_version/community" >> "/etc/apk/repositories"; \ + if [ "$alpine_version" = "edge" ]; then echo "http://dl-cdn.alpinelinux.org/alpine/$alpine_version/testing" >> "/etc/apk/repositories" ; fi ; \ + apk update --update-cache && apk add \ + unzip COPY ./bin/. /usr/local/bin/ -COPY ./config/. /config/ -COPY ./data/. /data/ +COPY ./data/. /usr/local/share/template-files/data/ +COPY ./config/. /usr/local/share/template-files/config/ RUN chmod -Rf 755 /usr/local/bin/get-deno.sh && \ DEBUG="true" /usr/local/bin/get-deno.sh && \ - rm -Rf /usr/local/bin/get-deno.sh + rm -Rf /usr/local/bin/get-deno.sh /bin/.gitkeep /config /data /var/cache/apk/* FROM scratch @@ -36,16 +48,23 @@ LABEL org.label-schema.name="deno" \ maintainer="CasjaysDev " ENV SHELL="/bin/bash" \ + ENV="$HOME/.bashrc" \ TERM="xterm-256color" \ - HOSTNAME="casjaysdev-deno" \ - TZ="${TZ:-America/New_York}" - -WORKDIR /data -VOLUME ["/data"] -EXPOSE 1-65535 + HOSTNAME="casjaysdev-alpine" \ + TZ="${TZ:-America/New_York}" \ + TIMEZONE="$TIMEZONE" \ + PHP_SERVER="none" \ + PORT="" COPY --from=build /. / -HEALTHCHECK --interval=15s --timeout=3s CMD [ "/usr/local/bin/entrypoint-deno.sh", "healthcheck" ] +WORKDIR /data/htdocs/www + +VOLUME [ "/config","/data" ] + +EXPOSE $PORTS + +ENTRYPOINT [ "tini", "-p", "SIGTERM", "--" ] +CMD [ "/usr/local/bin/entrypoint-deno.sh" ] +HEALTHCHECK --start-period=1m --interval=2m --timeout=3s CMD [ "/usr/local/bin/entrypoint-deno.sh", "healthcheck" ] -ENTRYPOINT [ "/usr/local/bin/entrypoint-deno.sh" ] diff --git a/bin/entrypoint-deno.sh b/bin/entrypoint-deno.sh index a9d6a70..03f211a 100755 --- a/bin/entrypoint-deno.sh +++ b/bin/entrypoint-deno.sh @@ -47,9 +47,9 @@ fi # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [[ -f "/config/.env" ]] && source /config/.env -if [ -z "$1" ] && [ -z "$(ls -A "" 2>/dev/null)" ]; then +if [ -z "$1" ] && [ -z "$(ls -A "/data/htdocs/www" 2>/dev/null)" ]; then FRESH_INSTALL="true" - deno run -A -r https://fresh.deno "/data/" + deno run -A -r https://fresh.deno "/data/htdocs/www" fi # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - case "$1" in @@ -67,13 +67,13 @@ sh | bash | shell | /bin/sh | /bin/bash) deno) shift 1 - deno run --allow-net "${@:-/data/sample.ts}" + deno run --allow-net "${@:-/data/htdocs/www/sample.ts}" ;; *) if [ "$FRESH_INSTALL" = "true" ]; then deno --allow-all task start else - deno run --watch --allow-all "${@:-/data/sample.ts}" + deno run --watch --allow-all "${@:-/data/htdocs/www/sample.ts}" fi ;; esac diff --git a/bin/get-deno.sh b/bin/get-deno.sh index d54ca60..6ef0ffb 100755 --- a/bin/get-deno.sh +++ b/bin/get-deno.sh @@ -18,18 +18,19 @@ [ -n "$DEBUG" ] && set -x # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - DENO_VERSION="${DENO_VERSION:-v1.26.1}" -DENO_URL_x64="https://github.com/denoland/deno/releases/download/latest/deno-x86_64-unknown-linux-gnu.zip" -DENO_URL_ARM64="https://github.com/LukeChannings/deno-arm64/releases/latest/download/deno-linux-arm64.zip" +DENO_URL_x64_LATEST="https://github.com/denoland/deno/releases/download/latest/deno-x86_64-unknown-linux-gnu.zip" +DENO_URL_x64_VERSION="https://github.com/denoland/deno/releases/download/$DENO_VERSION/deno-x86_64-unknown-linux-gnu.zip" +DENO_URL_ARM64_LATEST="https://github.com/LukeChannings/deno-arm64/releases/latest/download/deno-linux-arm64.zip" +DENO_URL_ARM64_VERSION="https://github.com/LukeChannings/deno-arm64/releases/download/$DENO_VERSION/deno-linux-arm64.zip" # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - __get_file() { - local version_url="${URL//latest/$DENO_VERSION/}" - if curl -q -LSSf -o "$FILE" "$URL"; then - DOWNLOAD_URL="$URL" + if curl -q -LSsf -o "$FILE" "$URL"||false; then return 0 - elif curl -q -LSsf -o "$FILE" "$version_url"; then - DOWNLOAD_URL="$version_url" + elif curl -q -LSsf -o "$FILE" "$LATEST_URL"||false; then + URL="$LATEST_URL" return 0 else + return 1 fi } @@ -37,8 +38,14 @@ __get_file() { # AMD64 binary if [ "$(uname -m)" = "amd64" ] || [ "$(uname -m)" = "x86_64" ]; then ARCH=x86_64 - URL="$DENO_URL_x64" FILE="/tmp/deno-$ARCH.zip" + LATEST_URL="$DENO_URL_x64_LATEST" + if [ "$DENO_VERSION" = "latest" ] || [ -z "$DENO_VERSION" ]; then + DENO_VERSION="latest" + URL="$DENO_URL_x64_LATEST" + else + URL="$DENO_URL_x64_VERSION" + fi echo "grabbing ${DENO_VERSION}/deno-x86_64-unknown-linux-gnu.zip from denoland for $ARCH" __get_file && if [ -f "/tmp/deno-$ARCH.zip" ]; then mkdir -p "/tmp/deno-$ARCH" && cd "/tmp/deno-$ARCH" || exit 10 @@ -48,15 +55,21 @@ if [ "$(uname -m)" = "amd64" ] || [ "$(uname -m)" = "x86_64" ]; then rm -Rf "/tmp/deno-$ARCH.zip" "/tmp/deno-$ARCH" fi else - echo "Failed to download deno from $DOWNLOAD_URL" + echo "Failed to download deno from $URL" exit 2 fi # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # ARM64 binary if [ "$(uname -m)" = "arm64" ] || [ "$(uname -m)" = "aarch64" ]; then ARCH=arm64 - URL="$DENO_URL_ARM64" FILE="/tmp/deno-$ARCH.zip" + LATEST_URL="$DENO_URL_ARM64_LATEST" + if [ "$DENO_VERSION" = "latest" ] || [ -z "$DENO_VERSION" ]; then + DENO_VERSION="latest" + URL="$DENO_URL_ARM64_LATEST" + else + URL="$DENO_URL_ARM64_VERSION" + fi echo "grabbing ${DENO_VERSION}/deno-linux-arm64.zip from LukeChannings for $ARCH" __get_file && if [ -f "/tmp/deno-$ARCH.zip" ]; then mkdir -p "/tmp/deno-$ARCH" && cd "/tmp/deno-$ARCH" || exit 10 @@ -66,7 +79,7 @@ if [ "$(uname -m)" = "arm64" ] || [ "$(uname -m)" = "aarch64" ]; then rm -Rf "/tmp/deno-$ARCH.zip" "/tmp/deno-$ARCH" fi else - echo "Failed to download deno from $DOWNLOAD_URL" + echo "Failed to download deno from $URL" exit 2 fi [ -f "$(which "deno")" ] && deno upgrade && exit 0 || exit 10