diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..4ff3bd7 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Always use LF endings. +* text eol=lf \ No newline at end of file diff --git a/.github/workflows/auto-pr.yml b/.github/workflows/auto-pr.yml index 213d5b8..ae26510 100644 --- a/.github/workflows/auto-pr.yml +++ b/.github/workflows/auto-pr.yml @@ -10,7 +10,7 @@ jobs: steps: - name: Checkout Branch ${{ github.ref_name }} - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Create Pull Request uses: bfren/pull-request@v2 diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index ea2be1e..0b59f98 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -12,7 +12,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 build: strategy: fail-fast: false @@ -22,7 +22,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Get repository name run: echo "REPOSITORY_NAME=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')" >> $GITHUB_ENV @@ -35,20 +35,20 @@ jobs: id: version - name: Set up QEMU - uses: docker/setup-qemu-action@v2 + uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v3 - name: Login to DockerHub - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Build and push id: docker_build - uses: docker/build-push-action@v4 + uses: docker/build-push-action@v5 with: context: . file: ./${{ matrix.dotnet }}/Dockerfile @@ -56,10 +56,10 @@ jobs: BF_IMAGE=${{ env.REPOSITORY_NAME }} BF_VERSION=${{ steps.version.outputs.contents }} push: ${{ startsWith(github.ref, 'refs/heads/') }} - platforms: linux/amd64,linux/arm64 + platforms: linux/amd64,linux/arm/v7,linux/arm64 tags: | bfren/aspnet:net${{ matrix.dotnet }}-dev - bfren/aspnet:net${{ matrix.dotnet }}-${{ steps.version.outputs.contents }}-beta + bfren/aspnet:net${{ matrix.dotnet }}-${{ steps.version.outputs.contents }}-dev - name: Image digest run: echo ${{ steps.docker_build.outputs.digest }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index bdead40..271c2d4 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -15,7 +15,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Get repository name run: echo "REPOSITORY_NAME=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')" >> $GITHUB_ENV @@ -46,20 +46,20 @@ jobs: id: version - name: Set up QEMU - uses: docker/setup-qemu-action@v2 + uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v3 - name: Login to DockerHub - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Build and push id: docker_build - uses: docker/build-push-action@v4 + uses: docker/build-push-action@v5 with: context: . file: ./${{ matrix.dotnet }}/Dockerfile @@ -67,7 +67,7 @@ jobs: BF_IMAGE=${{ env.REPOSITORY_NAME }} BF_VERSION=${{ steps.version.outputs.contents }} push: true - platforms: linux/amd64,linux/arm64 + platforms: linux/amd64,linux/arm/v7,linux/arm64 tags: | bfren/aspnet:net${{ matrix.dotnet }} bfren/aspnet:net${{ matrix.dotnet }}-${{ steps.version_major.outputs.contents }} diff --git a/.github/workflows/update-readme.yml b/.github/workflows/update-readme.yml index 14fd935..7fc7506 100644 --- a/.github/workflows/update-readme.yml +++ b/.github/workflows/update-readme.yml @@ -15,10 +15,10 @@ jobs: shell: bash - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Login to DockerHub - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} diff --git a/6/Dockerfile b/6/Dockerfile index 017f17d..1e37163 100644 --- a/6/Dockerfile +++ b/6/Dockerfile @@ -1,29 +1,22 @@ -FROM --platform=$BUILDPLATFORM golang:alpine AS build - -ARG TARGETPLATFORM -ARG BUILDPLATFORM - -RUN echo "Build: $BUILDPLATFORM, target: $TARGETPLATFORM" > /log - -FROM bfren/alpine-s6:alpine3.18-4.5.9 -COPY --from=build /log /log +FROM bfren/alpine-s6:alpine3.18-5.0.0 LABEL org.opencontainers.image.source="https://github.com/bfren/docker-aspnet" -ARG TARGETPLATFORM - ARG BF_IMAGE ARG BF_VERSION EXPOSE 5000 +COPY ./overlay / +COPY ./6/overlay / + ENV \ # The ASP.NET version - used to assist in calculating checksums ASPNET_VERSION=6 \ - # Must be defined so the service can run the application - ASPNET_ASSEMBLY= \ # Configure web servers to bind to port 5000 ASPNETCORE_URLS="http://+:5000" \ + # Must be defined so the service can run the application + BF_ASPNET_ASSEMBLY= \ # Otherwise it is set incorrectly to the S6 service directory DOTNET_CONTENTROOT="/app/live" \ # Enable detection of running in a container @@ -31,9 +24,6 @@ ENV \ # Set the invariant mode to false so CultureInfo can be used DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false -COPY ./overlay / -COPY ./6/overlay / - RUN bf-install VOLUME [ "/app/live", "/app/publish" ] diff --git a/6/overlay/tmp/DOTNET_REVISION b/6/overlay/tmp/DOTNET_REVISION index b7664d3..5ed3dad 100644 --- a/6/overlay/tmp/DOTNET_REVISION +++ b/6/overlay/tmp/DOTNET_REVISION @@ -1 +1 @@ -6.0.23 \ No newline at end of file +6.0.25 \ No newline at end of file diff --git a/7/Dockerfile b/7/Dockerfile index 00a081c..a91ddbc 100644 --- a/7/Dockerfile +++ b/7/Dockerfile @@ -1,29 +1,22 @@ -FROM --platform=$BUILDPLATFORM golang:alpine AS build - -ARG TARGETPLATFORM -ARG BUILDPLATFORM - -RUN echo "Build: $BUILDPLATFORM, target: $TARGETPLATFORM" > /log - -FROM bfren/alpine-s6:alpine3.18-4.5.9 -COPY --from=build /log /log +FROM bfren/alpine-s6:alpine3.18-5.0.0 LABEL org.opencontainers.image.source="https://github.com/bfren/docker-aspnet" -ARG TARGETPLATFORM - ARG BF_IMAGE ARG BF_VERSION EXPOSE 5000 +COPY ./overlay / +COPY ./7/overlay / + ENV \ # The ASP.NET version - used to assist in calculating checksums ASPNET_VERSION=7 \ - # Must be defined so the service can run the application - ASPNET_ASSEMBLY= \ # Configure web servers to bind to port 5000 ASPNETCORE_URLS="http://+:5000" \ + # Must be defined so the service can run the application + BF_ASPNET_ASSEMBLY= \ # Otherwise it is set incorrectly to the S6 service directory DOTNET_CONTENTROOT="/app/live" \ # Enable detection of running in a container @@ -31,9 +24,6 @@ ENV \ # Set the invariant mode to false so CultureInfo can be used DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false -COPY ./overlay / -COPY ./7/overlay / - RUN bf-install VOLUME [ "/app/live", "/app/publish" ] diff --git a/7/overlay/tmp/DOTNET_REVISION b/7/overlay/tmp/DOTNET_REVISION index 3d94166..c787f81 100644 --- a/7/overlay/tmp/DOTNET_REVISION +++ b/7/overlay/tmp/DOTNET_REVISION @@ -1 +1 @@ -7.0.12 \ No newline at end of file +7.0.14 \ No newline at end of file diff --git a/8/Dockerfile b/8/Dockerfile index eda0839..e32e5ec 100644 --- a/8/Dockerfile +++ b/8/Dockerfile @@ -1,29 +1,22 @@ -FROM --platform=$BUILDPLATFORM golang:alpine AS build - -ARG TARGETPLATFORM -ARG BUILDPLATFORM - -RUN echo "Build: $BUILDPLATFORM, target: $TARGETPLATFORM" > /log - -FROM bfren/alpine-s6:alpine3.18-4.5.9 -COPY --from=build /log /log +FROM bfren/alpine-s6:alpine3.18-5.0.0 LABEL org.opencontainers.image.source="https://github.com/bfren/docker-aspnet" -ARG TARGETPLATFORM - ARG BF_IMAGE ARG BF_VERSION EXPOSE 5000 +COPY ./overlay / +COPY ./8/overlay / + ENV \ # The ASP.NET version - used to assist in calculating checksums ASPNET_VERSION=8 \ - # Must be defined so the service can run the application - ASPNET_ASSEMBLY= \ # Configure web servers to bind to port 5000 ASPNETCORE_URLS="http://+:5000" \ + # Must be defined so the service can run the application + BF_ASPNET_ASSEMBLY= \ # Otherwise it is set incorrectly to the S6 service directory DOTNET_CONTENTROOT="/app/live" \ # Enable detection of running in a container @@ -31,9 +24,6 @@ ENV \ # Set the invariant mode to false so CultureInfo can be used DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false -COPY ./overlay / -COPY ./8/overlay / - RUN bf-install VOLUME [ "/app/live", "/app/publish" ] diff --git a/8/overlay/tmp/DOTNET_REVISION b/8/overlay/tmp/DOTNET_REVISION index d1ba9b6..fa5fce0 100644 --- a/8/overlay/tmp/DOTNET_REVISION +++ b/8/overlay/tmp/DOTNET_REVISION @@ -1 +1 @@ -8.0.0-rc.2 \ No newline at end of file +8.0.0 \ No newline at end of file diff --git a/Dockerfile.esh b/Dockerfile.esh index af67bba..0587bc9 100644 --- a/Dockerfile.esh +++ b/Dockerfile.esh @@ -1,29 +1,22 @@ -FROM --platform=$BUILDPLATFORM golang:alpine AS build - -ARG TARGETPLATFORM -ARG BUILDPLATFORM - -RUN echo "Build: $BUILDPLATFORM, target: $TARGETPLATFORM" > /log - -FROM bfren/alpine-s6:alpine<%= ${ALPINE_MINOR} %>-<%= ${BASE_REVISION} %> -COPY --from=build /log /log +FROM bfren/alpine-s6:alpine<%= ${ALPINE_MINOR} %>-<%= ${BASE_VERSION} %> LABEL org.opencontainers.image.source="https://github.com/bfren/docker-aspnet" -ARG TARGETPLATFORM - ARG BF_IMAGE ARG BF_VERSION EXPOSE 5000 +COPY ./overlay / +COPY ./<%= ${ASPNET_VERSION} %>/overlay / + ENV \ # The ASP.NET version - used to assist in calculating checksums ASPNET_VERSION=<%= ${ASPNET_VERSION} %> \ - # Must be defined so the service can run the application - ASPNET_ASSEMBLY= \ # Configure web servers to bind to port 5000 ASPNETCORE_URLS="http://+:5000" \ + # Must be defined so the service can run the application + BF_ASPNET_ASSEMBLY= \ # Otherwise it is set incorrectly to the S6 service directory DOTNET_CONTENTROOT="/app/live" \ # Enable detection of running in a container @@ -31,9 +24,6 @@ ENV \ # Set the invariant mode to false so CultureInfo can be used DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false -COPY ./overlay / -COPY ./<%= ${ASPNET_VERSION} %>/overlay / - RUN bf-install VOLUME [ "/app/live", "/app/publish" ] diff --git a/VERSION b/VERSION index 17ae38e..28cbf7c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.5.32 \ No newline at end of file +5.0.0 \ No newline at end of file diff --git a/VERSION_MAJOR b/VERSION_MAJOR index bf0d87a..7813681 100644 --- a/VERSION_MAJOR +++ b/VERSION_MAJOR @@ -1 +1 @@ -4 \ No newline at end of file +5 \ No newline at end of file diff --git a/VERSION_MINOR b/VERSION_MINOR index 958d30d..6e63660 100644 --- a/VERSION_MINOR +++ b/VERSION_MINOR @@ -1 +1 @@ -4.5 \ No newline at end of file +5.0 \ No newline at end of file diff --git a/generate-dockerfiles.sh b/generate-dockerfiles.sh index 3503d56..a908470 100755 --- a/generate-dockerfiles.sh +++ b/generate-dockerfiles.sh @@ -4,8 +4,8 @@ set -euo pipefail docker pull bfren/alpine -BASE_REVISION="4.5.9" -echo "Base: ${BASE_REVISION}" +BASE_VERSION="5.0.0" +echo "Base: ${BASE_VERSION}" ASPNET_VERSIONS="6 7 8" for V in ${ASPNET_VERSIONS} ; do @@ -18,7 +18,7 @@ for V in ${ASPNET_VERSIONS} ; do -e BF_DEBUG=0 \ bfren/alpine esh \ "/ws/Dockerfile.esh" \ - BASE_REVISION=${BASE_REVISION} \ + BASE_VERSION=${BASE_VERSION} \ ALPINE_MINOR=${ALPINE_MINOR} \ ASPNET_VERSION=${V} ) diff --git a/overlay/etc/bf/ch.d/10-aspnet b/overlay/etc/bf/ch.d/10-aspnet index bf84ff7..4b0b16c 100644 --- a/overlay/etc/bf/ch.d/10-aspnet +++ b/overlay/etc/bf/ch.d/10-aspnet @@ -1,2 +1,2 @@ /app/live www:www 0400 0500 -/app/publish www:www 0660 0770 +/app/publish www:www 0600 0700 diff --git a/overlay/etc/bf/init.d/10-env b/overlay/etc/bf/init.d/10-env deleted file mode 100644 index 6138043..0000000 --- a/overlay/etc/bf/init.d/10-env +++ /dev/null @@ -1,18 +0,0 @@ -#!/command/with-contenv sh - -set -euo pipefail -export BF_E=`basename ${0}` - - -#====================================================================================================================== -# Add environment variables. -#====================================================================================================================== - -# Library configuration -bf-env "ASPNET_LIB" "${BF_LIB}/aspnet" - -# app directories -ASPNET_APP=/app -bf-env "ASPNET_APP" "${ASPNET_APP}" -bf-env "ASPNET_APP_LIVE" "${ASPNET_APP}/live" -bf-env "ASPNET_APP_PUBLISH" "${ASPNET_APP}/publish" diff --git a/overlay/etc/bf/init.d/10-env.nu b/overlay/etc/bf/init.d/10-env.nu new file mode 100644 index 0000000..6b344d7 --- /dev/null +++ b/overlay/etc/bf/init.d/10-env.nu @@ -0,0 +1,10 @@ +use bf +bf env load + +# Set environment variables +def main [] { + let app = "/app" + bf env set ASPNET_APP $app + bf env set ASPNET_APP_LIVE $"($app)/live" + bf env set ASPNET_APP_PUBLISH $"($app)/publish" +} diff --git a/overlay/etc/bf/init.d/11-version b/overlay/etc/bf/init.d/11-version deleted file mode 100644 index e6a6c91..0000000 --- a/overlay/etc/bf/init.d/11-version +++ /dev/null @@ -1,20 +0,0 @@ -#!/command/with-contenv sh - -set -euo pipefail -export BF_E=`basename ${0}` - - -#====================================================================================================================== -# Output .NET Version. -#====================================================================================================================== - -# Get version: -# - get list of installed runtimes -# - get the line with the version on -# - strip out everything except numbers and full stops -# - trim full stops from start of string -# - trim full stops from end of string -VERSION=`dotnet --list-runtimes | grep "NETCore.App" | sed 's/[^0-9\.]*//g' | sed 's/^\.*//g' | sed 's/\.*$//g'` - -# output nicely -bf-echo ".NET ${VERSION} is installed." diff --git a/overlay/etc/bf/init.d/11-version.nu b/overlay/etc/bf/init.d/11-version.nu new file mode 100644 index 0000000..febebf7 --- /dev/null +++ b/overlay/etc/bf/init.d/11-version.nu @@ -0,0 +1,12 @@ +use bf +bf env load + +# Get installed version of ASP.NET runtime +def main [] { + # get the installed version ot ASP.NET + let version = glob $"(bf env ASPNET_RUNTIME)/*" + if ($version | length) != 1 { bf write error "Unable to determine ASP.NET version." } + + # output version + bf write $"ASP.NET v($version | first | path basename) is installed." +} diff --git a/overlay/etc/nu/scripts/bf-aspnet/app.nu b/overlay/etc/nu/scripts/bf-aspnet/app.nu new file mode 100644 index 0000000..f371bd5 --- /dev/null +++ b/overlay/etc/nu/scripts/bf-aspnet/app.nu @@ -0,0 +1,73 @@ +use bf +use bf-s6 + +# Disable the ASP.NET service +export def disable [] { + # disable the ASP.NET service + if (bf-s6 svc is_up aspnet) { + bf write "Disabling ASP.NET service." app/disable + bf-s6 svc down aspnet + } else { + bf write debug "ASP.NET service is down." app/disable + } + + # kill the .NET process (if it's still running) + let dotnet_pids = ps | where name == "dotnet" | get pid + if ($dotnet_pids | length) > 0 { + bf write "Killing .NET processes." app/disable + $dotnet_pids | each {|x| kill --force --quiet $x } + } else { + bf write debug "No .NET processes found." app/disable + } +} + +# Restart application +export def restart [] { + # disable the service + disable + + # restart the applcation + bf write $"Restarting (bf env ASPNET_ASSEMBLY) application." app/restart + ^s6-rc -u change aspnet +} + +# Switch publish and live application directories, and then restart the application +export def switch [ + --terminate (-t) # If set, the container will terminate after switching code +] { + # get directories for easy access + let dir_publish = bf env ASPNET_APP_PUBLISH + let dir_live = bf env ASPNET_APP_LIVE + + # check that there are some published files to switch to + let published_files_count = ls $dir_publish | length + if $published_files_count == 0 { bf write error "Please publish your application first." app/switch } + + bf write "Switching code." app/switch + + # create temporary directory and move live files into it + let dir_temp = bf fs make_temp_dir + let live_files_count = ls $dir_live| length + if $live_files_count > 0 { + bf write debug $" .. moving live files to ($dir_temp)." app/switch + mv $"($dir_live)/*" $dir_temp + } + + # move published files to live + bf write debug $" .. moving published files to ($dir_live)." app/switch + mv $"($dir_publish)/*" $dir_live + + # move old live files into publish + let temp_files_count = ls $dir_temp | length + if $temp_files_count > 0 { bf write debug $" .. moving old live files ($dir_publish)." app/switch } + + # reapply permissions + bf write debug " .. reapplying permissions." app/switch + bf ch apply_file "10-aspnet" + + # output success message + bf write ok "Application switched successfully." app/switch + + # terminate the container + if $terminate { bf-s6 cont terminate } +} diff --git a/overlay/etc/nu/scripts/bf-aspnet/mod.nu b/overlay/etc/nu/scripts/bf-aspnet/mod.nu new file mode 100644 index 0000000..e69de29 diff --git a/overlay/etc/nu/scripts/bf-aspnet/run.nu b/overlay/etc/nu/scripts/bf-aspnet/run.nu new file mode 100644 index 0000000..aba35e1 --- /dev/null +++ b/overlay/etc/nu/scripts/bf-aspnet/run.nu @@ -0,0 +1,28 @@ +use bf + +# Run preflight checks before executing process +export def preflight [...args] { + # load environment + bf env load + + # manually set executing script + bf env x_set --override run aspnet + + # verify ASPNET_ASSEMBLY is set + let assembly = bf env ASPNET_ASSEMBLY + let dir_live = bf env ASPNET_APP_LIVE + + # verify assembly exists + let assembly_path = $"($dir_live)/($assembly)" + if ($assembly_path | bf fs is_not_file) { + bf write notok $"($assembly_path) not found." + let for = 30sec + bf write $"Sleeping for ($for)." + sleep $for + exit 66 + } + + # start application + bf write "Starting ASP.NET application." + bf write debug $" .. ($assembly_path)." +} diff --git a/overlay/etc/periodic/daily/aspnet-restart b/overlay/etc/periodic/daily/aspnet-restart index 3d92c0e..3eb7ae2 100644 --- a/overlay/etc/periodic/daily/aspnet-restart +++ b/overlay/etc/periodic/daily/aspnet-restart @@ -1,11 +1,3 @@ -#!/command/with-contenv sh - -set -euo pipefail -export BF_E=`basename ${0}` - - -#====================================================================================================================== -# Run restart executable. -#====================================================================================================================== +#!/bin/sh aspnet-restart diff --git a/overlay/etc/s6-overlay/s6-rc.d/aspnet/finish b/overlay/etc/s6-overlay/s6-rc.d/aspnet/finish index 483a0d1..8e9f27e 100644 --- a/overlay/etc/s6-overlay/s6-rc.d/aspnet/finish +++ b/overlay/etc/s6-overlay/s6-rc.d/aspnet/finish @@ -1,11 +1,8 @@ -#!/command/with-contenv sh +#!/usr/bin/nu -set -euo pipefail -export BF_E="${PWD##*/}/$(basename ${0})" +use bf +use bf-s6 +bf env load -x aspnet - -#====================================================================================================================== -# Show helpful log message. -#====================================================================================================================== - -bf-svc-finish +# Show helpful log message - DO NOT TERMINATE CONTAINER though +def main [...args] { bf-s6 svc finish } diff --git a/overlay/etc/s6-overlay/s6-rc.d/aspnet/run b/overlay/etc/s6-overlay/s6-rc.d/aspnet/run index f4bd36f..e8771f6 100644 --- a/overlay/etc/s6-overlay/s6-rc.d/aspnet/run +++ b/overlay/etc/s6-overlay/s6-rc.d/aspnet/run @@ -1,55 +1,17 @@ -#!/command/with-contenv sh +#!/bin/withenv sh set -euo pipefail -export BF_E="${PWD##*/}/$(basename ${0})" #====================================================================================================================== -# Verify ASPNET_ASSEMBLY is set. +# Run preflight checks #====================================================================================================================== -[[ -z "${ASPNET_ASSEMBLY}" ]] && bf-error "ASPNET_ASSEMBLY environment variable must be set." +nu -c "use bf-aspnet run ; run preflight" #====================================================================================================================== -# Reset ASPNET_SLEEP variable. +# Start dotnet application. #====================================================================================================================== -bf-env ASPNET_SLEEP 0 > /dev/null 2>&1 - - -#====================================================================================================================== -# Sleep thread. -# -# Arguments -# 1 The number of seconds to sleep for -#====================================================================================================================== - -go_to_sleep() { - - SLEEP=${1} - bf-debug "Sleeping for ${SLEEP}s." - bf-env ASPNET_SLEEP ${SLEEP} > /dev/null 2>&1 - sleep ${SLEEP} - -} - - -#====================================================================================================================== -# Verify assembly exists before running it. -#====================================================================================================================== - -ASSEMBLY_PATH=${ASPNET_APP_LIVE}/${ASPNET_ASSEMBLY} -if [ -f "${ASSEMBLY_PATH}" ] ; then - - bf-echo "Starting ASP.NET application." - bf-debug " .. ${ASSEMBLY_PATH}." - - s6-setuidgid www /usr/bin/dotnet "${ASSEMBLY_PATH}" - -else - - bf-notok "${ASSEMBLY_PATH} not found." - go_to_sleep 30 - -fi +s6-setuidgid www dotnet ${BF_ASPNET_APP_LIVE}/${BF_ASPNET_ASSEMBLY} diff --git a/overlay/tmp/install b/overlay/tmp/install index 7cd0868..44217dc 100644 --- a/overlay/tmp/install +++ b/overlay/tmp/install @@ -1,154 +1,143 @@ -#!/bin/sh - -set -euo pipefail -export BF_E=`basename ${0}` - - -#====================================================================================================================== -# Add www user. -#====================================================================================================================== - -bf-adduser www - - -#====================================================================================================================== -# Install dotnet dependencies. -#====================================================================================================================== - -apk add --no-cache \ - ca-certificates \ - icu-libs \ - krb5-libs \ - libgcc \ - libintl \ - libssl1.1 \ - libstdc++ \ - zlib - - -#====================================================================================================================== -# Ensure target platform is set. -#====================================================================================================================== - -[[ -z "${TARGETPLATFORM-}" ]] && bf-error "Target platform not set." - - -#====================================================================================================================== -# Get target platform architecture. -#====================================================================================================================== - -case "${TARGETPLATFORM}" in - - linux/amd64) - ARCH="x64" - ;; - - linux/arm64) - ARCH="arm64" - ;; - - *) - bf-error "Unsupported target platform: ${TARGETPLATFORM}." - ;; - -esac - -bf-echo "Platform architecture ${ARCH}." - - -#====================================================================================================================== -# Get .NET Version. -#====================================================================================================================== - -cd /tmp - -V=$(cat DOTNET_REVISION) -bf-echo ".NET version ${V}." - - -#====================================================================================================================== -# Verify checksum of a dotnet download. -# 1 Either 'runtime' or 'aspnet' -#====================================================================================================================== - -verify () { - - DL="${ASPNET_VERSION}-${ARCH}-${1}" - - case "${DL}" in - - 6-x64-runtime) HASH="9e0dd5233c4d69b77e3852f31f8e535d86d3381115a3bc7340e0642aa2358f7b7d8ce1cf5186126d238637d0f98186d7b54307f96c560d4f2356916962093e58" ;; - 6-arm64-runtime) HASH="ddc9a8d9a4bb723f83badd0e849d65f7138125207e4bcd17264ead839483687afee70ee1e1d01e6fab2fef95f85d552d950a9fe814416fbf8feb32842bbed2ff" ;; - 7-x64-runtime) HASH="012e228b5809a5823ba50f3b93823d343da51f09e32c94ef0c1389870ee535ef0fc603e4f13812c75cb5c0f1d942601e8ba3ab4c423c631982d36252eec7d3dc" ;; - 7-arm64-runtime) HASH="62c80c4c368f4ca1ccdf3501b8f3caf4f7f4cac91214fc6186750c997c76da8425f4ad1732dab7935e0187610a70ccc78ee3d2885802cf25d71e745d1995b9e3" ;; - 8-x64-runtime) HASH="22e77f222b2d9015352f97826c046cac81f33a3bc945837143b799895a55efffb536aec5040fdce95abcaddc2e4fcdc6d818b41b6b3c224d4902c6192cf9190c" ;; - 8-arm64-runtime) HASH="bc9391771681719d7d44ac9357a877cb20a2d96e7cf13c05b7e9b1fc6905f6d9731202929cc42e5c8ad96d1edf22efd0e69ed62d63c889b554df56582dfd1918" ;; - - 6-x64-aspnet) HASH="e4b5f6447d498e352348490e70a7f6c0abf9339f7a1d326f32b5f96cef166833b1e0e942c913795a2d90b203e02f44f77be62f7898c17eac7b6c665cd4c13227" ;; - 6-arm64-aspnet) HASH="f47d4b1699c36d87db4297e86cf62222f7c89ed0341200df4e7dda6e63e3c1afa255e874501ed2cdf2a9170c508df54b27d88f0be72e8dfc760c02d3088c8c43" ;; - 7-x64-aspnet) HASH="a20921e3b534357938f93f368ef0de6eb5204208ece423697f28952176352b246dec43b41c95251b00769cf6a54f87bdcff48704f20a147759aacb3e6b58de3c" ;; - 7-arm64-aspnet) HASH="fa061e5fc279d95d600452651845d6297c9bae6776a9ed6562a681b272ea8bc33850ed005cce3cd901bbb940b2d012fea082aa83204e1684faa90b71b274bc6b" ;; - 8-x64-aspnet) HASH="af6889f875d113d014f1655f9b265e3e83e4b8203b4093b653d4b325d91ec54ed0ba324f1f417284ce631454656fa02f39f0601286c4d6ecc7b63ac8a67eec6c" ;; - 8-arm64-aspnet) HASH="67fdc66ba42f38ce04636f3a742bcfcbd17440aea19fdfed19ba1bebb934ef71959dd7b324064f927bcd1ff0f020601f3923ea12d0320f0a5d810b4fe32ee651" ;; - - *) bf-error "Unsupported dotnet download: ${DL}." ;; - - esac - - bf-echo "Verifying ${1} download..." - echo "${HASH} ${1}.tar.gz" | sha512sum -c - - bf-done - +#!/usr/bin/nu + +use bf + +# Download URLs for .NET and ASP.NET runtimes +const dotnet_url = "https://dotnetcli.azureedge.net/dotnet/Runtime/{v}/dotnet-runtime-{v}-linux-musl-{a}.tar.gz" +const aspnet_url = "https://dotnetcli.azureedge.net/dotnet/aspnetcore/Runtime/{v}/aspnetcore-runtime-{v}-linux-musl-{a}.tar.gz" + +# Setup and install .NET runtime and ASP.NET +def main [] { + # add www user + bf user add www + + # install dotnet dependencies + let deps = [ + ca-certificates + icu-libs + krb5-libs + libgcc + libintl + libssl1.1 + libstdc++ + zlib + ] + bf write "Installing .NET dependencies." + bf pkg install $deps + + # get platform architecture + let platform = bf build | get Platform + let arch = match $platform { + "linux/amd64" => "x64" + "linux/arm/v7" => "arm" + "linux/arm64" => "arm64" + _ => { bf write error $"Unsupported platform: ($platform)" } + } + bf write $"Detected platform architecture is: ($arch)." + + # get .NET version + cd /tmp + let revision = bf fs read DOTNET_REVISION + bf build add "ASP.NET" $revision + bf write $"Installing .NET v($revision)." + + # install .NET runtime + # See https://github.com/dotnet/dotnet-docker/blob/main/src/aspnet/8.0/alpine3.18/arm64v8/Dockerfile + bf write "Installing .NET runtime." + let dotnet_build = match (get_major $revision) { + "9" => "xxx" + _ => $revision + } + let dotnet_file = download $dotnet_build $arch dotnet $dotnet_url + let dotnet_dir = "/usr/share/dotnet" + + try { + bf write $" .. extracting ($dotnet_file)." + mkdir $dotnet_dir + ^tar -oxzf $dotnet_file -C $dotnet_dir + ^ln -s $"($dotnet_dir)/dotnet" /usr/bin/dotnet + } catch { + bf write error " .. error installing .NET runtime." + } + + # install ASP.NET runtime + # See https://github.com/dotnet/dotnet-docker/blob/main/src/aspnet/8.0/alpine3.18/arm64v8/Dockerfile + bf write $"Installing ASP.NET runtime." + let aspnet_build = match (get_major $revision) { + "9" => "xxx" + _ => $revision + } + let aspnet_file = download $aspnet_build $arch aspnet $aspnet_url + let aspnet_dir = "shared/Microsoft.AspNetCore.App" + + try { + bf write $" .. extracting ($aspnet_file)." + ^tar -oxzf $aspnet_file -C $dotnet_dir $"./($aspnet_dir)" + } + + if ($"($dotnet_dir)/($aspnet_dir)/($aspnet_build)" | bf fs is_not_dir) { + bf write error " .. error installing ASP.NET runtime." + } + + # save ASP.NET directory + bf env set ASPNET_RUNTIME $"($dotnet_dir)/($aspnet_dir)" + + # add bf-aspnet module to config + bf config use bf-aspnet } +# Get the major version from a revision (i.e. get the first character) +def get_major [ + revision: string # Revision number +] { + $revision | split chars | first +} -#====================================================================================================================== -# Download and install .NET Runtime. -#====================================================================================================================== - -DOTNET=/usr/share/dotnet - -if [ "$(echo ${V} | cut -c 1)" == "8" ] ; then - bf-echo "Changing version to ${V}." - V="8.0.0-rc.2.23479.6" # https://github.com/dotnet/dotnet-docker/blob/main/src/runtime/8.0/alpine3.18/arm64v8/Dockerfile -fi - -RUNTIME="runtime" -RUNTIME_URL="https://dotnetcli.azureedge.net/dotnet/Runtime/${V}/dotnet-runtime-${V}-linux-musl-${ARCH}.tar.gz" -bf-echo "Downloading ${RUNTIME_URL}..." -wget -O ${RUNTIME}.tar.gz ${RUNTIME_URL} -bf-done - -verify ${RUNTIME} - -bf-echo "Installing .NET runtime..." -mkdir -p ${DOTNET} \ - && tar -C ${DOTNET} -oxzf ${RUNTIME}.tar.gz \ - && ln -s ${DOTNET}/dotnet /usr/bin/dotnet - -[[ -d ${DOTNET} ]] && bf-done \ - || bf-error ".NET runtime not installed." - - -#====================================================================================================================== -# Download and install ASP.NET Runtime. -#====================================================================================================================== - -if [ "$(echo ${V} | cut -c 1)" == "8" ] ; then - bf-echo "Changing version to ${V}." - V="8.0.0-rc.2.23480.2" # https://github.com/dotnet/dotnet-docker/blob/main/src/aspnet/8.0/alpine3.18/arm64v8/Dockerfile -fi - -ASPNET="aspnet" -ASPNET_URL="https://dotnetcli.azureedge.net/dotnet/aspnetcore/Runtime/${V}/aspnetcore-runtime-${V}-linux-musl-${ARCH}.tar.gz" -bf-echo "Downloading ${ASPNET_URL}..." -wget -O ${ASPNET}.tar.gz ${ASPNET_URL} -bf-done - -verify ${ASPNET} - -bf-echo "Installing ASP.NET..." -tar -ozxf ${ASPNET}.tar.gz -C ${DOTNET} ./shared/Microsoft.AspNetCore.App - -[[ -d ${DOTNET}/shared/Microsoft.AspNetCore.App/${V} ]] && bf-done \ - || bf-error "ASP.NET runtime not installed." +# Download and verify a runtime for .NET or ASP.NET +def download [ + version: string # Runtime verison + arch : string # Platform architecture + kind: string # Runtime kind - 'dotnet' or 'aspnet' + url_format: string # URL format - see constants at top of module +] { + # build the URL and filename + let url = $url_format | str replace --all "{v}" $version | str replace --all "{a}" $arch + let filename = $"(get_major $version)-($arch)-($kind)" + let filename_with_ext = $"($filename).tar.gz" + + # download the requested runtime + bf write $" .. downloading ($url)." + http get $url | save $filename_with_ext + + # get the relevant hash + let hash = match $filename { + "6-x64-dotnet" => "bee78309422930d7c3cf7880fcacc7d130b936fde6c16162448869ae7516321edc145b0a53087a5d206d07fef8844d7f06eafe6db90b035ab4957ccf3ff80d26" + "6-arm-dotnet" => "99235f8efcdcd5148cc40ae5f43e5546ba73bffa410d17ae0880be96f819b4afe4ff6676598df95f3c873dd49965379343b44cd3d5ffde7fffb77c0142aa65ed" + "6-arm64-dotnet" => "0466e251a07262c9796d4d67f61247f6c7c6c998414cc789dda6e4f927ab7ff9463ba226f0141f71bc27a1e55f97ed6d313220e008806be3045929b709fa1175" + "7-x64-dotnet" => "954cb4d80a7da484c5f73a4dd26b35866fe320260af6c7c7dd79e7b82bfc4d972c6c854c705514983f78ee2f44b572f30ed622dd69e94c737e6c5663279f68be" + "7-arm-dotnet" => "16343c03c29c4242683c9e1c9a669ffdc50ca8f5805ee539a3628a05e412dc7afe2df1a81ba57bfceedc9a42450bbd9b59a1b64b32e0e0429f0ce7e335db6f11" + "7-arm64-dotnet" => "92262e41a370d9c4b05b0dec1a73deccfe05b1c841300f6c0aa2eed49f7ca5c1d76727a571cef3c5a063edcd6da2ce69d2357c3e3372f5789387706b4512e97d" + "8-x64-dotnet" => "bc9278786a728bcc404dd014f7823334312c0db6d949df104bb31e775f53b5684bba00611abb58873b8894d20489d5145fb351903b68dece92a7dbad14c3b9f2" + "8-arm-dotnet" => "3947064cdcf0c3417e9809f7595707bdc537c6280de82e0df170b15abc6be6705cb180b243c23dc373a76698e9e9f434a89975ae1734abad7f39607ef83e772c" + "8-arm64-dotnet" => "a8bb01b3e3dce7cd5a5ddcb8af13f3bc9b3be1cd3d60ee728b845c88cb12005e5e8c5d54a51391fc27de4023080ce9b231c1c48e858b3f1b551a9e1936d59f27" + "6-x64-aspnet" => "2730ef44301f0926ba8edf41180351f7f145843fd37eff8e2845eab02a5c449281bbbfdd21f1710f7773d93627f514298a46706801aef0063f920c752e063ea1" + "6-arm-aspnet" => "cf325dc954bbcc1476899fa6716cb7d474cf98eca12ae555425336e6277e638e93c2d186f61a93a2ccf19e33ee440a15980f5180b54fac1a2aa68121df30cab6" + "6-arm64-aspnet" => "c0f827ceb51e39a0a78d82efad03a43adf1c6a9ca3e411ace69be2dac4faad56c74775381517d676154b3a5e0d972ba5ad05593623c7af945643d518749e0426" + "7-x64-aspnet" => "e3fdc0b57683c633e18df0afb70d3348c1a756541c7dfab6c763b9b9ac471aac7b34170cc07d3b989d80521ae3b0b5c2af1aea593b4e13079bfe678356933c25" + "7-arm-aspnet" => "df4645f89aa8d4ae45a550c6c8b97f81d34b9e6c51b9b37b72b07e62e9d4a195b4fa7f6cd75956f77ce47d55273cbdd4edd51caa43f0453c43f4b0c43592a1f7" + "7-arm64-aspnet" => "4f7b441a8116f0fe4f6429f6aa5fa68b2387bcc9e59bb56c5c8bb53733f7c2e57bd45502c15f5c2c56d554f15543dbe7cc3a3faf9b1600f018b2d229030b8bbd" + "8-x64-aspnet" => "12723b685b86d3d2f69692781f731fe2c56bfc4d34489b9c901775e78f8f96edb78b97b9234b44b14aa2f578c1a054e425ebe8ced42f59e82c39c90c341fc1d9" + "8-arm-aspnet" => "16254138c90ceb74becd25b0a4bc000838ee5e480c987b68300244d2916a97fb2adb4c715935f9a8547efd30bbf499ab68dfdcb79cfbeab77c46f1b575cca2e9" + "8-arm64-aspnet" => "9ac1b612e126c7c4a9eb2b3343c93875268f3a4d78cf4c6ece9e718b76b60f13e96efb9488e7d83cfb128ae766d8bf05e764d6a11c3a315ea1820a011afd585f" + _ => { bf write error $"Unsupported .NET download: ($filename)." } + } + + # verify downloaded file + bf write $" .. verifying ($filename) download." install/download + { $"($hash) ($filename_with_ext)" | ^sha512sum -c - } | bf handle -f {|code, err| + bf write error $" .. checksum did not match for ($filename)." install/download + } install/download + + # return filename with extension + $filename_with_ext +} diff --git a/overlay/usr/bin/bf/aspnet-restart b/overlay/usr/bin/bf/aspnet-restart index 6995826..72ba48f 100644 --- a/overlay/usr/bin/bf/aspnet-restart +++ b/overlay/usr/bin/bf/aspnet-restart @@ -1,11 +1,8 @@ -#!/command/with-contenv sh +#!/usr/bin/nu -set -euo pipefail -export BF_E=`basename ${0}` +use bf +use bf-aspnet app +bf env load -x - -#====================================================================================================================== -# Run restart script. -#====================================================================================================================== - -${ASPNET_LIB}/restart +# Restart ASP.NET application +def main [] { app restart } diff --git a/overlay/usr/bin/bf/aspnet-switch b/overlay/usr/bin/bf/aspnet-switch index e49d10c..546fde4 100644 --- a/overlay/usr/bin/bf/aspnet-switch +++ b/overlay/usr/bin/bf/aspnet-switch @@ -1,18 +1,8 @@ -#!/command/with-contenv sh +#!/usr/bin/nu -set -euo pipefail -export BF_E=`basename ${0}` +use bf +use bf-aspnet app +bf env load -x - -#====================================================================================================================== -# Run switch executable. -#====================================================================================================================== - -${ASPNET_LIB}/switch - - -#====================================================================================================================== -# Restart the service (it is disabled as part of the switch process). -#====================================================================================================================== - -${ASPNET_LIB}/restart +# Switch and then restart ASP.NET application +def main [] { app switch ; app restart } diff --git a/overlay/usr/bin/bf/aspnet-switch-terminate b/overlay/usr/bin/bf/aspnet-switch-terminate index a8c4a85..f0addcc 100644 --- a/overlay/usr/bin/bf/aspnet-switch-terminate +++ b/overlay/usr/bin/bf/aspnet-switch-terminate @@ -1,18 +1,8 @@ -#!/command/with-contenv sh +#!/usr/bin/nu -set -euo pipefail -export BF_E=`basename ${0}` +use bf +use bf-aspnet app +bf env load -x - -#====================================================================================================================== -# Run switch executable. -#====================================================================================================================== - -${ASPNET_LIB}/switch - - -#====================================================================================================================== -# Terminate container to force Kestrel to restart using the new code. -#====================================================================================================================== - -bf-cont-terminate +# Switch publish and live application directories, and then terminate the container +def main [] { app switch --terminate } diff --git a/overlay/usr/bin/bf/healthcheck b/overlay/usr/bin/bf/healthcheck index fade83b..648bacb 100644 --- a/overlay/usr/bin/bf/healthcheck +++ b/overlay/usr/bin/bf/healthcheck @@ -1,11 +1,7 @@ -#!/command/with-contenv sh +#!/usr/bin/nu -set -euo pipefail -export BF_E=`basename ${0}` +use bf +bf env load -x - -#====================================================================================================================== -# Test site. -#====================================================================================================================== - -bf-test-url ${ASPNETCORE_URLS//[+]/localhost} +# Attempt to load localhost +def main [] { bf http test_url $"(bf env -P ASPNETCORE_URLS | str replace "+" "localhost")" | if not $in { exit 1 } } diff --git a/overlay/usr/lib/bf/aspnet/disable b/overlay/usr/lib/bf/aspnet/disable deleted file mode 100644 index c8502ad..0000000 --- a/overlay/usr/lib/bf/aspnet/disable +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/sh - -set -euo pipefail - - -#====================================================================================================================== -# Stop the aspnet service (if it is up). -#====================================================================================================================== - -UP=`s6-svstat -u ${S6_SERVICES}/aspnet` -if [ "${UP}" = "true" ] ; then - - bf-echo "Disabling ASP.NET service." "aspnet/disable" - bf-svc-down aspnet - -else - - bf-debug "No need to disable ASP.NET service - it is down." "aspnet/disable" - -fi - - -#====================================================================================================================== -# Kill the remaining process (if it is running). -#====================================================================================================================== - -PID=`ps aux | grep ${ASPNET_ASSEMBLY} | grep -v 'grep' | awk '{print $1}' || echo ""` -if [ -n "${PID}" ] ; then - - bf-echo "Killing ${ASPNET_ASSEMBLY} process." "aspnet/disable" - kill ${PID} > /dev/null 2>&1 || true - -else - - bf-debug "No need to kill ${ASPNET_ASSEMBLY} process - it is not running." "aspnet/disable" - -fi diff --git a/overlay/usr/lib/bf/aspnet/restart b/overlay/usr/lib/bf/aspnet/restart deleted file mode 100644 index 72c6ffa..0000000 --- a/overlay/usr/lib/bf/aspnet/restart +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh - -set -euo pipefail - - -#====================================================================================================================== -# Restart the aspnet service. -#====================================================================================================================== - -${ASPNET_LIB}/disable - -bf-echo "Restarting ${ASPNET_ASSEMBLY} application." "aspnet/restart" -s6-rc -u change aspnet diff --git a/overlay/usr/lib/bf/aspnet/switch b/overlay/usr/lib/bf/aspnet/switch deleted file mode 100644 index 0ef4631..0000000 --- a/overlay/usr/lib/bf/aspnet/switch +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/sh - -set -euo pipefail - - -#====================================================================================================================== -# Check for published files. -#====================================================================================================================== - -[[ -z "$(ls -A ${ASPNET_APP_PUBLISH})" ]] && bf-error "Please publish source files first." "aspnet/switch" - - -#====================================================================================================================== -# Disable application (so it won't try to restart before we're ready). -#====================================================================================================================== - -${ASPNET_LIB}/disable - - -#====================================================================================================================== -# Switch code from publish to live. -#====================================================================================================================== - -bf-echo "Switching code..." "aspnet/switch" - -TEMP=$(mktemp -d src.XXXXXX) || bf-error "Unable to create temporary source directory." "aspnet/switch" - -if [ "$(ls -A ${ASPNET_APP_LIVE})" ] ; then - bf-debug " .. moving live files to ${TEMP}" "aspnet/switch" - mv ${ASPNET_APP_LIVE}/* ${TEMP} -fi - -bf-debug " .. moving published files to ${ASPNET_APP_LIVE}" "aspnet/switch" -mv ${ASPNET_APP_PUBLISH}/* ${ASPNET_APP_LIVE} - -if [ "$(ls -A ${TEMP})" ] ; then - bf-debug " .. moving live files to ${ASPNET_APP_PUBLISH}" "aspnet/switch" - mv ${TEMP}/* ${ASPNET_APP_PUBLISH} -fi - -bf-debug " .. reapplying permissions" "aspnet/switch" -bf-ch-apply "${BF_CH_D}/10-aspnet" - -bf-done "aspnet/switch" diff --git a/run.sh b/run.sh old mode 100644 new mode 100755 index efc51bc..7ab91b7 --- a/run.sh +++ b/run.sh @@ -1,7 +1,7 @@ #!/bin/sh IMAGE=`cat VERSION` -ASPNET=${1:-6.0} +ASPNET=${1:-8} docker buildx build \ --load \ @@ -11,4 +11,10 @@ docker buildx build \ -t aspnet${ASPNET}-dev \ . \ && \ - docker run -it aspnet${ASPNET}-dev sh + docker run -it \ + -e BF_DEBUG=1 \ + -e BF_ASPNET_ASSEMBLY=bf.bfren_dev.dll \ + -p "5000:5000" \ + -v /home/bcg/docker/aspnet/v/live:/app/live \ + aspnet${ASPNET}-dev \ + sh