Skip to content
Snippets Groups Projects
Commit eb66aa91 authored by Benjamin Bertrand's avatar Benjamin Bertrand
Browse files

Add Jenkinsfile and Makefile to build the image

parent dc12809b
No related branches found
No related tags found
No related merge requests found
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}]>")
}
}
}
.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
......@@ -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::
......
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
......
version: '2'
services:
web:
image: inventory
image: europeanspallationsource/ics-inventory:latest
container_name: inventory_web
build: .
environment:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment