Skip to content

Commit

Permalink
NOISSUE - add dockerfile and change makefile (#9)
Browse files Browse the repository at this point in the history
* add dockerfile

Signed-off-by: Mirko Teodorovic <[email protected]>

* Update dockerfile

Signed-off-by: Mirko Teodorovic <[email protected]>

* add makefile

Signed-off-by: Mirko Teodorovic <[email protected]>
  • Loading branch information
mteodor authored and drasko committed Jan 10, 2020
1 parent ac1b92d commit 00d08e5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
32 changes: 21 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -34,48 +34,58 @@ 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)

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)
$(MAKE) dockers
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
15 changes: 15 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit 00d08e5

Please sign in to comment.