Skip to content

Commit

Permalink
add docker files
Browse files Browse the repository at this point in the history
update readme

Signed-off-by: SammyOina <[email protected]>
  • Loading branch information
SammyOina committed Aug 23, 2023
1 parent 66947e9 commit c60987d
Show file tree
Hide file tree
Showing 16 changed files with 221 additions and 81 deletions.
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work

/build

*.cov

*.BIN
45 changes: 43 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,56 @@
# Copyright (c) Mainflux
# SPDX-License-Identifier: Apache-2.0

PROGRAM = mproxy
PROGRAM = aproxy
MF_DOCKER_IMAGE_NAME_PREFIX ?= amdm
SOURCES = $(wildcard *.go) cmd/main.go
CGO_ENABLED ?= 0
GOARCH ?= amd64
VERSION ?= $(shell git describe --abbrev=0 --tags 2>/dev/null || echo "0.13.0")
COMMIT ?= $(shell git rev-parse HEAD)
TIME ?= $(shell date +%F_%T)

all: $(PROGRAM)

.PHONY: all clean $(PROGRAM)

define make_docker
docker build \
--no-cache \
--build-arg SVC=$(PROGRAM) \
--build-arg GOARCH=$(GOARCH) \
--build-arg GOARM=$(GOARM) \
--build-arg VERSION=$(VERSION) \
--build-arg COMMIT=$(COMMIT) \
--build-arg TIME=$(TIME) \
--tag=$(MF_DOCKER_IMAGE_NAME_PREFIX)/$(PROGRAM) \
-f docker/Dockerfile .
endef

define make_docker_dev
docker build \
--no-cache \
--build-arg SVC=$(PROGRAM) \
--tag=$(MF_DOCKER_IMAGE_NAME_PREFIX)/$(PROGRAM) \
-f docker/Dockerfile.dev ./build
endef

$(PROGRAM): $(SOURCES)
go build -ldflags "-s -w" -o ./build/$@ cmd/main.go
CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) GOARCH=$(GOARCH) GOARM=$(GOARM) \
go build -mod=vendor -ldflags "-s -w \
-X 'github.com/mainflux/mainflux.BuildTime=$(TIME)' \
-X 'github.com/mainflux/mainflux.Version=$(VERSION)' \
-X 'github.com/mainflux/mainflux.Commit=$(COMMIT)'" \
-o ./build/$(MF_DOCKER_IMAGE_NAME_PREFIX)-$(PROGRAM) cmd/main.go

clean:
rm -rf $(PROGRAM)

docker-image:
$(call make_docker)
docker-dev:
$(call make_docker_dev)

run:
docker compose -f ./docker/docker-compose.yml up

3 changes: 3 additions & 0 deletions docker/.env
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ MF_MQTT_ADAPTER_ES_PASS=
MF_MQTT_ADAPTER_INSTANCE_ID=
MF_MQTT_ADAPTER_ES_DB=0
MF_MQTT_ADAPTER_CONFIG_FILE="config.toml"

# Docker image tag
MF_RELEASE_TAG=latest
20 changes: 20 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM golang:1.21.0-alpine AS builder
ARG SVC
ARG GOARCH
ARG GOARM
ARG VERSION
ARG COMMIT
ARG TIME

WORKDIR /go/src/github.com/absmach/aproxy
COPY . .
RUN apk update \
&& apk add make\
&& make $SVC \
&& mv build/amdm-$SVC /exe

FROM scratch
# Certificates are needed so that mailing util can work.
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=builder /exe /
ENTRYPOINT ["/exe"]
5 changes: 5 additions & 0 deletions docker/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM scratch
ARG SVC
COPY amdm-$SVC /exe
COPY --from=alpine:latest /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
ENTRYPOINT ["/exe"]
8 changes: 0 additions & 8 deletions docker/brokers/nats.yml

This file was deleted.

11 changes: 0 additions & 11 deletions docker/brokers/rabbitmq.yml

This file was deleted.

14 changes: 1 addition & 13 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ version: "3.7"

networks:
mainflux-base-net:
driver: bridge
external: true

