From 06166764989130ae5cc7c9d1e70440820f6f499a Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 21 Oct 2023 18:27:49 -0400 Subject: [PATCH] Try to get github actions to automatically tag --- .github/workflows/docker-publish.yml | 15 +++++-- .gitignore | 2 + Dockerfile | 36 ++++++----------- bedrock_server.sh | 5 +++ src/resources/.keep | 0 taskfile.dist.yaml | 59 ++++++++++++++++++++++++++++ 6 files changed, 90 insertions(+), 27 deletions(-) create mode 100644 src/resources/.keep create mode 100644 taskfile.dist.yaml diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 55e464b..2209cb2 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -10,8 +10,6 @@ on: - cron: '38 1 * * *' push: branches: [ "main" ] - # Publish semver tags as releases. - tags: [ 'v*.*.*' ] pull_request: branches: [ "main" ] @@ -21,7 +19,6 @@ env: # github.repository as / IMAGE_NAME: ${{ github.repository }} - jobs: build: @@ -37,6 +34,18 @@ jobs: - name: Checkout repository uses: actions/checkout@v3 + - name: Setup Task + uses: arduino/setup-task@v1 + with: + version: 3.x + repo-token: ${{ secrets.GITHUB_TOKEN }} + + - name: Setup Task + uses: arduino/setup-task@v1 + + - name: Run git-tag Task + run: task clean git-tag + # Install the cosign tool except on PR # https://github.com/sigstore/cosign-installer - name: Install cosign diff --git a/.gitignore b/.gitignore index bbbc734..727ade4 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,6 @@ valid_known_packs.json resource_packs config behavior_packs +src/resources/*-url.txt +.task diff --git a/Dockerfile b/Dockerfile index 4b28cdc..494ecfd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,39 +1,27 @@ +# syntax=docker/dockerfile:1.4 FROM cgr.dev/chainguard/wolfi-base:latest AS builder RUN apk add curl -RUN mkdir -p /root/download/bedrock /root/download/mc-monitor +RUN mkdir -p /tmp/download/bedrock /tmp/download/mc-monitor -WORKDIR /root/download +WORKDIR /tmp/download -# We can't use the authorative url to check for new versions because they block non-browser User-Agents -# This service always seems to return the current version download url -ADD --chmod=644 https://mc-bds-helper.vercel.app/api/latest bedrock-version.txt +COPY src/resources/bedrock-url.txt bedrock/ +RUN cat bedrock/bedrock-url.txt | xargs -n 1 curl -L --no-clobber -o bedrock.zip && \ + unzip -d bedrock bedrock.zip -# We don't need to user the the prior url - but it's an effective cache-buster -#RUN curl -s -L -A 'Edge/10000' 'https://www.minecraft.net/en-us/download/server/bedrock' |\ -# grep -i 'href=' | grep -i linux | grep -Eo 'https?:[^\"]+.zip' | grep -vi preview | head -n 1 | xargs -n 1 curl -L --no-clobber -o bedrock.zip - -RUN cat bedrock-version.txt | head -n 1 | xargs -n 1 curl -L --no-clobber -o bedrock.zip - -RUN unzip -d bedrock bedrock.zip - -#ADD --chmod=644 https://api.github.com/repos/itzg/mc-monitor/releases/latest mc-monitor-version.json - -#RUN cat mc-monitor-version.json | grep -Eo 'https://[^"]+_linux_amd64.tar.gz' | head -n 1 | xargs -n 1 curl -L --no-clobber -o mc-monitor.tar.gz - -ADD https://github.com/itzg/mc-monitor/releases/download/0.12.2/mc-monitor_0.12.2_linux_amd64.tar.gz mc-monitor.tar.gz - -RUN tar -xzvf mc-monitor.tar.gz -C mc-monitor +RUN curl -s -L "https://api.github.com/repos/itzg/mc-monitor/releases/latest" | grep -Eo 'https://[^"]+_linux_amd64.tar.gz' | head -n 1 > mc-monitor/mc-monitor-url.txt && \ + cat mc-monitor/mc-monitor-url.txt | xargs -n 1 curl -L --no-clobber -o mc-monitor.tar.gz && \ + tar -xzvf mc-monitor.tar.gz -C mc-monitor FROM cgr.dev/chainguard/wolfi-base:latest AS runner -RUN \ - apk add libstdc++ curl +RUN apk add libstdc++ curl -COPY --from=builder --chown=root:root /root/download/mc-monitor/mc-monitor /usr/local/bin/ +COPY --from=builder /tmp/download/mc-monitor/mc-monitor /usr/local/bin/ -COPY --from=builder --chown=root:root /root/download/bedrock/ /srv/app/ +COPY --from=builder /tmp/download/bedrock/ /srv/app/ WORKDIR /srv/app diff --git a/bedrock_server.sh b/bedrock_server.sh index d60a268..6b13bf7 100755 --- a/bedrock_server.sh +++ b/bedrock_server.sh @@ -1,5 +1,10 @@ #!/bin/sh +if [ $# -eq 1 ] &&[ $1 = 'version' ]; then + cat bedrock-version.txt + exit +fi + set -e echo "Updating base files in storage..." diff --git a/src/resources/.keep b/src/resources/.keep new file mode 100644 index 0000000..e69de29 diff --git a/taskfile.dist.yaml b/taskfile.dist.yaml new file mode 100644 index 0000000..7edf9d3 --- /dev/null +++ b/taskfile.dist.yaml @@ -0,0 +1,59 @@ +version: '3' + +vars: + IMAGE_BUILDER_CMD: podman + IMAGE_NAME: ghcr.io/jamcole/minecraft-bedrock-image + +tasks: + default: + cmds: + - task: build + url-get: + run: once + generates: + - src/resources/bedrock-url.txt + status: + - test -f src/resources/bedrock-url.txt + cmds: + - curl -s -L -A Edge/10000 "https://www.minecraft.net/en-us/download/server/bedrock" | grep -i 'href=' | grep -i linux | grep -Eo 'https?:[^\"]+.zip' | grep -vi preview | head -n 1 > src/resources/bedrock-url.txt + version-get: + run: once + sources: + - src/resources/bedrock-url.txt + generates: + - src/resources/bedrock-version.txt + status: + - test -f src/resources/bedrock-version.txt + cmds: + - grep -Eo '([0-9\.]*[0-9]+)+' src/resources/bedrock-url.txt > src/resources/bedrock-version.txt + deps: + - url-get + build: + run: always + envs: + DOCKER_BUILDKIT: 1 + cmds: + - sh -c '{{.IMAGE_BUILDER_CMD}} build --progress plain --tag {{.IMAGE_NAME}}:v$(cat src/resources/bedrock-version.txt) .' + requires: + vars: [IMAGE_BUILDER_CMD, IMAGE_NAME] + deps: + - version-get + git-tag: + run: always + cmds: + - git add src/resources/bedrock-version.txt + - git commit -m "version tag" --only src/resources/bedrock-version.txt || true + - git tag v$(cat src/resources/bedrock-version.txt) + - git push origin v$(cat src/resources/bedrock-version.txt) + deps: + - version-get + clean: + status: + - false + cmds: + - for: sources + cmd: '[ -f "{{ .ITEM }}" ] && rm "{{ .ITEM }}"' + sources: + - src/resources/bedrock-url.txt + - src/resources/bedrock-version.txt +