Skip to content

Commit

Permalink
Go releaser (#238)
Browse files Browse the repository at this point in the history
* add goreleaser config

* update go.mod / gitignore

* dev/cross cleanup

* switch to cgo-less sqlite driver

* workflows

* fix build workflow

Co-authored-by: BuckarooBanzay <[email protected]>
  • Loading branch information
BuckarooBanzay and BuckarooBanzay authored Feb 1, 2022
1 parent e7b0b74 commit ddb5267
Show file tree
Hide file tree
Showing 22 changed files with 279 additions and 225 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: build

on:
push:
branches:
- 'master'
tags:
- 'v*'
pull_request:

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set up Go
uses: actions/[email protected]
with:
go-version: 1.16

- name: Set up nodejs
uses: actions/setup-node@v2
with:
node-version: '17'

- name: Create frontend bundle
run: cd public && npm ci && npm run bundle

- name: Cache Go modules
uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Tests
run: |
go mod tidy
go test -v ./...
- name: Docker Login
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
if: success() && startsWith(github.ref, 'refs/tags/')
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26 changes: 0 additions & 26 deletions .github/workflows/docker.yml

This file was deleted.

15 changes: 7 additions & 8 deletions .github/workflows/jshint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: apt
run: sudo apt-get install -y nodejs npm

- name: jshint install
run: sudo npm i -g jshint

- name: jshint run
run: cd public/js && jshint
- name: Set up nodejs
uses: actions/setup-node@v2
with:
node-version: '17'

- name: Run jshint
run: cd public && npm ci && npm run jshint
22 changes: 0 additions & 22 deletions .github/workflows/release.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mapserver
output
test-output

dist/
22 changes: 22 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
before:
hooks:
- go mod tidy
builds:
- env:
- CGO_ENABLED=0
targets:
- linux_amd64
- windows_amd64
- darwin_arm64
- linux_arm_6
ldflags:
- -s -w -X mapserver/app.Version={{.Version}}
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
dockers:
- image_templates: ["minetestmapserver/mapserver:{{ .Version }}"]
dockerfile: Dockerfile
22 changes: 3 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,4 @@
FROM golang:1.17.6-alpine as builder

RUN apk --no-cache add ca-certificates gcc libc-dev nodejs npm git make

VOLUME /root/go
COPY ./ /server
RUN cd /server &&\
npm install -g jshint rollup &&\
make test jshint all

FROM alpine:3.15.0
RUN apk --no-cache add ca-certificates curl
WORKDIR /app
COPY --from=builder /server/output/mapserver-linux-x86_64 /bin/mapserver

HEALTHCHECK --interval=5s --timeout=3s \
CMD curl -f http://localhost:8080/api/config || exit 1

FROM scratch
COPY mapserver /bin/mapserver
EXPOSE 8080
CMD ["/bin/mapserver"]
ENTRYPOINT ["/bin/mapserver"]
64 changes: 0 additions & 64 deletions Makefile

This file was deleted.

2 changes: 1 addition & 1 deletion db/sqlite/initialblocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"mapserver/layer"
"mapserver/settings"

_ "github.com/mattn/go-sqlite3"
_ "modernc.org/sqlite"
)

const (
Expand Down
6 changes: 3 additions & 3 deletions db/sqlite/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"mapserver/public"
"time"

_ "github.com/mattn/go-sqlite3"
"github.com/sirupsen/logrus"
_ "modernc.org/sqlite"
)

/*
Expand All @@ -24,7 +24,7 @@ type Sqlite3Accessor struct {
func (db *Sqlite3Accessor) Migrate() error {

//RW connection
rwdb, err := sql.Open("sqlite3", db.filename+"?mode=rw")
rwdb, err := sql.Open("sqlite", db.filename+"?mode=rw")
if err != nil {
return err
}
Expand Down Expand Up @@ -164,7 +164,7 @@ func (db *Sqlite3Accessor) GetBlock(pos *coords.MapBlockCoords) (*db.Block, erro
}

func New(filename string) (*Sqlite3Accessor, error) {
db, err := sql.Open("sqlite3", filename+"?mode=ro&_timeout=2000")
db, err := sql.Open("sqlite", filename+"?mode=ro&_timeout=2000")
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion db/sqlite/sqlite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"os"
"testing"

_ "github.com/mattn/go-sqlite3"
_ "modernc.org/sqlite"
)

func TestMigrateEmpty(t *testing.T) {
Expand Down
38 changes: 9 additions & 29 deletions doc/dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@

# Build dependencies

## Basic
* go >= 1.11
* make
* go >= 1.16
* nodejs >= v17.4.0
* npm >= 8.3.0

## With crosscompiling (optional)
Either apt-get:
* gcc-mingw-w64
* gcc-5-arm-linux-gnueabihf
* gcc-i686-linux-gnu
# Create the frontend bundle

Or use the docker-builder image in `/docker-builder`
```bash
cd public
npm ci
npm run bundle
```

# Development setup

Expand Down Expand Up @@ -56,23 +56,3 @@ pgsql_player_connection = host=localhost port=5432 user=postgres password=enter
* Change the value `webdev` in the `mapserver.json` to `true`
* Start the server with `go run .` or with debug output: `go run . -debug`
* The web files in `public/` can now be changed on the fly without restarting the server

# All platform build

Prerequisites:
* docker
* make

Building:
* Run `make clean all` to build for all supported targets

The artifacts should now be in the `output` directory

# Release build

Prerequisites:
* docker
* make

Building:
* Run `make all VERSION=X.Y.Z` in the root directory
18 changes: 0 additions & 18 deletions docker_builder/Dockerfile

This file was deleted.

4 changes: 0 additions & 4 deletions docker_builder/Makefile

This file was deleted.

12 changes: 0 additions & 12 deletions docker_builder/readme.md

This file was deleted.

4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ module mapserver
require (
github.com/gorilla/websocket v1.4.2
github.com/lib/pq v1.10.2
github.com/mattn/go-sqlite3 v1.14.8
github.com/minetest-go/mapparser v0.1.0 // indirect
github.com/minetest-go/mapparser v0.1.0
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/prometheus/client_golang v1.11.0
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/testify v1.7.0
github.com/yuin/gopher-lua v0.0.0-20210529063254-f4c35e4016d9
modernc.org/sqlite v1.14.5
)

go 1.16
Loading

0 comments on commit ddb5267

Please sign in to comment.