services:
mqtt-adapter:
image: mainflux/mqtt:${MF_RELEASE_TAG}
image: amdm/aproxy:${MF_RELEASE_TAG}
container_name: mainflux-mqtt
restart: on-failure
environment:
Expand Down Expand Up @@ -35,13 +33,3 @@ services:
MF_SEND_TELEMETRY: ${MF_SEND_TELEMETRY}
networks:
- mainflux-base-net
broker:
extends:
file: brokers/nats.yml
service: broker
container_name: mainflux-broker
restart: on-failure
networks:
- mainflux-base-net
ports:
- 4222:4222
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/cenkalti/backoff/v4 v4.2.1
github.com/mainflux/callhome v0.0.0-20230626140149-b03b1f4c46f2
github.com/mainflux/mainflux v0.12.0
github.com/mainflux/mproxy v0.3.0
github.com/mainflux/mproxy v0.3.1-0.20230822124450-4b4dfe600cc2
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.42.0
golang.org/x/sync v0.3.0
google.golang.org/grpc v1.56.1
Expand Down Expand Up @@ -64,4 +64,4 @@ require (
google.golang.org/protobuf v1.31.0 // indirect
)

replace github.com/mainflux/mainflux => github.com/mainflux/mainflux v0.0.0-20230811131717-9dbe87f03a1a
replace github.com/mainflux/mainflux => github.com/mainflux/mainflux v0.0.0-20230823124803-822a607e31fe
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw=
github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/mainflux/callhome v0.0.0-20230626140149-b03b1f4c46f2 h1:QN+yhU6Twwwwz8Mu9u12f2TbPsmM/zIvndAhH1dIdWU=
github.com/mainflux/callhome v0.0.0-20230626140149-b03b1f4c46f2/go.mod h1:q4cTH8I3Y6kDyocJh5dBppuv4dY9drb/2kVdB6FP124=
github.com/mainflux/mainflux v0.0.0-20230811131717-9dbe87f03a1a h1:y4dbYC2XQKAhJ3Q8sGJe0WzDL8tADh7H0P15CSsyIzg=
github.com/mainflux/mainflux v0.0.0-20230811131717-9dbe87f03a1a/go.mod h1:N1M7LhMt/mvgjn0Z5m2kRfJir6aTv0mDOJZPNKVcacI=
github.com/mainflux/mproxy v0.3.0 h1:tU60nu/Bd5lWb7NlJJvW6ulKxeBGJFnp5uOS9j6JXBQ=
github.com/mainflux/mproxy v0.3.0/go.mod h1:nG9MP2YbS8ax26Z8mvJOYohhi3ebYwSlOmePzbfv2ew=
github.com/mainflux/mainflux v0.0.0-20230823124803-822a607e31fe h1:galNZWS6B/O0TM8ByATkpXgTTO18lpOmjmxZ9y0kNXg=
github.com/mainflux/mainflux v0.0.0-20230823124803-822a607e31fe/go.mod h1:cHi+VUm+VST3OaROF0W34pqtr7DHOhrjJ3PDNBTI5W4=
github.com/mainflux/mproxy v0.3.1-0.20230822124450-4b4dfe600cc2 h1:D5Ofrffx/4FWehczvJbmzD8lfcOkxcIS4XZE/fwl4mo=
github.com/mainflux/mproxy v0.3.1-0.20230822124450-4b4dfe600cc2/go.mod h1:nG9MP2YbS8ax26Z8mvJOYohhi3ebYwSlOmePzbfv2ew=
github.com/markbates/errx v1.1.0 h1:QDFeR+UP95dO12JgW+tgi2UVfo0V8YBHiUIOaeBPiEI=
github.com/markbates/errx v1.1.0/go.mod h1:PLa46Oex9KNbVDZhKel8v1OT7hD5JZ2eI7AHhA0wswc=
github.com/markbates/oncer v1.0.0 h1:E83IaVAHygyndzPimgUYJjbshhDTALZyXxvk9FOlQRY=
Expand Down
82 changes: 77 additions & 5 deletions vendor/github.com/mainflux/mainflux/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c60987d

Please sign in to comment.