From b39cb6391b854732cdeaa4781dd221b5bff73d53 Mon Sep 17 00:00:00 2001 From: PassiveLemon Date: Thu, 24 Aug 2023 17:15:24 -0400 Subject: [PATCH] Completely rework the container --- .github/workflows/main.yml | 46 +++++++++++++++++++++++++++++++ docker/Dockerfile | 44 ++++++++++++++++++++---------- docker/LICENSE | 21 --------------- docker/README.md | 25 ++++++++--------- docker/entrypoint.sh | 55 ++------------------------------------ docker/notifier.sh | 26 ------------------ 6 files changed, 89 insertions(+), 128 deletions(-) create mode 100644 .github/workflows/main.yml delete mode 100644 docker/LICENSE delete mode 100644 docker/notifier.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..ca9d9a1 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,46 @@ +name: Image Publisher + +on: + release: + types: [ published ] + +jobs: + setup-build-push: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + ref: ${{ github.event.release.tag_name }} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to Dockerhub + run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin + + - name: Setup building file structure + run: | + cp -r $GITHUB_WORKSPACE/src/ $GITHUB_WORKSPACE/docker/ + + - name: Build the image + run: | + cd $GITHUB_WORKSPACE/docker/ + docker buildx create --name mainbuilder --driver docker-container --platform linux/amd64,linux/arm64 --use + + docker buildx build --push \ + --build-arg VERSION=${{ github.event.release.tag_name }} \ + --provenance=false \ + --platform linux/amd64,linux/arm64 \ + --tag zoraxydocker/zoraxy:${{ github.event.release.tag_name }} \ + . + + docker buildx build --push \ + --build-arg VERSION=${{ github.event.release.tag_name }} \ + --provenance=false \ + --platform linux/amd64,linux/arm64 \ + --tag zoraxydocker/zoraxy:latest \ + . diff --git a/docker/Dockerfile b/docker/Dockerfile index 1b742f5..8ffd402 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,22 +1,38 @@ -FROM docker.io/golang:1.21rc3-alpine3.18 +FROM docker.io/golang:alpine +# VERSION comes from the main.yml workflow --build-arg +ARG VERSION -RUN apk add --no-cache bash curl jq git sudo +RUN apk add --no-cache bash netcat-openbsd sudo -RUN mkdir -p /zoraxy/source/ &&\ - mkdir -p /zoraxy/config/ +RUN mkdir -p /opt/zoraxy/source/ &&\ + mkdir -p /opt/zoraxy/config/ &&\ + mkdir -p /usr/local/bin/ -VOLUME [ "/zoraxy/config/" ] +COPY entrypoint.sh /opt/zoraxy/ -COPY entrypoint.sh /zoraxy/ -COPY notifier.sh /zoraxy/ +RUN chmod -R 755 /opt/zoraxy/ &&\ + chmod +x /opt/zoraxy/entrypoint.sh -RUN chmod 755 /zoraxy/ &&\ - chmod +x /zoraxy/entrypoint.sh +VOLUME [ "/opt/zoraxy/config/" ] -ENV DOCKER="2.1.0" -ENV NOTIFS="1" +# If you build it yourself, you will need to add the src directory into the docker directory. +COPY ./src/ /opt/zoraxy/source/ -ENV VERSION="latest" -ENV ARGS="-port=:8000 -noauth=false" +WORKDIR /opt/zoraxy/source/ + +RUN go mod tidy &&\ + go build -o /usr/local/bin/zoraxy &&\ + rm -r /opt/zoraxy/source/ + +RUN chmod +x /usr/local/bin/zoraxy + +WORKDIR /opt/zoraxy/config/ + +ENV VERSION=$VERSION + +ENV ARGS="-noauth=false" + +ENTRYPOINT ["/opt/zoraxy/entrypoint.sh"] + +HEALTHCHECK --interval=5s --timeout=5s --retries=2 CMD nc -vz 127.0.0.1 8000 || exit 1 -ENTRYPOINT ["/zoraxy/entrypoint.sh"] diff --git a/docker/LICENSE b/docker/LICENSE deleted file mode 100644 index 1c169e2..0000000 --- a/docker/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2022 PassiveLemon - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/docker/README.md b/docker/README.md index 3e7879b..bef8a87 100644 --- a/docker/README.md +++ b/docker/README.md @@ -16,21 +16,20 @@ docker run -d --name (container name) -p (ports) -v (path to storage directory): ``` ### Using Docker Compose
-``` +```yml version: '3.3' services: zoraxy-docker: image: passivelemon/zoraxy-docker:latest container_name: (container name) ports: - - 80:80 # Http port - - 443:443 # Https port - - (external):8000 # Management portal port + - 80:80 + - 443:443 + - (external):8000 volumes: - - (path to storage directory):/zoraxy/config/ # Host directory for Zoraxy file storage + - (path to storage directory):/opt/zoraxy/config/ environment: - ARGS: '(your arguments)' # The arguments to run with Zoraxy. Enter them as they would be entered normally. - VERSION: '(version in x.x.x)' # The release version of Zoraxy. + ARGS: '(your arguments)' ``` | Operator | Need | Details | @@ -38,9 +37,8 @@ services: | `-d` | Yes | will run the container in the background. | | `--name (container name)` | No | Sets the name of the container to the following word. You can change this to whatever you want. | | `-p (ports)` | Yes | Depending on how your network is setup, you may need to portforward 80, 443, and the management port. | -| `-v (path to storage directory):/zoraxy/config/` | Recommend | Sets the folder that holds your files. This should be the place you just chose. By default, it will create a Docker volume for the files for persistency but they will not be accessible. | -| `-e ARGS=(your arguments)` | No | Sets the arguments to run Zoraxy with. Enter them as you would normally. By default, it is ran with `-port=:8000 -noauth=false` | -| `-e VERSION=(version)` | Recommended | Sets the version of Zoraxy that the container will download. Must be a supported release found on the Zoraxy GitHub. Make sure that it is not set to the containers version. Defaults to the latest if not set. | +| `-v (path to storage directory):/opt/zoraxy/config/` | Recommend | Sets the folder that holds your files. This should be the place you just chose. By default, it will create a Docker volume for the files for persistency but they will not be accessible. | +| `-e ARGS=(your arguments)` | No | Sets the arguments to run Zoraxy with. Enter them as you would normally. By default, it is ran with `-noauth=false` but you cannot change the management port. This is required for the healthcheck to work. | | `passivelemon/zoraxy-docker:latest` | Yes | The repository on Docker hub. By default, it is the latest version that I have published. | ## Examples:
@@ -50,7 +48,7 @@ docker run -d --name zoraxy -p 80:80 -p 443:443 -p 8005:8000/tcp -v /home/docker ``` ### Docker Compose
-``` +```yml version: '3.3' services: zoraxy-docker: @@ -61,8 +59,7 @@ services: - 443:443 - 8005:8000/tcp volumes: - - /home/docker/Containers/Zoraxy:/zoraxy/config/ + - /home/docker/Containers/Zoraxy:/opt/zoraxy/config/ environment: - ARGS: '-port=:8000 -noauth=false' - VERSION: '2.6.5' + ARGS: '-noauth=false' ``` diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 871d2bd..cc51aff 100644 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -1,55 +1,4 @@ #!/usr/bin/env bash +echo "Zoraxy version $VERSION" -echo "|| Testing connectivity... ||" -if ! curl -sSf https://www.github.com > /dev/null; then - echo "|| GitHub could not be reached. Please check your internet connection and try again. ||" - exit -fi -if [ "$(curl -s "https://api.github.com/repos/tobychui/zoraxy/git/refs/tags" | jq 'any(.[] | tostring; test("API rate limit exceeded"))')" = "true" ]; then - echo "|| Currently rate limited by GitHub. Please wait until it clears. ||" - exit -fi - -# Container update notifier -. /zoraxy/notifier.sh - -# Remove the V from the version if its present -VERSION=$(echo "${VERSION}" | awk '{gsub(/^v/, ""); print}') - -# If version isn't valid, hard stop. -function versionvalidate () { - if [ -z $(curl -s "https://api.github.com/repos/tobychui/zoraxy/git/refs/tags" | jq -r ".[].ref | select(contains(\"${VERSION}\"))") ]; then - echo "|| ${VERSION} is not a valid version. Please ensure it is set correctly. ||" - exit - fi -} - -# Version setting -if [ "${VERSION}" = "latest" ]; then - # Latest release - VERSION=$(curl -s https://api.github.com/repos/tobychui/zoraxy/releases | jq -r "[.[] | select(.tag_name)] | max_by(.created_at) | .tag_name") - versionvalidate - echo "|| Using Zoraxy version ${VERSION} (latest). ||" -else - versionvalidate - echo "|| Using Zoraxy version ${VERSION}. ||" -fi - -# Downloads & setup -if [ ! -f "/zoraxy/server/zoraxy_bin_${VERSION}" ]; then - echo "|| Cloning repository... ||" - cd /zoraxy/source/ - git clone --depth 1 --single-branch --branch main https://github.com/tobychui/zoraxy - cd /zoraxy/source/zoraxy/src/ - echo "|| Building... ||" - go mod tidy - go build - mkdir -p /usr/local/bin/ - mv /zoraxy/source/zoraxy/src/zoraxy /usr/local/bin/zoraxy_bin_${VERSION} - chmod 755 /usr/local/bin/zoraxy_bin_${VERSION} - echo "|| Finished. ||" -fi - -# Starting -cd /zoraxy/config/ -zoraxy_bin_${VERSION} ${ARGS} +zoraxy -port=:8000 ${ARGS} diff --git a/docker/notifier.sh b/docker/notifier.sh deleted file mode 100644 index c470012..0000000 --- a/docker/notifier.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash - -# Container update notifier. Funny code do not go brrrrrrr -UPDATE=$(curl -s https://api.github.com/repos/PassiveLemon/zoraxy-docker/releases | jq -r 'map(select(.prerelease = false)) | .[0].tag_name') -UPDATE1=$(echo $UPDATE | awk -F. '{print $1}') -UPDATE2=$(echo $UPDATE | awk -F. '{print $2}') -UPDATE3=$(echo $UPDATE | awk -F. '{print $3}') - -DOCKER1=$(echo $DOCKER | awk -F. '{print $1}') -DOCKER2=$(echo $DOCKER | awk -F. '{print $2}') -DOCKER3=$(echo $DOCKER | awk -F. '{print $3}') - -NOTIFY=0 - -if [ "${DOCKER1}" -lt "${UPDATE1}" ]; then - NOTIFY=1 -fi -if [ "${DOCKER1}" -le "${UPDATE1}" ] && [ "${DOCKER2}" -lt "${UPDATE2}" ]; then - NOTIFY=1 -fi -if [ "${DOCKER1}" -le "${UPDATE1}" ] && [ "${DOCKER2}" -le "${UPDATE2}" ] && [ "${DOCKER3}" -lt "${UPDATE3}" ]; then - NOTIFY=1 -fi -if [ "${NOTIFY}" = "1" ] && [ "${NOTIFS}" != "0" ]; then - echo "|| Container update available. Current (${DOCKER}): New (${UPDATE}). ||" -fi