diff --git a/.gitignore b/.gitignore index 7dbb826..e636d91 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ -gin-bin config.yml +config_test.yml .idea/ /bin/* -mg-telegram +*.xml \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 0eafdc1..4f24cb4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM golang:1.9.3-stretch WORKDIR / -ADD ./bin/mg-telegram / +ADD ./bin/transport / ADD ./templates/ /templates/ ADD ./static/ /static/ ADD ./translate/ /translate/ @@ -9,6 +9,6 @@ ADD ./migrations/ /migrations/ EXPOSE 3001 -ENTRYPOINT ["/mg-telegram"] +ENTRYPOINT ["/transport"] CMD ["run"] diff --git a/Jenkinsfile b/Jenkinsfile index 6540574..8d4862e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -15,7 +15,7 @@ pipeline { stages { stage('Prepare') { steps { - sh 'cp config_test.yml.dist config.yml' + sh 'cp config_test.yml.dist config_test.yml' compose 'up -d --build postgres_test' compose 'run --rm mg_telegram_test make migrate_test' } @@ -23,7 +23,7 @@ pipeline { stage('Tests') { steps { - compose 'run --rm --no-deps mg_telegram_test make jenkins_test' + compose 'run --rm mg_telegram_test make jenkins_test' } post { diff --git a/Makefile b/Makefile index e166e68..8f47b24 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ 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)/bin/mg-telegram +BIN=$(ROOT_DIR)/bin/transport REVISION=$(shell git describe --tags 2>/dev/null || git log --format="v0.0-%h" -n 1 || echo "v0.0-unknown") ifndef GOPATH @@ -22,9 +22,8 @@ run: migrate @${BIN} --config $(CONFIG_FILE) run test: deps fmt - @echo "==> Running tests (result in test-report.xml)" - @go get -v -u github.com/jstemmer/go-junit-report - @cd $(SRC_DIR) && go test ./... -v -cpu 2 -cover -race | go-junit-report -set-exit-code > $(SRC_DIR)/test-report.xml + @echo "==> Running tests" + @cd $(SRC_DIR) && go test ./... -v -cpu 2 jenkins_test: deps @echo "==> Running tests (result in test-report.xml)" @@ -43,10 +42,10 @@ deps: @go get -d -v $(DEPS) migrate: build - @${BIN} --config $(CONFIG_FILE) migrate -p ./migrations/ + ${BIN} --config $(CONFIG_FILE) migrate -p $(MIGRATIONS_DIR) migrate_test: build - @${BIN} --config $(CONFIG_TEST_FILE) migrate ./migrations/ + @${BIN} --config $(CONFIG_TEST_FILE) migrate -p $(MIGRATIONS_DIR) migrate_down: build @${BIN} --config $(CONFIG_FILE) migrate -v down diff --git a/config_test.yml.dist b/config_test.yml.dist index db022a0..1132bce 100644 --- a/config_test.yml.dist +++ b/config_test.yml.dist @@ -1,5 +1,5 @@ database: - connection: postgres://mg_telegram_test:mg_telegram_test@postgres_test:5450/mg_telegram_test?sslmode=disable + connection: postgres://mg_telegram_test:mg_telegram_test@postgres_test:5432/mg_telegram_test?sslmode=disable http_server: host: ~ diff --git a/docker-compose-test.yml b/docker-compose-test.yml index cba0c50..7233b5c 100644 --- a/docker-compose-test.yml +++ b/docker-compose-test.yml @@ -8,16 +8,17 @@ services: POSTGRES_PASSWORD: mg_telegram_test POSTGRES_DATABASE: mg_telegram_test ports: - - ${POSTGRES_ADDRESS:-127.0.0.1:5450}:${POSTGRES_PORT:-5450} + - ${POSTGRES_ADDRESS:-127.0.0.1:5434}:${POSTGRES_PORT:-5432} mg_telegram_test: image: golang:1.9.3-stretch - working_dir: /mg_telegram + working_dir: /mgtg user: ${UID:-1000}:${GID:-1000} volumes: - - ./:/mg_telegram/ + - ./:/mgtg/ + - ./static:/static/ links: - postgres_test ports: - ${MG_TELEGRAM_ADDRESS:-3002}:3002 - command: make migrate_test +# command: make migrate_test diff --git a/docker-compose.yml b/docker-compose.yml index bbe9880..2ebc45e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,14 +8,14 @@ services: POSTGRES_PASSWORD: mg_telegram POSTGRES_DATABASE: mg_telegram ports: - - ${POSTGRES_ADDRESS:-127.0.0.1:5434}:5432 + - ${POSTGRES_ADDRESS:-127.0.0.1:5434}:${POSTGRES_PORT:-5432} mg_telegram: image: golang:1.9.3-stretch - working_dir: /mg_telegram + working_dir: /mgtg user: ${UID:-1000}:${GID:-1000} volumes: - - ./:/mg_telegram/ + - ./:/mgtg - ./static:/static/ links: - postgres diff --git a/main.go b/main.go index f90cbc8..48e6de6 100644 --- a/main.go +++ b/main.go @@ -3,8 +3,9 @@ package main import ( "os" - "github.com/getsentry/raven-go" "github.com/jessevdk/go-flags" + + "github.com/op/go-logging" ) // Options struct @@ -14,12 +15,13 @@ type Options struct { const transport = "mg-telegram" -var options Options -var parser = flags.NewParser(&options, flags.Default) - -func init() { - raven.SetDSN(config.SentryDSN) -} +var ( + config *TransportConfig + orm *Orm + logger *logging.Logger + options Options + parser = flags.NewParser(&options, flags.Default) +) func main() { if _, err := parser.Parse(); err != nil { diff --git a/routing_test.go b/routing_test.go index 656a167..d1fc9df 100644 --- a/routing_test.go +++ b/routing_test.go @@ -11,6 +11,10 @@ import ( ) func init() { + config = LoadConfig("config_test.yml") + orm = NewDb(config) + logger = newLogger() + c := Connection{ ID: 1, ClientID: "123123", diff --git a/run.go b/run.go index 51a13fe..c553730 100644 --- a/run.go +++ b/run.go @@ -7,16 +7,11 @@ import ( "os/signal" "syscall" + "github.com/getsentry/raven-go" _ "github.com/golang-migrate/migrate/database/postgres" _ "github.com/golang-migrate/migrate/source/file" ) -var ( - config = LoadConfig("config.yml") - orm = NewDb(config) - logger = newLogger() -) - func init() { parser.AddCommand("run", "Run mg-telegram", @@ -30,6 +25,11 @@ type RunCommand struct{} // Execute command func (x *RunCommand) Execute(args []string) error { + config = LoadConfig(options.Config) + orm = NewDb(config) + logger = newLogger() + raven.SetDSN(config.SentryDSN) + go start() c := make(chan os.Signal, 1)