Skip to content

Commit

Permalink
Try to get github actions to automatically tag
Browse files Browse the repository at this point in the history
  • Loading branch information
jamcole committed Oct 21, 2023
1 parent db636e8 commit 0616676
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 27 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ on:
- cron: '38 1 * * *'
push:
branches: [ "main" ]
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]
pull_request:
branches: [ "main" ]

Expand All @@ -21,7 +19,6 @@ env:
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}


jobs:
build:

Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ valid_known_packs.json
resource_packs
config
behavior_packs
src/resources/*-url.txt
.task

36 changes: 12 additions & 24 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
5 changes: 5 additions & 0 deletions bedrock_server.sh
Original file line number Diff line number Diff line change
@@ -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..."
Expand Down
Empty file added src/resources/.keep
Empty file.
59 changes: 59 additions & 0 deletions taskfile.dist.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 0616676

Please sign in to comment.