commit
c9d6459b9f
80
Jenkinsfile
vendored
Normal file
80
Jenkinsfile
vendored
Normal file
@ -0,0 +1,80 @@
|
||||
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'
|
||||
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'
|
||||
)]) {
|
||||
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}"
|
||||
}
|
11
Makefile
11
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)
|
||||
@ -36,7 +45,7 @@ migrate: build
|
||||
@${BIN} --config $(CONFIG_FILE) migrate -p ./migrations/
|
||||
|
||||
migrate_test: build
|
||||
@${BIN} --config $(CONFIG_TEST_FILE) migrate
|
||||
@${BIN} --config $(CONFIG_TEST_FILE) migrate ./migrations/
|
||||
|
||||
migrate_down: build
|
||||
@${BIN} --config $(CONFIG_FILE) migrate -v down
|
||||
|
@ -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