Skip to content

Commit

Permalink
Merge pull request #16 from ultreme/dev/moul/static-files
Browse files Browse the repository at this point in the history
switch to gRPC + support static files
  • Loading branch information
moul authored Jan 14, 2019
2 parents be86b55 + 029856d commit 42c41d1
Show file tree
Hide file tree
Showing 28 changed files with 13,173 additions and 701 deletions.
20 changes: 20 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: 2

jobs:
docker.build:
docker:
- image: docker:17.05.0-ce-git
steps:
- run: apk --no-cache add make
- checkout
- setup_remote_docker
- run: docker info
- run: make docker.build
- run: docker run -it --rm ultreme/calcbiz -h || true
# FIXME: save cache

workflows:
version: 2
commit:
jobs:
- docker.build
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
*~
*#
.#*
vendor/
vendor/
Dockerfile
Empty file added .generated
Empty file.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ services:
- docker

script:
- docker build -t camembertaulaitcrew/camembert-au-lait-crew .
- docker run -it --rm camembertaulaitcrew/camembert-au-lait-crew calc-www -h
- make docker.build
- docker run -it --rm ultreme/calcbiz -h || true
24 changes: 16 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
FROM golang:1.11
COPY go.* /go/src/ultre.me/calcbiz/
WORKDIR /go/src/ultre.me/calcbiz
RUN GO111MODULE=on go mod download
COPY . /go/src/ultre.me/calcbiz
RUN GO111MODULE=on go install -v ./cmd/calc-www
CMD ["calc-www", "server"]
EXPOSE 9000
FROM golang:1.11.4-alpine as builder
WORKDIR /go/src/ultre.me/calcbiz
RUN apk --no-cache --update add nodejs-npm make gcc g++ musl-dev openssl-dev git
RUN go get -u github.com/gobuffalo/packr/packr
ENV GO111MODULE=on
COPY go.* /go/src/ultre.me/calcbiz/
RUN go mod download
COPY . /go/src/ultre.me/calcbiz/
RUN make release

FROM alpine:3.8
RUN apk --no-cache --update add ca-certificates && update-ca-certificates
COPY --from=builder /go/bin/calcbiz /bin/calcbiz
ENTRYPOINT ["/bin/calcbiz"]
CMD ["server"]
EXPOSE 9000 9001
106 changes: 93 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,25 +1,105 @@
SOURCE := $(shell find . -name "*.go")
##
## functions
##

rwildcard = $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))

install:
go install ./cmd/calc-www
##
## vars
##

GOPATH ?= $(HOME)/go
BIN = $(GOPATH)/bin/calcbiz
SOURCES = $(call rwildcard, ./, *.go)
OUR_SOURCES = $(filter-out $(call rwildcard,vendor//,*.go),$(SOURCES))
PROTOS = $(call rwildcard, ./, *.proto)
OUR_PROTOS = $(filter-out $(call rwildcard,vendor//,*.proto),$(PROTOS))
GENERATED_FILES = \
$(patsubst %.proto,%.pb.go,$(PROTOS)) \
$(call rwildcard .//, *.gen.go) \
$(call rwildcard .//, *.pb.gw.go)
PROTOC_OPTS = -I/protobuf:vendor:.
RUN_OPTS ?=

run: up
##
## rules
##

up:
docker-compose up -d --force-recreate --remove-orphans
.PHONY: help
help:
@echo "Make commands:"
@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: \
'/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | \
sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | grep -v / | \
sed 's/^/ $(HELP_MSG_PREFIX)make /'

.PHONY: dev
dev: calc-www
calc-www server
.PHONY: run
run: $(BIN)
$(BIN) server $(RUN_OPTS)

.PHONY: install
install: $(BIN)
$(BIN): .generated $(OUR_SOURCES)
packr clean
go install -v .

.PHONY: docker
docker:
docker build -t ultreme/calcbiz .
.PHONY: release
release:
packr
go install -v .

.PHONY: clean
clean:
rm -f $(GENERATED_FILES) .generated
packr clean

.PHONY: _ci_prepare
_ci_prepare:
touch $(OUR_PROTOS) $(GENERATED_FILES)
sleep 1
touch .generated

.PHONY: generate
generate: .generated
.generated: $(OUR_PROTOS)
rm -f $(GENERATED_FILES)
go mod vendor
docker run \
--user="$(shell id -u)" \
--volume="$(PWD):/go/src/ultre.me/calcbiz" \
--workdir="/go/src/ultre.me/calcbiz" \
--entrypoint="sh" \
--rm \
pathwar/protoc:v1 \
-xec "make _generate"
touch $@

.PHONY: _generate
_generate: $(GENERATED_FILES)

.PHONY: test
test:
test: .generated
go test -v ./...

%.pb.go: %.proto
protoc \
$(PROTOC_OPTS) \
--grpc-gateway_out=logtostderr=true:"$(GOPATH)/src" \
--gogofaster_out=plugins=grpc:"$(GOPATH)/src" \
"$(dir $<)"/*.proto

.PHONY: lint
lint:
golangci-lint run --verbose ./...

##
## production
##

.PHONY: docker.up
docker.up:
docker-compose up -d --force-recreate --remove-orphans

.PHONY: docker.build
docker.build:
docker build -t ultreme/calcbiz .
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# camembert-au-lait-crew
# calcbiz - Camembert au lait crew's website
:hamburger: Camembert au lait crew website &amp; API

---

Live: https://www.camembertaulaitcrew.biz
Install/Dev: `go get ultre.me/calcbiz`
Loading

0 comments on commit 42c41d1

Please sign in to comment.