Skip to content

Commit

Permalink
Add Docker/release mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Apr 5, 2020
1 parent d56db5b commit ef2073a
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 7 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: goreleaser
on:
# Trigger the workflow on push or pull request,
# but only if a semver tag is created.
push:
tags:
- v*.*.*
jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v1
-
name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.14.x
-
name: Login to DockerHub Registry
run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
-
name: Run goreleaser
uses: goreleaser/goreleaser-action@v1
with:
version: latest
args: release --rm-dist --skip-validate
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39 changes: 39 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
env:
- GO111MODULE=on
- CGO_ENABLED=0
- RELEASE_BUILDS=dist/niltalk_darwin_amd64/niltalk dist/niltalk_linux_amd64/niltalk dist/niltalk_windows_amd64/niltalk.exe

builds:
- binary: niltalk
goos:
- linux
- darwin
- windows
goarch:
- amd64
ldflags:
- -s -w -X "main.buildString={{ .Tag }} ({{ .ShortCommit }} {{ .Date }})"
hooks:
# stuff binaries with static assets.
post: make pack-releases

archives:
- format: tar.gz
files:
- README.md
- LICENSE

dockers:
-
goos: linux
goarch: amd64
goarm: ''
binaries:
- niltalk
image_templates:
- "kailashnadh/niltalk:latest"
- "kailashnadh/niltalk:{{ .Tag }}"
skip_push: false
dockerfile: Dockerfile
extra_files:
- config.toml.sample
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM alpine:latest AS deploy
WORKDIR /niltalk
COPY niltalk .
COPY config.toml.sample config.toml
ENTRYPOINT [ "./niltalk" ]
21 changes: 17 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,36 @@ BUILDSTR := ${VERSION} (${LAST_COMMIT} $(shell date -u +"%Y-%m-%dT%H:%M:%S%z"))
BIN := niltalk
STATIC := static/templates static/static:/static config.toml.sample

.PHONY: deps
deps:
go get -u github.com/knadh/stuffbin/...

.PHONY: build
build:
go build -o ${BIN} -ldflags="-s -w -X 'main.buildString=${BUILDSTR}'"
stuffbin -a stuff -in ${BIN} -out ${BIN} ${STATIC}

.PHONY: run
run: build
./${BIN}

.PHONY: deps
deps:
go get -u github.com/knadh/stuffbin/...
.PHONY: dist
dist: build
# If dependencies are not installed, install.
@type stuffbin >/dev/null 2>&1 || make deps
stuffbin -a stuff -in ${BIN} -out ${BIN} ${STATIC}

# pack-releases runns stuffbin packing on a given list of
# binaries. This is used with goreleaser for packing
# release builds for cross-build targets.
.PHONY: pack-releases
pack-releases:
$(foreach var,$(RELEASE_BUILDS),stuffbin -a stuff -in ${var} -out ${var} ${STATIC} $(var);)

.PHONY: test
test:
go test

.PHONE: clean
clean:
go clean
- rm -f ${BIN}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ Niltalk requires a Redis instance to persist room and session states.
- Run `./niltalk` and visit http://localhost:9000.

### Docker
TODO
The official Docker image `niltalk:latest` is [available here](https://hub.docker.com/r/kailashnadh/niltalk). To try out the app, copy [docker-compose.yml](docker-compose.yml) and run `docker-compose run niltalk`.

### Customisation
The static HTML/JS/CSS assets can be customized. Copy the `static` directory from the repository, change the files, and invoke like `./niltalk --static-dir=/path/to/custom/static`
The static HTML/JS/CSS assets can be customized. Copy the `static` directory from the repository, change the files, and do: `./niltalk --static-dir=/path/to/custom/static`

> This is a complete rewrite of the old version that had been dead and obsolete for several years (can be found in the `old` branch). These codebases are not compatible with each other and `master` has been overwritten.
Expand Down
2 changes: 1 addition & 1 deletion config.toml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ session_cookie = "niltoken"
# Redis cache server.
# Rooms are cached until they expires. Messages are not cached.
[store]
address = "127.0.0.1:6379"
address = "redis:6379" # Eg: 127.0.0.1:6379
password = ""
db = 0
active_conns = 100
Expand Down
30 changes: 30 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# NOTE: This docker-compose.yml is meant to be just an example guideline
# on how you can achieve the same. It is not intented to run out of the box
# and you must edit the below configurations to suit your needs.

version: "3.7"

services:
redis:
image: redis:alpine
networks:
- niltalk
volumes:
- niltalk-data
restart: unless-stopped

niltalk:
image: kailashnadh/niltalk:latest
ports:
- "9000:9000"
networks:
- niltalk
depends_on:
- redis
restart: unless-stopped

networks:
niltalk:

volumes:
niltalk-data:

0 comments on commit ef2073a

Please sign in to comment.