1
0
mirror of synced 2024-11-25 13:16:02 +03:00

Merge pull request #5 from gwinn/master

Docker & Jenkins configuration
This commit is contained in:
Alex Lushpai 2018-05-25 16:16:41 +03:00 committed by GitHub
commit c9d6459b9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 93 additions and 3 deletions

80
Jenkinsfile vendored Normal file
View 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}"
}

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)
@ -36,7 +45,7 @@ migrate: build
@${BIN} --config $(CONFIG_FILE) migrate -p ./migrations/ @${BIN} --config $(CONFIG_FILE) migrate -p ./migrations/
migrate_test: build migrate_test: build
@${BIN} --config $(CONFIG_TEST_FILE) migrate @${BIN} --config $(CONFIG_TEST_FILE) migrate ./migrations/
migrate_down: build migrate_down: build
@${BIN} --config $(CONFIG_FILE) migrate -v down @${BIN} --config $(CONFIG_FILE) migrate -v down

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