diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..cc9d25f --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +/.github/ + +Dockerfile* +docker-compose*.yml + +/.data/ +/secret.key + +/rogueserver* +!/rogueserver.go diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..a71cad6 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,46 @@ +name: Build + +on: + push: + pull_request: + +jobs: + build: + name: Build (${{ matrix.os_name }}) + env: + GO_VERSION: 1.22 + GOOS: ${{ matrix.os_name }} + GOARCH: ${{ matrix.arch }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-latest + os_name: linux + arch: amd64 + - os: windows-latest + os_name: windows + arch: amd64 +# TODO macos needs universal binary! +# - os: macos-latest +# os_name: macos + steps: + - uses: actions/checkout@v4 + - name: Set up Go ${{ env.GO_VERSION }} + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + - name: Install dependencies + run: go mod download + - name: Test + run: go test -v + - name: Build + run: go build -v + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: rogueserver-${{ matrix.os_name }}-${{ matrix.arch }}-${{ github.sha }} + path: | + rogueserver* + !rogueserver.go diff --git a/.github/workflows/ghcr.yml b/.github/workflows/ghcr.yml new file mode 100644 index 0000000..6b7eb3d --- /dev/null +++ b/.github/workflows/ghcr.yml @@ -0,0 +1,38 @@ +name: Publish to GHCR + +on: + push: + +jobs: + build: + name: Build and publish to GHCR + if: github.repository == 'pagefaultgames/rogueserver' + env: + GO_VERSION: 1.22 + runs-on: ubuntu-latest + steps: + - name: Setup Docker BuildX + uses: docker/setup-buildx-action@v2 + - name: Log into container registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ github.token }} + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.repository }} + - name: Build Docker image + uses: docker/build-push-action@v5 + with: + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + build-args: | + GO_VERSION=${{ env.GO_VERSION }} + VERSION=${{ github.ref_name }}-SNAPSHOT + COMMIT_SHA=${{ env.GITHUB_SHA_SHORT }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8a07093 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +ARG GO_VERSION=1.22 + +FROM golang:${GO_VERSION} AS builder + +WORKDIR /src + +COPY ./go.mod /src/ +COPY ./go.sum /src/ + +RUN go mod download && go mod verify + +COPY . /src/ + +RUN CGO_ENABLED=0 \ + go build -o rogueserver + +RUN chmod +x /src/rogueserver + +# --------------------------------------------- + +FROM scratch + +WORKDIR /app + +COPY --from=builder /src/rogueserver . + +EXPOSE 8001 + +ENTRYPOINT ["./rogueserver"] diff --git a/docker-compose.Example.yml b/docker-compose.Example.yml new file mode 100644 index 0000000..b377d71 --- /dev/null +++ b/docker-compose.Example.yml @@ -0,0 +1,27 @@ +services: + server: + image: ghcr.io/pagefaultgames/pokerogue:latest + command: --debug --dbaddr db:3306 --dbuser pokerogue --dbpass pokerogue --dbname pokeroguedb + restart: unless-stopped + depends_on: + - db + networks: + - internal + ports: + - "8001:8001" + db: + image: mariadb:11 + restart: unless-stopped + environment: + MYSQL_ROOT_PASSWORD: admin + MYSQL_DATABASE: pokeroguedb + MYSQL_USER: pokerogue + MYSQL_PASSWORD: pokerogue + volumes: + - database:/var/lib/mysql + +volumes: + database: + +networks: + internal: