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

add Jenkins configuration

This commit is contained in:
Alex Lushpai 2018-05-25 16:01:58 +03:00
parent 755354f1b7
commit 47d790075f
4 changed files with 89 additions and 2 deletions

77
Jenkinsfile vendored Normal file
View File

@ -0,0 +1,77 @@
pipeline {
agent {
label 't2medium'
}
options {
disableConcurrentBuilds()
}
stages {
stage('Prepare') {
steps {
sh 'cp config_test.yml.dist config_test.yml'
compose 'up -d --build postgres_test'
compose 'run --rm mg_telegram make migrate_test'
}
}
stage('Tests') {
steps {
compose 'run --rm --no-deps mg_telegram 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'
urlVariable: 'HUB_URL'
pathVariable: 'HUB_PATH'
)]) {
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}"
}

View File

@ -21,6 +21,15 @@ run: migrate
@echo "==> Running" @echo "==> Running"
@${BIN} --config $(CONFIG_FILE) run @${BIN} --config $(CONFIG_FILE) run
test: deps fmt
@echo "==> Running tests"
@cd $(SRC_DIR) && go test ./... -v -cpu 2 -cover -race
jenkins_test: deps
@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
fmt: fmt:
@echo "==> Running gofmt" @echo "==> Running gofmt"
@gofmt -l -s -w $(SRC_DIR) @gofmt -l -s -w $(SRC_DIR)

View File

@ -3,7 +3,7 @@ database:
http_server: http_server:
host: ~ host: ~
listen: :3001 listen: :3002
sentry_dsn: ~ sentry_dsn: ~

View File

@ -9,7 +9,6 @@ services:
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:5450}:${POSTGRES_PORT:-5450}
command: -p ${POSTGRES_PORT:-5450}
mg_telegram_test: mg_telegram_test:
image: golang:1.9.3-stretch image: golang:1.9.3-stretch
@ -19,3 +18,5 @@ services:
- ./:/mg_telegram/ - ./:/mg_telegram/
links: links:
- postgres_test - postgres_test
ports:
- ${MG_TELEGRAM_ADDRESS:-3002}:3002