add GitHub actions scripts and dockerfile

This commit is contained in:
Up 2024-05-09 11:24:07 +02:00
parent ae23b18f9c
commit bd1e324bbd
No known key found for this signature in database
GPG Key ID: 3B75CD7439FEB388
4 changed files with 117 additions and 0 deletions

10
.dockerignore Normal file
View File

@ -0,0 +1,10 @@
/.github/
Dockerfile*
docker-compose*.yml
/.data/
/secret.key
/rogueserver*
!/rogueserver.go

42
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,42 @@
name: Build
on:
push:
pull_request:
jobs:
build:
name: Build (${{ matrix.os_name }})
env:
GO_VERSION: 1.22
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
os_name: linux
- os: windows-latest
os_name: windows
- 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 }}-${{ github.sha }}
path: |
rogueserver*
!rogueserver.go

36
.github/workflows/ghcr.yml vendored Normal file
View File

@ -0,0 +1,36 @@
name: Publish to GHCR
on:
push:
jobs:
build:
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 }}

29
Dockerfile Normal file
View File

@ -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"]