diff --git a/Makefile b/Makefile index 06d02ba5..eb555c7a 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ SERVICES = agent DOCKERS = $(addprefix docker_,$(SERVICES)) DOCKERS_DEV = $(addprefix docker_dev_,$(SERVICES)) CGO_ENABLED ?= 0 -GOOS ?= linux +GOARCH ?= amd64 define compile_service CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) GOARCH=$(GOARCH) GOARM=$(GOARM) go build -ldflags "-s -w" -o ${BUILD_DIR}/mainflux-$(1) cmd/main.go @@ -34,12 +34,13 @@ define make_docker_dev -f docker/Dockerfile.dev ./build endef -all: $(SERVICES) ui +all: $(SERVICES) -.PHONY: all $(SERVICES) dockers dockers_dev +.PHONY: all $(SERVICES) dockers dockers_dev latest release clean: rm -rf ${BUILD_DIR} + install: cp ${BUILD_DIR}/* $(GOBIN) @@ -47,23 +48,33 @@ install: test: go test -v -race -count 1 -tags test $(shell go list ./... | grep -v 'vendor\|cmd') + $(SERVICES): $(call compile_service,$(@)) -docker_ui: - $(MAKE) -C ui docker +$(DOCKERS): + $(call make_docker,$(@),$(GOARCH)) + +$(DOCKERS_DEV): + $(call make_docker_dev,$(@)) -dockers: $(DOCKERS) docker_ui +dockers: $(DOCKERS) dockers_dev: $(DOCKERS_DEV) + define docker_push for svc in $(SERVICES); do \ docker push mainflux/$$svc:$(1); \ done - docker push mainflux/mqtt:$(1) endef +changelog: + git log $(shell git describe --tags --abbrev=0)..HEAD --pretty=format:"- %s" + +latest: dockers + $(call docker_push,latest) + release: $(eval version = $(shell git describe --abbrev=0 --tags)) git checkout $(version) @@ -71,11 +82,10 @@ release: for svc in $(SERVICES); do \ docker tag mainflux/$$svc mainflux/$$svc:$(version); \ done - docker tag mainflux/agent-ui mainflux/agent-ui:$(version) $(call docker_push,$(version)) -ui: - $(MAKE) -C ui +rundev: + cd scripts && ./run.sh run: - cd $(BUILD_DIR) && ./mainflux-$(SERVICES) + docker-compose -f docker/docker-compose.yml up diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 00000000..4ef7a9ac --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,15 @@ +FROM golang:1.13-alpine AS builder +ARG SVC +ARG GOARCH +ARG GOARM + +WORKDIR /go/src/github.com/mainflux/agent +COPY . . +RUN apk update \ + && apk add make\ + && make $SVC \ + && mv build/mainflux-$SVC /exe + +FROM scratch +COPY --from=builder /exe / +ENTRYPOINT ["/exe"]