diff --git a/.gitignore b/.gitignore index 2241fc0..7dbb826 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ gin-bin config.yml .idea/ -/bin/ -mg-telegram \ No newline at end of file +/bin/* +mg-telegram diff --git a/Dockerfile b/Dockerfile index 3694bfa..940fb3b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,9 @@ -FROM golang:1.9.3-stretch as ca-certs -FROM scratch - -COPY --from=ca-certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt +FROM golang:1.9.3-stretch WORKDIR / +ADD ./bin/mg-telegram / +ADD ./templates/ /templates/ EXPOSE 3001 -ENTRYPOINT ["/mg-telegram", "--config", "/config.yml"] - -CMD ["run"] +ENTRYPOINT ["/mg-telegram", "run"] diff --git a/Makefile b/Makefile index a1e4a0f..ae2acb7 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,9 @@ ROOT_DIR=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) SRC_DIR=$(ROOT_DIR) +MIGRATIONS_DIR=$(ROOT_DIR)/migrations CONFIG_FILE=$(ROOT_DIR)/config.yml CONFIG_TEST_FILE=$(ROOT_DIR)/config_test.yml -BIN=$(ROOT_DIR)/mg-telegram +BIN=$(ROOT_DIR)/bin/mg-telegram REVISION=$(shell git describe --tags 2>/dev/null || git log --format="v0.0-%h" -n 1 || echo "v0.0-unknown") ifndef GOPATH @@ -11,25 +12,31 @@ endif export GOPATH := $(GOPATH):$(ROOT_DIR) +build: deps fmt + @echo "==> Building" + @go build -o $(BIN) -ldflags "-X common.build=${REVISION}" . + @echo $(BIN) + +run: migrate + @echo "==> Running" + @${BIN} --config $(CONFIG_FILE) run + fmt: @echo "==> Running gofmt" @gofmt -l -s -w $(SRC_DIR) -install: fmt - @echo "==> Running go get" +deps: + @echo "==> Installing dependencies" $(eval DEPS:=$(shell cd $(SRC_DIR) \ && go list -f '{{join .Imports "\n"}}{{ "\n" }}{{join .TestImports "\n"}}' ./... \ | sort | uniq | tr '\r' '\n' | paste -sd ' ' -)) @go get -d -v $(DEPS) -build: install - @echo "==> Building" - @go build -o $(BIN) -ldflags "-X common.build=${REVISION}" . - @echo $(BIN) - migrate: build @${BIN} --config $(CONFIG_FILE) migrate -p ./migrations/ -run: migrate - @echo "==> Running" - @${BIN} --config $(CONFIG_FILE) run \ No newline at end of file +migrate_test: build + @${BIN} --config $(CONFIG_TEST_FILE) migrate + +migrate_down: build + @${BIN} --config $(CONFIG_FILE) migrate -v down diff --git a/docker-compose-prebuild.yml b/docker-compose-prebuild.yml new file mode 100644 index 0000000..38b7a69 --- /dev/null +++ b/docker-compose-prebuild.yml @@ -0,0 +1,35 @@ +version: '2.1' + +services: + postgres: + image: postgres:9.6 + environment: + POSTGRES_USER: mg_telegram + POSTGRES_PASSWORD: mg_telegram + POSTGRES_DATABASE: mg_telegram + ports: + - ${POSTGRES_ADDRESS:-127.0.0.1:5434}:5432 + + mg_migrate: + image: golang:1.9.3-stretch + working_dir: /mg_telegram_migrate + user: ${UID:-1000}:${GID:-1000} + volumes: + - ./:/mg_telegram_migrate/ + links: + - postgres + depends_on: + - postgres + command: make migrate + + mg_telegram: + image: hub.retailcrm.pro/message-gateway/transport-telegram:latest + restart: always + volumes: + - ./config.yml:/config.yml + ports: + - ${MG_TELEGRAM_ADDRESS:-3001}:3001 + links: + - postgres + depends_on: + - mg_migrate