1
0
mirror of synced 2024-11-22 12:26:02 +03:00

update docker & jenkinks configuration

This commit is contained in:
Alex Lushpai 2018-05-31 15:03:57 +03:00
parent 889e246320
commit 3933319b0e
10 changed files with 39 additions and 33 deletions

4
.gitignore vendored
View File

@ -1,5 +1,5 @@
gin-bin
config.yml config.yml
config_test.yml
.idea/ .idea/
/bin/* /bin/*
mg-telegram *.xml

View File

@ -1,7 +1,7 @@
FROM golang:1.9.3-stretch FROM golang:1.9.3-stretch
WORKDIR / WORKDIR /
ADD ./bin/mg-telegram / ADD ./bin/transport /
ADD ./templates/ /templates/ ADD ./templates/ /templates/
ADD ./static/ /static/ ADD ./static/ /static/
ADD ./translate/ /translate/ ADD ./translate/ /translate/
@ -9,6 +9,6 @@ ADD ./migrations/ /migrations/
EXPOSE 3001 EXPOSE 3001
ENTRYPOINT ["/mg-telegram"] ENTRYPOINT ["/transport"]
CMD ["run"] CMD ["run"]

4
Jenkinsfile vendored
View File

@ -15,7 +15,7 @@ pipeline {
stages { stages {
stage('Prepare') { stage('Prepare') {
steps { 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 'up -d --build postgres_test'
compose 'run --rm mg_telegram_test make migrate_test' compose 'run --rm mg_telegram_test make migrate_test'
} }
@ -23,7 +23,7 @@ pipeline {
stage('Tests') { stage('Tests') {
steps { steps {
compose 'run --rm --no-deps mg_telegram_test make jenkins_test' compose 'run --rm mg_telegram_test make jenkins_test'
} }
post { post {

View File

@ -3,7 +3,7 @@ SRC_DIR=$(ROOT_DIR)
MIGRATIONS_DIR=$(ROOT_DIR)/migrations MIGRATIONS_DIR=$(ROOT_DIR)/migrations
CONFIG_FILE=$(ROOT_DIR)/config.yml CONFIG_FILE=$(ROOT_DIR)/config.yml
CONFIG_TEST_FILE=$(ROOT_DIR)/config_test.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") REVISION=$(shell git describe --tags 2>/dev/null || git log --format="v0.0-%h" -n 1 || echo "v0.0-unknown")
ifndef GOPATH ifndef GOPATH
@ -22,9 +22,8 @@ run: migrate
@${BIN} --config $(CONFIG_FILE) run @${BIN} --config $(CONFIG_FILE) run
test: deps fmt test: deps fmt
@echo "==> Running tests (result in test-report.xml)" @echo "==> Running tests"
@go get -v -u github.com/jstemmer/go-junit-report @cd $(SRC_DIR) && go test ./... -v -cpu 2
@cd $(SRC_DIR) && go test ./... -v -cpu 2 -cover -race | go-junit-report -set-exit-code > $(SRC_DIR)/test-report.xml
jenkins_test: deps jenkins_test: deps
@echo "==> Running tests (result in test-report.xml)" @echo "==> Running tests (result in test-report.xml)"
@ -43,10 +42,10 @@ deps:
@go get -d -v $(DEPS) @go get -d -v $(DEPS)
migrate: build migrate: build
@${BIN} --config $(CONFIG_FILE) migrate -p ./migrations/ ${BIN} --config $(CONFIG_FILE) migrate -p $(MIGRATIONS_DIR)
migrate_test: build migrate_test: build
@${BIN} --config $(CONFIG_TEST_FILE) migrate ./migrations/ @${BIN} --config $(CONFIG_TEST_FILE) migrate -p $(MIGRATIONS_DIR)
migrate_down: build migrate_down: build
@${BIN} --config $(CONFIG_FILE) migrate -v down @${BIN} --config $(CONFIG_FILE) migrate -v down

View File

@ -1,5 +1,5 @@
database: 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: http_server:
host: ~ host: ~

View File

@ -8,16 +8,17 @@ services:
POSTGRES_PASSWORD: mg_telegram_test POSTGRES_PASSWORD: mg_telegram_test
POSTGRES_DATABASE: mg_telegram_test POSTGRES_DATABASE: mg_telegram_test
ports: ports:
- ${POSTGRES_ADDRESS:-127.0.0.1:5450}:${POSTGRES_PORT:-5450} - ${POSTGRES_ADDRESS:-127.0.0.1:5434}:${POSTGRES_PORT:-5432}
mg_telegram_test: mg_telegram_test:
image: golang:1.9.3-stretch image: golang:1.9.3-stretch
working_dir: /mg_telegram working_dir: /mgtg
user: ${UID:-1000}:${GID:-1000} user: ${UID:-1000}:${GID:-1000}
volumes: volumes:
- ./:/mg_telegram/ - ./:/mgtg/
- ./static:/static/
links: links:
- postgres_test - postgres_test
ports: ports:
- ${MG_TELEGRAM_ADDRESS:-3002}:3002 - ${MG_TELEGRAM_ADDRESS:-3002}:3002
command: make migrate_test # command: make migrate_test

View File

@ -8,14 +8,14 @@ services:
POSTGRES_PASSWORD: mg_telegram POSTGRES_PASSWORD: mg_telegram
POSTGRES_DATABASE: mg_telegram POSTGRES_DATABASE: mg_telegram
ports: ports:
- ${POSTGRES_ADDRESS:-127.0.0.1:5434}:5432 - ${POSTGRES_ADDRESS:-127.0.0.1:5434}:${POSTGRES_PORT:-5432}
mg_telegram: mg_telegram:
image: golang:1.9.3-stretch image: golang:1.9.3-stretch
working_dir: /mg_telegram working_dir: /mgtg
user: ${UID:-1000}:${GID:-1000} user: ${UID:-1000}:${GID:-1000}
volumes: volumes:
- ./:/mg_telegram/ - ./:/mgtg
- ./static:/static/ - ./static:/static/
links: links:
- postgres - postgres

16
main.go
View File

@ -3,8 +3,9 @@ package main
import ( import (
"os" "os"
"github.com/getsentry/raven-go"
"github.com/jessevdk/go-flags" "github.com/jessevdk/go-flags"
"github.com/op/go-logging"
) )
// Options struct // Options struct
@ -14,12 +15,13 @@ type Options struct {
const transport = "mg-telegram" const transport = "mg-telegram"
var options Options var (
var parser = flags.NewParser(&options, flags.Default) config *TransportConfig
orm *Orm
func init() { logger *logging.Logger
raven.SetDSN(config.SentryDSN) options Options
} parser = flags.NewParser(&options, flags.Default)
)
func main() { func main() {
if _, err := parser.Parse(); err != nil { if _, err := parser.Parse(); err != nil {

View File

@ -11,6 +11,10 @@ import (
) )
func init() { func init() {
config = LoadConfig("config_test.yml")
orm = NewDb(config)
logger = newLogger()
c := Connection{ c := Connection{
ID: 1, ID: 1,
ClientID: "123123", ClientID: "123123",

12
run.go
View File

@ -7,16 +7,11 @@ import (
"os/signal" "os/signal"
"syscall" "syscall"
"github.com/getsentry/raven-go"
_ "github.com/golang-migrate/migrate/database/postgres" _ "github.com/golang-migrate/migrate/database/postgres"
_ "github.com/golang-migrate/migrate/source/file" _ "github.com/golang-migrate/migrate/source/file"
) )
var (
config = LoadConfig("config.yml")
orm = NewDb(config)
logger = newLogger()
)
func init() { func init() {
parser.AddCommand("run", parser.AddCommand("run",
"Run mg-telegram", "Run mg-telegram",
@ -30,6 +25,11 @@ type RunCommand struct{}
// Execute command // Execute command
func (x *RunCommand) Execute(args []string) error { func (x *RunCommand) Execute(args []string) error {
config = LoadConfig(options.Config)
orm = NewDb(config)
logger = newLogger()
raven.SetDSN(config.SentryDSN)
go start() go start()
c := make(chan os.Signal, 1) c := make(chan os.Signal, 1)