Skip to content

Commit

Permalink
Merge pull request #62 from jfontan/go
Browse files Browse the repository at this point in the history
New Go server with moderation
  • Loading branch information
jfontan authored Jul 27, 2021
2 parents 176283a + 1f49eeb commit 77fff9b
Show file tree
Hide file tree
Showing 27 changed files with 2,512 additions and 368 deletions.
93 changes: 93 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: glslsandbox

on:
push:
branches:
- master
pull_request:
branches:
- master
release:
types:
- created

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

permissions:
contents: write

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v1
with:
go-version: 1.16.x

- name: Checkout code
uses: actions/checkout@v2

- name: Test
run: go test ./...

docker:
if: github.event_name == 'release' && github.event.action == 'created'
needs: test

runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

binaries:
if: github.event_name == 'release' && github.event.action == 'created'
needs: test

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

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
distribution: goreleaser
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33 changes: 33 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This is an example .goreleaser.yml file with some sane defaults.
# Make sure to check the documentation at http://goreleaser.com
before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
- go generate ./...
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
main: ./server/cmd/glslsandbox
archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM golang:1.16 AS builder

ENV GOPATH /go
RUN apt-get update && \
apt-get install -y libsqlite3-0 libsqlite3-dev

WORKDIR /build
COPY . .

RUN go build -v ./server/cmd/glslsandbox

FROM debian:buster-slim

RUN apt-get update && \
apt-get install -y --no-install-recommends ca-certificates && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

EXPOSE 8888
EXPOSE 8883
COPY --from=builder /build/ /glslsandbox/
ENTRYPOINT [ "/glslsandbox/entrypoint.sh" ]
8 changes: 0 additions & 8 deletions Gemfile

This file was deleted.

49 changes: 0 additions & 49 deletions Gemfile.lock

This file was deleted.

110 changes: 110 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# glsl-sandbox

## Server development

### Setup

* Fork repository
* Download repository and create new development branch:

```
$ git clone [email protected]:<your user>/glsl-sandbox
$ cd glsl-sandbox
$ git checkout -b <feature name> go
```

* Download and uncompress test data:

```
$ curl -O https://downloads.zooloo.org/glslsandbox-data.tar.gz
$ tar xvf glslsandbox-data.tar.gz
```

* Build server binary needs go compiler:

```
$ go build ./server/cmd/glslsandbox
```

* Alternatively you can download and uncompress the binary in the repository directory from https://github.com/jfontan/glsl-sandbox/releases/latest

* Run server:

```
$ ./glslsandbox
```

* The first time it starts it creates an admin user and the credentials are printed.

* The server should be accessible on http://localhost:8888

* Admin interface is on http://localhost:8888/admin

### Template and javascript modifications

The server reloads templates and assets on each query. This eases the development as you can modify the files and changes will take effect reloading the page.

There's only one template that is used for both the gallery (index) and admin page. The file is `server/assets/gallery.html` and uses go language templates. You can find more information about its syntax here:

* https://gohugo.io/templates/introduction/
* https://pkg.go.dev/text/template
* https://pkg.go.dev/html/template

Currently the page receives this data:

```go
// galleryEffect has information about each effect displayed in the gallery.
type galleryEffect struct {
// ID is the effect identifyier.
ID int
// Version is the latest effect version.
Version int
// Image holds the thumbnail name.
Image string
// Hidden tells if the effect has been moderated.
Hidden bool
}

// galleryData has information about the current gallery page.
type galleryData struct {
// Effects is an array with all the effects for the page.
Effects []galleryEffect
// URL is the path of the gallery. Can be "/" or "/admin".
URL string
// Page holds the current page number.
Page int
// IsPrevious is true if there is a previous page.
IsPrevious bool
// PreviousPage is the previous page number.
PreviousPage int
// IsNext is true if there is a next page.
IsNext bool
// NextPage is the next page number.
NextPage int
// Admin is true when accessing "/admin" path.
Admin bool
}
```

This is, `galleryData` for the page and `galleryEffect` for each effect. For example, to print all the effect IDs you can use:

```html
<ul>
{{ range .Effects }}
<li>{{ .ID }}</li>
{{ end }}
<ul>
```

The following directories are accessible from the server and can be modified if needed:

* `server/assets/css` -> `/css`
* `server/assets/js` -> `/js`

By default the data files are read from `./data`. This path can be hanged with the environment variable `DATA_PATH`. For example:

```
$ DATA_PATH=/my/data/directory ./glslsandbox
```

The data directory contains the sqlite database (`glslsandbox.db`) and the thumbnails (`thumbs` directory).
6 changes: 0 additions & 6 deletions config.ru

This file was deleted.

8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: "3.9"
services:
glslsandbox:
image: ghcr.io/jfontan/glsl-sandbox:latest
volumes:
- ./data:/data
ports:
- "3000:8888"
6 changes: 6 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

cd glslsandbox
export DEV ADDR AUTH_SECRET IMPORT
export TLS_ADDR DOMAINS
DATA_PATH=/data ./glslsandbox
19 changes: 19 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module github.com/mrdoob/glsl-sandbox

go 1.16

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang-jwt/jwt v3.2.1+incompatible
github.com/jmoiron/sqlx v1.3.4
github.com/kelseyhightower/envconfig v1.4.0
github.com/kr/text v0.2.0 // indirect
github.com/labstack/echo/v4 v4.3.0
github.com/labstack/gommon v0.3.0
github.com/mattn/go-sqlite3 v1.14.7 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/stretchr/testify v1.7.0
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
modernc.org/sqlite v1.11.2
)
Loading

0 comments on commit 77fff9b

Please sign in to comment.