diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000000000000000000000000000000000000..c548e323c08404325cb3b7d9ec84e0a6315bd8fc --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,54 @@ +pipeline { + agent { label 'docker' } + + stages { + stage('Refresh') { + steps { + slackSend (color: 'good', message: "STARTED: <${env.BUILD_URL}|${env.JOB_NAME} [${env.BUILD_NUMBER}]>") + sh 'git fetch --tags' + sh 'make clean' + sh 'make refresh' + } + } + stage('Build') { + steps { + ansiColor('xterm') { + sh 'make build' + } + } + } + stage('Test') { + steps { + sh 'make db_test' + /* let the time to postgres to start */ + sh 'sleep 5' + sh 'make test' + } + } + stage('Push') { + steps { + sh 'make tag' + sh 'make push' + } + } + stage('Clean') { + steps { + sh 'make clean' + } + } + } + + post { + always { + /* clean up the workspace */ + deleteDir() + } + failure { + slackSend (color: 'danger', message: "FAILED: <${env.BUILD_URL}|${env.JOB_NAME} [${env.BUILD_NUMBER}]>") + } + success { + slackSend (color: 'good', message: "SUCCESSFUL: <${env.BUILD_URL}|${env.JOB_NAME} [${env.BUILD_NUMBER}]>") + } + } + +} diff --git a/Makefile b/Makefile index 26ba66bfa18bbe7e37784f0bf1d118a99c3110c3..4de5afef661ec5be8bfffbc36199c34f30e7ce1d 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,49 @@ -.PHONY: help db_test test +.PHONY: help build tag push refresh release db_dev initdb db_test test + +OWNER := europeanspallationsource +GIT_TAG := $(shell git describe --always) +IMAGE := ics-inventory help: - @echo "Please use \`make <target>' where <target> is one of" - @echo " db_test to start the postgres database for test" - @echo " test to run the tests" +# http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html + @echo "ics-inventory" + @echo "=============" + @echo + @grep -E '^[a-zA-Z0-9_%/-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' + +build: ## build the latest image + docker build -t $(OWNER)/$(IMAGE):latest . + +tag: ## tag the latest image with the git tag + docker tag $(OWNER)/$(IMAGE):latest $(OWNER)/$(IMAGE):$(GIT_TAG) + +push: ## push the latest and git tag image + docker push $(OWNER)/$(IMAGE):$(GIT_TAG) + docker push $(OWNER)/$(IMAGE):latest + +clean: ## remove the image with git tag and the test database + -docker rmi $(OWNER)/$(IMAGE):$(GIT_TAG) + -docker rm -f inventory_postgres_test + +refresh: ## pull the latest image from Docker Hub +# skip if error: image might not be on dockerhub yet + -docker pull $(OWNER)/$(IMAGE):latest + +release: refresh \ + build \ + tag \ + push +release: ## build, tag, and push all stacks + +db_dev: ## start postgres for development + docker-compose up -d postgres + +initdb: ## initialize the dev database + docker-compose run --rm web flask initdb -db_test: +db_test: ## start postgres for test docker-compose -f docker-compose-test.yml up -d postgres_test -test: +test: ## run the tests docker-compose -f docker-compose-test.yml run --rm web_test diff --git a/README.rst b/README.rst index c0284028f7e567f3e2cc0b4805dd3b07469f99be..89f675c51b730d59ea47ab664660cca87f67b1af 100644 --- a/README.rst +++ b/README.rst @@ -16,8 +16,12 @@ You can use docker for development: # Start only postgres so it has time to initialize $ docker-compose up -d postgres + or + $ make db_dev # Create the database - $ docker-compose run web flask initdb + $ docker-compose run --rm web flask initdb + or + $ make initdb 3. Start the application:: diff --git a/docker-compose-test.yml b/docker-compose-test.yml index 987622fab0513f27237bb869ed21d64ff5464121..ed71ab40e7542107cc88e21927a15d06ce92eb08 100644 --- a/docker-compose-test.yml +++ b/docker-compose-test.yml @@ -1,7 +1,7 @@ version: '2' services: web_test: - image: inventory + image: europeanspallationsource/ics-inventory:latest container_name: inventory_web_test build: . command: pytest --cov=app -v @@ -14,8 +14,6 @@ services: container_name: inventory_postgres_test expose: - "5432" - volumes: - - ./data/test:/var/lib/postgresql/data/pgdata environment: POSTGRES_USER: ics POSTGRES_PASSWORD: icstest diff --git a/docker-compose.yml b/docker-compose.yml index dafc6031f6ec9432dfdfe4127db2877aec263746..d6f7922f3b1d85d5353f09c05ca37a420902a527 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: '2' services: web: - image: inventory + image: europeanspallationsource/ics-inventory:latest container_name: inventory_web build: . environment: