From 57719a8e075cb1bbf0dade9c564dc374e6cf49cd Mon Sep 17 00:00:00 2001 From: Alessandro Cerioni <acerioni@grandlyon.com> Date: Tue, 19 Mar 2019 19:46:19 +0100 Subject: [PATCH] Added GitLab CI. Loading the configuration from environment variables. --- .gitlab-ci.yml | 73 ++++++++++++++++++++++++++++++++++++++++++++ config.template.yaml | 29 ++++++++---------- docker-compose.yml | 3 +- 3 files changed, 88 insertions(+), 17 deletions(-) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..bfdb200 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,73 @@ +variables: + GHOST_API: https://ghost-intothesky.alpha.grandlyon.com/ghost/api + #GHOST_ADMIN_API_KEY: + INDEXER__ES_URL: https://elastic2.alpha.grandlyon.com + INDEXER__ES_POSTS_INDEX: posts.ingest.v5 + INDEXER__ES_PAGES_INDEX: pages.ingest.v5 + REINDEXER__ES_SOURCE_URL: https://elastic2.alpha.grandlyon.com:443 + REINDEXER__ES_DESTINATION_URL: https://elastic2.alpha.grandlyon.com + REINDEXER__SOURCE_POSTS_INDEX: posts.ingest.v5 + REINDEXER__SOURCE_PAGES_INDEX: pages.ingest.v5 + REINDEXER__DESTINATION_POSTS_INDEX: posts.v5 + REINDEXER__DESTINATION_PAGES_INDEX: pages.v5 + REINDEXER__POSTS_TEMPLATE_NAME: ghost-posts-template + REINDEXER__PAGES_TEMPLATE_NAME: ghost-pages-template + +stages: + - build + - deploy + +build_development: + stage: build + only: + - development + script: + - export TAG=dev + - export CONTENT_INDEXER_BIND_PORT=4000 + - docker-compose build + - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY + - docker-compose push + +build_release: + stage: build + only: + - tags + except: + - /^(?!master).+@/ + script: + - export TAG=$(echo $CI_COMMIT_TAG | sed 's/v//g') + - export CONTENT_INDEXER_BIND_PORT=4000 + - docker-compose build + - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY + - docker-compose push + +deploy_development: + stage: deploy + only: + - development + script: + - export TAG=dev + - export CONTENT_INDEXER_BIND_PORT=4000 + - envsubst < config.template.yml > config.yml + - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY + - docker-compose pull + - docker-compose --project-name service-email-${TAG} up -d --force-recreate + environment: + name: development + +deploy_staging: + stage: deploy + only: + - development + when: manual + script: + - export TAG=staging + - export CONTENT_INDEXER_BIND_PORT=4100 + - envsubst < config.template.yml > config.yml + - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY + - TAG=dev docker-compose pull + - docker tag $CI_REGISTRY/refonte-data/service-email:dev $CI_REGISTRY/refonte-data/service-email:${TAG} + - docker push $CI_REGISTRY/refonte-data/service-email:${TAG} + - docker-compose --project-name service-email-${TAG} up -d --force-recreate + environment: + name: staging diff --git a/config.template.yaml b/config.template.yaml index 98a9ff8..3b55f01 100644 --- a/config.template.yaml +++ b/config.template.yaml @@ -1,25 +1,22 @@ content_getter: - # wp_api: <the_wordpress_api_url> - # wp_username: <the_wordpress_username> - # wp_password: <the_wordpress_password> - ghost_api: <the_ghost_api_url, ex. https://your-domain/ghost/api> - ghost_admin_api_key: <the_ghost_admin_api_key> + ghost_api: ${GHOST_API} + ghost_admin_api_key: ${GHOST_ADMIN_API_KEY} indexer: - url: <the_elasticsearch_url> + url: ${INDEXER__ES_URL} index: - posts: <the_elasticsearch_index_for_posts> - pages: <the_elasticsearch_index_for_pages> + posts: ${INDEXER__ES_POSTS_INDEX} + pages: ${INDEXER__ES_PAGES_INDEX} reindexer: - source_url: <the_source_elasticsearch_url> - destination_url: <the_destination_elasticsearch_url> + source_url: ${REINDEXER__ES_SOURCE_URL} + destination_url: ${REINDEXER__ES_DESTINATION_URL} source_index: - posts: <the_source_elasticsearch_index_for_posts> - pages: <the_source_elasticsearch_index_for_pages> + posts: ${REINDEXER__SOURCE_POSTS_INDEX} + pages: ${REINDEXER__SOURCE_PAGES_INDEX} destination_index: - posts: <the_destination_elasticsearch_index_for_posts> - pages: <the_destination_elasticsearch_index_for_pages> + posts: ${REINDEXER__DESTINATION_POSTS_INDEX} + pages: ${REINDEXER__DESTINATION_PAGES_INDEX}} template: - posts: <the_name_to_use_for_the_elasticsearch_dynamic_template_for_posts> - pages: <the_name_to_use_for_the_elasticsearch_dynamic_template_for_pages> + posts: ${REINDEXER__POSTS_TEMPLATE_NAME} + pages: ${REINDEXER__PAGES_TEMPLATE_NAME} diff --git a/docker-compose.yml b/docker-compose.yml index 12544fe..02426d2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,8 @@ version: "3.0" services: api: build: . + image: registry.alpha.grandlyon.com/refonte-data/content-indexer:${TAG} ports: - - 8000:8000 + - ${CONTENT_INDEXER_BIND_PORT}:8000 volumes: - ./config.yaml:/app/config.yaml -- GitLab