add Jenkins configuration
This commit is contained in:
parent
755354f1b7
commit
47d790075f
77
Jenkinsfile
vendored
Normal file
77
Jenkinsfile
vendored
Normal 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}"
|
||||
}
|
9
Makefile
9
Makefile
@ -21,6 +21,15 @@ 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: 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:
|
||||
@echo "==> Running gofmt"
|
||||
@gofmt -l -s -w $(SRC_DIR)
|
||||
|
@ -3,7 +3,7 @@ database:
|
||||
|
||||
http_server:
|
||||
host: ~
|
||||
listen: :3001
|
||||
listen: :3002
|
||||
|
||||
sentry_dsn: ~
|
||||
|
||||
|
@ -9,7 +9,6 @@ services:
|
||||
POSTGRES_DATABASE: mg_telegram_test
|
||||
ports:
|
||||
- ${POSTGRES_ADDRESS:-127.0.0.1:5450}:${POSTGRES_PORT:-5450}
|
||||
command: -p ${POSTGRES_PORT:-5450}
|
||||
|
||||
mg_telegram_test:
|
||||
image: golang:1.9.3-stretch
|
||||
@ -19,3 +18,5 @@ services:
|
||||
- ./:/mg_telegram/
|
||||
links:
|
||||
- postgres_test
|
||||
ports:
|
||||
- ${MG_TELEGRAM_ADDRESS:-3002}:3002
|
||||
|
Loading…
Reference in New Issue
Block a user