Permalink
Browse files

CI and releases

  • Loading branch information...
dunglas committed Oct 11, 2018
1 parent dfa3346 commit 92b15fe7d096dec9f1ee5d45f732026ac43e80bd
Showing with 154 additions and 48 deletions.
  1. +1 −0 .gitignore
  2. +34 −0 .goreleaser.yml
  3. +32 −0 .travis.yml
  4. +1 −9 Dockerfile
  5. +11 −4 README.md
  6. +11 −6 go.mod
  7. +41 −10 go.sum
  8. +23 −19 hub/server_test.go
View
@@ -1,3 +1,4 @@
/dist
/gin-bin
/mercure
/vendor
View
@@ -0,0 +1,34 @@
# This is an example goreleaser.yaml file with some sane defaults.
# Make sure to check the documentation at http://goreleaser.com
before:
hooks:
- go mod download
builds:
- env:
- CGO_ENABLED=0
archive:
replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
files:
- COPYRIGHT
- LICENSE
- README.md
- public/*
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
dockers:
- image: dunglas/mercure
extra_files:
- public/
View
@@ -0,0 +1,32 @@
language: go
go:
- '1.11'
env:
- GO111MODULE=on
services:
- docker
before_install:
- go get github.com/mattn/goveralls
install:
- go get
script:
- go vet
- gofmt -e -d *.go
- go build
- go test -coverprofile=profile.cov -timeout 30s ./...
- goveralls -coverprofile=profile.cov -service=travis-ci
after_success:
- test -n "$TRAVIS_TAG" && docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
deploy:
- provider: script
skip_cleanup: true
script: curl -sL https://git.io/goreleaser | bash
on:
tags: true
condition: $TRAVIS_OS_NAME = linux
View
@@ -1,13 +1,5 @@
FROM golang:1-alpine AS builder
WORKDIR /go/src/github.com/dunglas/mercure/
RUN apk --no-cache add git
COPY main.go .
COPY hub ./hub
RUN go get -d -v ./...
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o mercure .
FROM scratch
COPY mercure /
COPY public .
COPY --from=builder /go/src/github.com/dunglas/mercure/mercure .
CMD ["./mercure"]
EXPOSE 80 443
View
@@ -1,6 +1,11 @@
# Mercure, Server-Sent Live Updates
*Protocol and Reference Implementation*
[![GoDoc](https://godoc.org/github.com/dunglas/mercure?status.svg)](https://godoc.org/github.com/dunglas/mercure/hub)
[![Build Status](https://travis-ci.com/dunglas/mercure.svg?branch=master)](https://travis-ci.com/dunglas/mercure)
[![Coverage Status](https://coveralls.io/repos/github/dunglas/mercure/badge.svg?branch=master)](https://coveralls.io/github/dunglas/mercure?branch=master)
[![Go Report Card](https://goreportcard.com/badge/github.com/dunglas/mercure)](https://goreportcard.com/report/github.com/dunglas/mercure)
Mercure is a protocol allowing to push data updates to web browsers and other HTTP clients in a convenient, fast, reliable and battery-efficient way.
It is especially useful to publish real-time updates of resources served through web APIs, to reactive web and mobile apps.
@@ -9,6 +14,8 @@ The protocol has been published as an Internet Draft that [is maintained in this
A reference, production-grade, implementation of **a Mercure hub** (the server) is also available here.
It's a free software (AGPL) written in Go. It is provided along with a library that can be used in any Go application to implement the Mercure protocol directly (without a hub) and an official Docker image.
[Try the demo!](https://demo.mercure.rocks/)
In addition, a managed and high-scalability version of Mercure is [available in private beta](mailto:dunglas+mercure@gmail.com?subject=I%27m%20interested%20in%20Mercure%27s%20private%20beta).
## Mercure in a Few Words
@@ -134,9 +141,9 @@ A managed, high-scalability version of Mercure is available in private beta.
Grab a binary from the release page and run:
PUBLISHER_JWT_KEY=myPublisherKey SUBSCRIBER_JWT_KEY=mySubcriberKey ADDR=:3000 DEMO=1 ./mercure
PUBLISHER_JWT_KEY=myPublisherKey SUBSCRIBER_JWT_KEY=mySubcriberKey ADDR=:3000 DEMO=1 ALLOW_ANONYMOUS=1 ./mercure
The server is now available on `http://localhost:3000`, with the demo mode enabled.
The server is now available on `http://localhost:3000`, with the demo mode enabled. Because `ALLOW_ANONYMOUS` is set to `1`, anonymous subscribers are allowed.
To run it in production mode, and generate automatically a Let's Encrypt TLS certificate, just run the following command as root:
@@ -160,11 +167,11 @@ To compile the development version and register the demo page, see [CONTRIBUTING
A Docker image is available on Docker Hub. The following command is enough to get a working server in demo mode:
docker run \
-e PUBLISHER_JWT_KEY=myPublisherKey -e SUBSCRIBER_JWT_KEY=mySubcriberKey \
-e PUBLISHER_JWT_KEY=myPublisherKey -e SUBSCRIBER_JWT_KEY=mySubcriberKey -e DEMO=1 -e ALLOW_ANONYMOUS=1 \
-p 80:80 \
dunglas/mercure
The server, in demo mode, is available on `http://localhost:80`.
The server, in demo mode, is available on `http://localhost:80`. Anonymous subscribers are allowed.
In production, run:
View
17 go.mod

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
51 go.sum

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -8,17 +8,40 @@ import (
"strings"
"sync"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestServeAllOptions(t *testing.T) {
h := createAnonymousDummy()
h.options.Demo = true
h.options.CorsAllowedOrigins = []string{"*"}
h.Start()
go func() {
h.Serve()
}()
time.Sleep(time.Second) // Wait for the server to start
resp, _ := http.Get("http://" + testAddr + "/")
assert.Equal(t, "default-src 'self'", resp.Header.Get("Content-Security-Policy"))
assert.Equal(t, "nosniff", resp.Header.Get("X-Content-Type-Options"))
assert.Equal(t, "DENY", resp.Header.Get("X-Frame-Options"))
assert.Equal(t, "1; mode=block", resp.Header.Get("X-Xss-Protection"))
h.server.Shutdown(context.Background())
}
func TestServe(t *testing.T) {
h := createAnonymousDummy()
h.Start()
go func() {
h.Serve()
}()
time.Sleep(time.Second) // Wait for the server to start
var wg sync.WaitGroup
wg.Add(2)
@@ -70,22 +93,3 @@ func TestServe(t *testing.T) {
h.server.Shutdown(context.Background())
wg.Wait()
}
func TestServeAllOptions(t *testing.T) {
h := createAnonymousDummy()
h.options.Demo = true
h.options.CorsAllowedOrigins = []string{"*"}
h.Start()
go func() {
h.Serve()
}()
resp, _ := http.Get("http://" + testAddr + "/")
assert.Equal(t, "default-src 'self'", resp.Header.Get("Content-Security-Policy"))
assert.Equal(t, "nosniff", resp.Header.Get("X-Content-Type-Options"))
assert.Equal(t, "DENY", resp.Header.Get("X-Frame-Options"))
assert.Equal(t, "1; mode=block", resp.Header.Get("X-Xss-Protection"))
h.server.Shutdown(context.Background())
}

0 comments on commit 92b15fe

Please sign in to comment.