From c45773f6f7a56d1ecd9c11d463beb0586588a81c Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Thu, 17 Sep 2020 18:56:40 -0600 Subject: [PATCH] Rearrange directories and CI a little --- .github/workflows/docker_build_mothd.yml | 12 -------- .github/workflows/publish.yml | 35 +++++++++++++++++++--- .github/workflows/test.yml | 16 ++++++++++ .gitignore | 3 -- CHANGELOG.md | 27 +++++++++++------ Dockerfile | 19 ------------ README.md | 4 +-- VERSION | 1 - build.sh | 14 --------- build/package/Containerfile | 37 ++++++++++++++++++++++++ build/package/build.sh | 22 ++++++++++++++ 11 files changed, 126 insertions(+), 64 deletions(-) delete mode 100644 .github/workflows/docker_build_mothd.yml create mode 100644 .github/workflows/test.yml delete mode 100644 Dockerfile delete mode 100644 VERSION delete mode 100755 build.sh create mode 100644 build/package/Containerfile create mode 100755 build/package/build.sh diff --git a/.github/workflows/docker_build_mothd.yml b/.github/workflows/docker_build_mothd.yml deleted file mode 100644 index 63b8aaa..0000000 --- a/.github/workflows/docker_build_mothd.yml +++ /dev/null @@ -1,12 +0,0 @@ -name: Mothd Docker build -on: [push] - -jobs: - build-mothd: - name: Build mothd - runs-on: ubuntu-latest - steps: - - name: Retrieve code - uses: actions/checkout@v1 - - name: Build mothd - run: docker build . diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 1293514..c6c03aa 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,4 +1,4 @@ -name: Publish Container image +name: Publish on: release: types: [published] @@ -10,18 +10,45 @@ jobs: steps: - name: Retrieve code uses: actions/checkout@v1 - - name: Push to GitHub Packages + + - name: Push moth to GitHub Packages uses: docker/build-push-action@v2 with: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + target: moth + file: build/package/Containerfile registry: docker.pkg.github.com repository: dirtbags/moth/moth tag_with_ref: true - - name: Push to Docker Hub + + - name: Push moth-devel to GitHub Packages + uses: docker/build-push-action@v2 + with: + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + target: moth-devel + file: build/package/Containerfile + registry: docker.pkg.github.com + repository: dirtbags/moth/moth-devel + tag_with_ref: true + + - name: Push moth to Docker Hub uses: docker/build-push-action@v2 with: username: neale password: ${{ secrets.DOCKER_TOKEN }} - registry: dirtbags/moth + target: moth + file: build/packages/Containerfile + repository: dirtbags/moth + tag_with_ref: true + + - name: Push moth-devel to Docker Hub + uses: docker/build-push-action@v2 + with: + username: neale + password: ${{ secrets.DOCKER_TOKEN }} + target: moth-devel + file: build/packages/Containerfile + repository: dirtbags/moth-devel tag_with_ref: true diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..f704c0e --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,16 @@ +name: Tests +on: [push] + +jobs: + test-mothd: + name: Test mothd + runs-on: ubuntu-latest + steps: + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: 1.13 + - name: Retrieve code + uses: actions/checkout@v1 + - name: Test + run: go test ./... diff --git a/.gitignore b/.gitignore index 4e8c7d1..ade229e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,8 +4,5 @@ *.o .idea ./bin/ -build/ -cache/ -target/ puzzles __debug_bin diff --git a/CHANGELOG.md b/CHANGELOG.md index 58b1183..2942bb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,20 +4,29 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [4.0.0] - Unreleased -### Added -- New `transpile` command to replace some functionality of devel server - +## [v4.0.0] - Unreleased ### Changed - Major rewrite/refactor of `mothd` - - There are now providers for State, Puzzles, and Theme. Sqlite, Redis, or S3 should fit in easily. + - Clear separation of roles: State, Puzzles, and Theme + - Sqlite, Redis, or S3 should fit in easily now + - Will allow "dynamic" puzzles now, we just need a flag to enable it - Server no longer provides unlocked content - - Puzzle URLs are now just `/content/${cat}/${points}/` -- `state/until` is now `state/hours` and can specify multiple begin/end hours -- `state/disabled` is now `state/enabled` -- Mothball structure has changed substantially + - Puzzle URLs are now just `/content/${cat}/${points}/` + - Changes to `state` directory + - Most files now have a bit of (English) documentation at the beginning + - `state/until` is now `state/hours` and can specify multiple begin/end hours + - `state/disabled` is now `state/enabled` +- Mothball structure has changed - Mothballs no longer contain `map.txt` + - Mothballs no longer obfuscate content paths - Clients now expect unlocked puzzles to just be `map[string][]int` +- New `/state` API endpoint + - Provides *all* server state: event log, team mapping, messages, configuration + +### Added +- New `transpile` CLI command + - Provides `mothball` action to create mothballs + - Lets you test a few development server things, if you want ### Deprecated diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 3def45a..0000000 --- a/Dockerfile +++ /dev/null @@ -1,19 +0,0 @@ -FROM golang:1.13 AS builder -COPY go.* /src/ -COPY pkg /src/pkg/ -COPY cmd /src/cmd/ -COPY theme /target/theme/ -COPY example-puzzles /target/puzzles/ -COPY LICENSE.md /target/ -WORKDIR /src/ -RUN CGO_ENABLED=0 GOOS=linux go install -i -a -ldflags '-extldflags "-static"' ./... -RUN mkdir -p /target/bin -RUN cp /go/bin/* /target/bin/ - -FROM builder AS tester -RUN go test ./... - -FROM scratch -COPY --from=builder /target / - -ENTRYPOINT [ "/bin/mothd" ] diff --git a/README.md b/README.md index f46329b..47dfc91 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ Dirtbags Monarch Of The Hill Server ===================== -![](https://github.com/dirtbags/moth/workflows/Mothd%20Docker%20build/badge.svg?branch=master) -![](https://github.com/dirtbags/moth/workflows/moth-devel%20Docker%20build/badge.svg?branch=master) +![Build badge](https://github.com/dirtbags/moth/workflows/Mothd%20Docker%20build/badge.svg?branch=master) +![Go report card](https://goreportcard.com/badge/github.com/dirtbags/moth) Monarch Of The Hill (MOTH) is a puzzle server. We (the authors) have used it for instructional and contest events called diff --git a/VERSION b/VERSION deleted file mode 100644 index d5c0c99..0000000 --- a/VERSION +++ /dev/null @@ -1 +0,0 @@ -3.5.1 diff --git a/build.sh b/build.sh deleted file mode 100755 index ac8d438..0000000 --- a/build.sh +++ /dev/null @@ -1,14 +0,0 @@ -#! /bin/sh - -set -e - -read version < VERSION - -cd $(dirname $0) -for img in moth moth-devel; do - echo "==== $img" - sudo docker build --build-arg http_proxy=$http_proxy --build-arg https_proxy=$https_proxy --tag dirtbags/$img --tag dirtbags/$img:$version -f Dockerfile.$img . - [ "$1" = "-push" ] && docker push dirtbags/$img:$version && docker push dirtbags/$img:latest -done - -exit 0 diff --git a/build/package/Containerfile b/build/package/Containerfile new file mode 100644 index 0000000..8b4b94c --- /dev/null +++ b/build/package/Containerfile @@ -0,0 +1,37 @@ +FROM golang:1.13 AS builder +COPY go.* /src/ +COPY pkg /src/pkg/ +COPY cmd /src/cmd/ +COPY theme /target/theme/ +COPY example-puzzles /target/puzzles/ +COPY LICENSE.md /target/ +WORKDIR /src/ +RUN CGO_ENABLED=0 GOOS=linux go install -i -a -ldflags '-extldflags "-static"' ./... + +# I can't put these in /target/bin: doing so would cause the devel server to overwrite Ubuntu's /bin +RUN mkdir -p /target/bin/ +RUN cp /go/bin/* /target/ + +########## + +FROM builder AS tester +RUN go test ./... + +########## + +FROM scratch AS moth +COPY --from=builder /target / +ENTRYPOINT [ "/mothd" ] + +########## + +FROM ubuntu AS moth-devel +RUN apt-get -y update && apt-get -y install \ + build-essential \ + bsdgames \ + figlet toilet \ + python3 \ + python3-pil \ + lua5.3 +COPY --from=builder /bin/* / +CMD [ "/mothd", "-puzzles", "/puzzles" ] diff --git a/build/package/build.sh b/build/package/build.sh new file mode 100755 index 0000000..c9913a0 --- /dev/null +++ b/build/package/build.sh @@ -0,0 +1,22 @@ +#! /bin/sh + +set -e + +cd $(dirname $0)/../.. + +PODMAN=$(command -v podman || echo docker) +VERSION=$(cat CHANGELOG.md | awk -F '[][]' '/^## \[/ {print $2; exit}') + +for target in moth moth-devel; do + tag=dirtbags/$target:$VERSION + echo "==== Building $tag" + $PODMAN build \ + --build-arg http_proxy --build-arg https_proxy --build-arg no_proxy \ + --tag dirtbags/$target \ + --tag dirtbags/$target:$VERSION \ + --target $target \ + -f build/package/Containerfile . + [ "$1" = "-push" ] && docker push dirtbags/$target:$VERSION && docker push dirtbags/$img:latest +done + +exit 0