From 3259217e9dc5bb23c9dbd5679f7de68dc2da9db7 Mon Sep 17 00:00:00 2001 From: aptalca Date: Thu, 15 Oct 2020 07:49:11 -0400 Subject: [PATCH] code-server-dotnet: initial release --- .travis.yml | 21 +++++++---- Dockerfile | 42 ++++++++++++++++++++-- Dockerfile.complex | 21 ----------- README.md | 20 +++++------ root/etc/cont-init.d/98-dotnet | 56 ++++++++++++++++++++++++++++++ root/etc/cont-init.d/98-vpn-config | 27 -------------- root/etc/services.d/sshvpn/run | 3 -- 7 files changed, 117 insertions(+), 73 deletions(-) delete mode 100644 Dockerfile.complex create mode 100644 root/etc/cont-init.d/98-dotnet delete mode 100644 root/etc/cont-init.d/98-vpn-config delete mode 100644 root/etc/services.d/sshvpn/run diff --git a/.travis.yml b/.travis.yml index e6e5b1f..44e4732 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,16 +4,16 @@ language: shell branches: only: - - - #replace variables, omit brackets + - code-server-dotnet services: - docker env: global: - - DOCKERHUB="linuxserver/mods" #don't modify - - BASEIMAGE="baseimagename" #replace - - MODNAME="modname" #replace + - DOCKERHUB="linuxserver/mods" + - BASEIMAGE="code-server" + - MODNAME="dotnet" jobs: include: @@ -21,15 +21,22 @@ jobs: if: (type IN (pull_request)) script: # Build image - - docker build --no-cache -t ${DOCKERHUB}:${BASEIMAGE}-${MODNAME}-${TRAVIS_COMMIT} . + - DOTNET_JSON="$(curl --retry 5 -sX GET https://raw.githubusercontent.com/dotnet/core/master/release-notes/releases-index.json)" + - DOTNET_VERSIONS="$(echo $DOTNET_JSON | jq -r '."releases-index"[] | select(."support-phase"=="lts") | ."latest-sdk"' | tr '\n' ' ' | head -c -1)" + - docker build --no-cache --build-arg DOTNET_VERSIONS="${DOTNET_VERSIONS}" -t ${DOCKERHUB}:${BASEIMAGE}-${MODNAME}-${TRAVIS_COMMIT} . - stage: BuildImage if: (NOT (type IN (pull_request))) script: # Build image - - docker build --no-cache -t ${DOCKERHUB}:${BASEIMAGE}-${MODNAME}-${TRAVIS_COMMIT} . + - DOTNET_JSON="$(curl --retry 5 -sX GET https://raw.githubusercontent.com/dotnet/core/master/release-notes/releases-index.json)" + - DOTNET_VERSIONS="$(echo $DOTNET_JSON | jq -r '."releases-index"[] | select(."support-phase"=="lts") | ."latest-sdk"' | tr '\n' ' ' | head -c -1)" + - DOTNET_TAG="$(echo $DOTNET_VERSIONS | tr ' ' '_')" + - docker build --no-cache --build-arg DOTNET_VERSIONS="${DOTNET_VERSIONS}" -t ${DOCKERHUB}:${BASEIMAGE}-${MODNAME}-${TRAVIS_COMMIT} . - docker tag ${DOCKERHUB}:${BASEIMAGE}-${MODNAME}-${TRAVIS_COMMIT} ${DOCKERHUB}:${BASEIMAGE}-${MODNAME} + - docker tag ${DOCKERHUB}:${BASEIMAGE}-${MODNAME}-${TRAVIS_COMMIT} ${DOCKERHUB}:${BASEIMAGE}-${MODNAME}-${DOTNET_TAG} # Login to DockerHub - echo $DOCKERPASS | docker login -u $DOCKERUSER --password-stdin # Push all of the tags - docker push ${DOCKERHUB}:${BASEIMAGE}-${MODNAME}-${TRAVIS_COMMIT} - - docker push ${DOCKERHUB}:${BASEIMAGE}-${MODNAME} \ No newline at end of file + - docker push ${DOCKERHUB}:${BASEIMAGE}-${MODNAME} + - docker push ${DOCKERHUB}:${BASEIMAGE}-${MODNAME}-${DOTNET_TAG} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 4ece5e8..5a74641 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,42 @@ +FROM lsiobase/alpine:3.12 as buildstage + +ARG DOTNET_VERSIONS + +RUN \ + apk add --no-cache \ + curl \ + jq && \ + DOTNET_JSON=$(curl -sX GET "https://raw.githubusercontent.com/dotnet/core/master/release-notes/releases-index.json") && \ + if [ -z ${DOTNET_VERSIONS+x} ]; then \ + DOTNET_VERSIONS=$(echo "$DOTNET_JSON" | jq -r '."releases-index"[] | select(."support-phase"=="lts") | ."latest-sdk"' | tr '\n' ' ' | head -c -1); \ + fi && \ + mkdir -p /root-layer/dotnet && \ + echo "$DOTNET_VERSIONS" > /root-layer/dotnet/versions.txt && \ + echo "versions are ${DOTNET_VERSIONS}" && \ + for i in $DOTNET_VERSIONS; do \ + echo "processing version ${i}" && \ + DOTNET_RELEASE_URL=$(echo "${DOTNET_JSON}" | jq -r ".\"releases-index\"[] | select(.\"latest-sdk\"==\"${i}\") | .\"releases.json\"") && \ + DOTNET_RELEASE_JSON=$(curl -sX GET "${DOTNET_RELEASE_URL}") && \ + AMD64_URL=$(echo "${DOTNET_RELEASE_JSON}" | jq -r ".releases[] | select(.sdk.version==\"${i}\") | .sdk.files[] | select(.name | contains(\"linux-x64\")) | .url") && \ + ARM32_URL=$(echo "${DOTNET_RELEASE_JSON}" | jq -r ".releases[] | select(.sdk.version==\"${i}\") | .sdk.files[] | select(.name | contains(\"linux-arm.\")) | .url") && \ + ARM64_URL=$(echo "${DOTNET_RELEASE_JSON}" | jq -r ".releases[] | select(.sdk.version==\"${i}\") | .sdk.files[] | select(.name | contains(\"linux-arm64\")) | .url") && \ + curl -fS --retry 3 --retry-connrefused -o \ + /root-layer/dotnet/dotnetsdk_"${i}"_x86_64.tar.gz -L \ + "${AMD64_URL}" && \ + curl -fS --retry 3 --retry-connrefused -o \ + /root-layer/dotnet/dotnetsdk_"${i}"_armv7l.tar.gz -L \ + "${ARM32_URL}" && \ + curl -fS --retry 3 --retry-connrefused -o \ + /root-layer/dotnet/dotnetsdk_"${i}"_aarch64.tar.gz -L \ + "${ARM64_URL}"; \ +done + +COPY root/ /root-layer/ + +# runtime stage FROM scratch -LABEL maintainer="username" +LABEL maintainer="aptalca" -# copy local files -COPY root/ / +# Add files from buildstage +COPY --from=buildstage /root-layer/ / \ No newline at end of file diff --git a/Dockerfile.complex b/Dockerfile.complex deleted file mode 100644 index 4463d83..0000000 --- a/Dockerfile.complex +++ /dev/null @@ -1,21 +0,0 @@ -## Buildstage ## -FROM lsiobase/alpine:3.9 as buildstage - -RUN \ - echo "**** install packages ****" && \ - apk add --no-cache \ - curl && \ - echo "**** grab rclone ****" && \ - mkdir -p /root-layer && \ - curl -o \ - /root-layer/rclone.deb -L \ - "https://downloads.rclone.org/v1.47.0/rclone-v1.47.0-linux-amd64.deb" - -# copy local files -COPY root/ /root-layer/ - -## Single layer deployed image ## -FROM scratch - -# Add files from buildstage -COPY --from=buildstage /root-layer/ / diff --git a/README.md b/README.md index 62f203f..8e1d5fe 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,13 @@ -# Rsync - Docker mod for openssh-server +# .NET Core SDK - Docker mod for code server -This mod adds rsync to openssh-server, to be installed/updated during container start. +This mod adds .NET CORE SDK to code server. -In openssh-server docker arguments, set an environment variable `DOCKER_MODS=linuxserver/mods:openssh-server-rsync` +In code server docker arguments, set an environment variable `DOCKER_MODS=linuxserver/mods:code-server-dotnet` -If adding multiple mods, enter them in an array separated by `|`, such as `DOCKER_MODS=linuxserver/mods:openssh-server-rsync|linuxserver/mods:openssh-server-mod2` +If adding multiple mods, enter them in an array separated by `|`, such as `DOCKER_MODS=linuxserver/mods:code-server-dotnet|linuxserver/mods:code-server-mod2` -# Mod creation instructions +All current [lts releases](https://dotnet.microsoft.com/download/dotnet-core) will be made available inside the container (3.1.403 and 2.1.811 as of 2020/10/14). -* Fork the repo, create a new branch based on the branch `template`. -* Edit the `Dockerfile` for the mod. `Dockerfile.complex` is only an example and included for reference; it should be deleted when done. -* Inspect the `root` folder contents. Edit, add and remove as necessary. -* Edit this readme with pertinent info, delete these instructions. -* Finally edit the `travis.yml`. Customize the build branch, and the vars for `BASEIMAGE` and `MODNAME`. -* Ask the team to create a new branch named `-`. Baseimage should be the name of the image the mod will be applied to. The new branch will be based on the `template` branch. -* Submit PR against the branch created by the team. +The binaries are accessible at `/dotnet_/dotnet` for each respective version. + +The latest version binary is symlinked from `/usr/local/bin/dotnet` so it can be called via `dotnet` from anywhere. diff --git a/root/etc/cont-init.d/98-dotnet b/root/etc/cont-init.d/98-dotnet new file mode 100644 index 0000000..a7d1b2e --- /dev/null +++ b/root/etc/cont-init.d/98-dotnet @@ -0,0 +1,56 @@ +#!/usr/bin/with-contenv bash + +# Determine if setup is needed +if [ -d /dotnet ]; then + # remove existing install if updating + if ls -d /dotnet_* >/dev/null 2>&1; then + echo "deleting" $(ls -d /dotnet_*) + rm -rf /dotnet_* + fi + DOTNET_VERSIONS=$(cat /dotnet/versions.txt) + ARCH=$(uname -m) + for i in $DOTNET_VERSIONS; do + mkdir -p "/dotnet_${i}" + tar xzf "/dotnet/dotnetsdk_${i}_${ARCH}.tar.gz" -C "/dotnet_${i}" + done + rm -rf /dotnet + # symlink latest dotnet binary + DOTNET_LATEST=$(echo "$DOTNET_VERSIONS" | awk '{print $1}') + rm -rf /usr/local/bin/dotnet + ln -s /dotnet_${DOTNET_LATEST}/dotnet /usr/local/bin/dotnet + echo " + **************************************************** + **************************************************** + ** + ** + DOTNET SDK versions installed: + $(echo $DOTNET_VERSIONS | sed 's| |\n |g') + ** + ** + Binary locations are:" + for i in $DOTNET_VERSIONS; do + echo " /dotnet_${i}/dotnet" + done + echo " ** + ** + Version $DOTNET_LATEST is symlinked from /usr/local/bin/dotnet and can be called from anywhere via \"dotnet\" + ** + ** + **************************************************** + ****************************************************" + # symlink other dotnet installs for access through latest binary + for i in {2..5}; do + DOTNET_OTHER_SDK_VERSION="$(echo $DOTNET_VERSIONS | awk -v var=${i} '{print $var}')" + if [ -n "$DOTNET_OTHER_SDK_VERSION" ]; then + DOTNET_OTHER_RUNTIME_VERSION="$(ls /dotnet_${DOTNET_OTHER_SDK_VERSION}/shared/Microsoft.NETCore.App)" + echo "**** Symlinking sdk version ${DOTNET_OTHER_SDK_VERSION} and runtime version ${DOTNET_OTHER_RUNTIME_VERSION} ****" + ln -s "/dotnet_${DOTNET_OTHER_SDK_VERSION}/shared/Microsoft.NETCore.App/${DOTNET_OTHER_RUNTIME_VERSION}" "/dotnet_${DOTNET_LATEST}/shared/Microsoft.NETCore.App/${DOTNET_OTHER_RUNTIME_VERSION}" + ln -s "/dotnet_${DOTNET_OTHER_SDK_VERSION}/shared/Microsoft.AspNetCore.App/${DOTNET_OTHER_RUNTIME_VERSION}" "/dotnet_${DOTNET_LATEST}/shared/Microsoft.AspNetCore.App/${DOTNET_OTHER_RUNTIME_VERSION}" + ln -s "/dotnet_${DOTNET_OTHER_SDK_VERSION}/sdk/${DOTNET_OTHER_SDK_VERSION}" "/dotnet_${DOTNET_LATEST}/sdk/${DOTNET_OTHER_SDK_VERSION}" + else + break + fi + done +else + echo "**** Existing dotnet install is up to date, skipping ****" +fi \ No newline at end of file diff --git a/root/etc/cont-init.d/98-vpn-config b/root/etc/cont-init.d/98-vpn-config deleted file mode 100644 index a5f9127..0000000 --- a/root/etc/cont-init.d/98-vpn-config +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/with-contenv bash - -# Determine if setup is needed -if [ ! -f /usr/local/lib/python***/dist-packages/sshuttle ] && \ -[ -f /usr/bin/apt ]; then - ## Ubuntu - apt-get update - apt-get install --no-install-recommends -y \ - iptables \ - openssh-client \ - python3 \ - python3-pip - pip3 install sshuttle -fi -if [ ! -f /usr/lib/python***/site-packages/sshuttle ] && \ -[ -f /sbin/apk ]; then - # Alpine - apk add --no-cache \ - iptables \ - openssh \ - py3-pip \ - python3 - pip3 install sshuttle -fi - -chown -R root:root /root -chmod -R 600 /root/.ssh diff --git a/root/etc/services.d/sshvpn/run b/root/etc/services.d/sshvpn/run deleted file mode 100644 index 7d49e79..0000000 --- a/root/etc/services.d/sshvpn/run +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/with-contenv bash - -sshuttle --dns --remote root@${HOST}:${PORT} 0/0 -x 172.17.0.0/16