1
0
mirror of synced 2024-11-22 04:26:01 +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_test.yml
.idea/
/bin/*
mg-telegram
*.xml

View File

@ -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"]

4
Jenkinsfile vendored
View File

@ -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 {

View File

@ -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

View File

@ -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: ~

View File

@ -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

View File

@ -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

16
main.go
View File

@ -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 {

View File

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

12
run.go
View File

@ -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)