mirror of
https://github.com/retailcrm/mg-bot-helper.git
synced 2025-04-10 12:30:54 +00:00
cleanup CI configuration
This commit is contained in:
parent
cceb2b8949
commit
ec0ed29030
4 changed files with 13 additions and 147 deletions
79
Jenkinsfile
vendored
79
Jenkinsfile
vendored
|
@ -1,79 +0,0 @@
|
|||
pipeline {
|
||||
agent {
|
||||
label 't2medium'
|
||||
}
|
||||
|
||||
options {
|
||||
disableConcurrentBuilds()
|
||||
}
|
||||
|
||||
environment {
|
||||
HUB_URL = credentials('docker_hub_url')
|
||||
HUB_PATH = credentials('docker_hub_path')
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Prepare') {
|
||||
steps {
|
||||
sh 'cp config_test.yml.dist config_test.yml'
|
||||
compose 'up -d --build postgres_test'
|
||||
}
|
||||
}
|
||||
|
||||
stage('Tests') {
|
||||
steps {
|
||||
compose 'run --rm mg_bot_test make jenkins_test'
|
||||
}
|
||||
|
||||
post {
|
||||
always {
|
||||
sh 'cat ./test-report.xml'
|
||||
junit 'test-report.xml'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Docker Images') {
|
||||
when {
|
||||
branch 'master'
|
||||
}
|
||||
steps {
|
||||
withCredentials([usernamePassword(
|
||||
credentialsId: 'docker-hub-credentials',
|
||||
usernameVariable: 'HUB_USER',
|
||||
passwordVariable: 'HUB_PASS'
|
||||
)]) {
|
||||
sh 'echo ${HUB_PASS} | docker login -u ${HUB_USER} --password-stdin ${HUB_URL}'
|
||||
}
|
||||
|
||||
sh 'docker build -t ${HUB_URL}${HUB_PATH} ./'
|
||||
sh 'docker push ${HUB_URL}${HUB_PATH}'
|
||||
}
|
||||
post {
|
||||
always {
|
||||
sh 'docker rmi ${HUB_URL}${HUB_PATH}:latest'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
post {
|
||||
always {
|
||||
compose 'down -v'
|
||||
deleteDir ()
|
||||
}
|
||||
aborted {
|
||||
echo "Aborted."
|
||||
}
|
||||
success {
|
||||
echo "Success."
|
||||
}
|
||||
failure {
|
||||
echo "Failure."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def compose(cmd) {
|
||||
sh "docker-compose --no-ansi -f docker-compose-test.yml ${cmd}"
|
||||
}
|
37
Makefile
37
Makefile
|
@ -2,30 +2,9 @@ ROOT_DIR=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
|
|||
SRC_DIR=$(ROOT_DIR)/src
|
||||
MIGRATIONS_DIR=$(ROOT_DIR)/migrations
|
||||
CONFIG_FILE=$(ROOT_DIR)/config.yml
|
||||
CONFIG_TEST_FILE=$(ROOT_DIR)/config_test.yml
|
||||
BIN=$(ROOT_DIR)/bin/bot
|
||||
REVISION=$(shell git describe --tags 2>/dev/null || git log --format="v0.0-%h" -n 1 || echo "v0.0-unknown")
|
||||
|
||||
build: deps fmt
|
||||
@echo "==> Building"
|
||||
@cd $(SRC_DIR) && CGO_ENABLED=0 go build -o $(BIN) -ldflags "-X common.build=${REVISION}" .
|
||||
@echo $(BIN)
|
||||
|
||||
run: migrate
|
||||
@echo "==> Running"
|
||||
@${BIN} --config $(CONFIG_FILE) run
|
||||
|
||||
test: deps fmt
|
||||
@echo "==> Running tests"
|
||||
@cd $(SRC_DIR) && go test ./... -v -cpu 2 -cover -race
|
||||
|
||||
jenkins_test: migrate_test
|
||||
@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 > $(ROOT_DIR)/test-report.xml
|
||||
@echo "==> Cleanup dependencies"
|
||||
@go mod tidy
|
||||
|
||||
fmt:
|
||||
@echo "==> Running gofmt"
|
||||
@gofmt -l -s -w $(SRC_DIR)
|
||||
|
@ -34,11 +13,21 @@ deps:
|
|||
@echo "==> Installing dependencies"
|
||||
@go mod tidy
|
||||
|
||||
build: deps fmt
|
||||
@echo "==> Building"
|
||||
@cd $(SRC_DIR) && CGO_ENABLED=0 go build -o $(BIN) -ldflags "-X common.build=${REVISION}" .
|
||||
@echo $(BIN)
|
||||
|
||||
migrate: build
|
||||
${BIN} --config $(CONFIG_FILE) migrate -p $(MIGRATIONS_DIR)
|
||||
|
||||
migrate_test: build
|
||||
@${BIN} --config $(CONFIG_TEST_FILE) migrate -p $(MIGRATIONS_DIR)
|
||||
|
||||
migrate_down: build
|
||||
@${BIN} --config $(CONFIG_FILE) migrate -v down
|
||||
|
||||
run: migrate
|
||||
@echo "==> Running"
|
||||
@${BIN} --config $(CONFIG_FILE) run
|
||||
|
||||
test: deps fmt
|
||||
@echo "==> Running tests"
|
||||
@cd $(SRC_DIR) && go test ./... -v -cpu 2 -cover -race
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
version: ~
|
||||
|
||||
database:
|
||||
connection: postgres://mg_bot_test:mg_bot_test@postgres_test:5432/mg_bot_test?sslmode=disable
|
||||
|
||||
http_server:
|
||||
host: ~
|
||||
listen: :3002
|
||||
|
||||
bot_info:
|
||||
name: Helper
|
||||
code: crm-info-bot
|
||||
logo_path: /static/logo.svg
|
||||
|
||||
sentry_dsn: ~
|
||||
|
||||
log_level: 5
|
||||
|
||||
debug: false
|
|
@ -1,25 +0,0 @@
|
|||
version: '2.1'
|
||||
|
||||
services:
|
||||
postgres_test:
|
||||
image: postgres:9.6
|
||||
environment:
|
||||
POSTGRES_USER: mg_bot_test
|
||||
POSTGRES_PASSWORD: mg_bot_test
|
||||
POSTGRES_DATABASE: mg_bot_test
|
||||
ports:
|
||||
- ${POSTGRES_ADDRESS:-127.0.0.1:5434}:${POSTGRES_PORT:-5432}
|
||||
|
||||
mg_bot_test:
|
||||
image: golang:1.11-stretch
|
||||
working_dir: /mg-bot
|
||||
user: ${UID:-1000}:${GID:-1000}
|
||||
environment:
|
||||
GOCACHE: /go
|
||||
volumes:
|
||||
- ./:/mg-bot/
|
||||
- ./static:/static/
|
||||
links:
|
||||
- postgres_test
|
||||
ports:
|
||||
- ${mg_bot_ADDRESS:-3002}:3002
|
Loading…
Add table
Reference in a new issue