diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1a3407acce0e6dd22163d75449cea99db91569f9..63bbe7be64bc420c304f9d6e7594c31cd4f72855 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,20 +1,39 @@ stages: + - sonar-analysis - build - - deploy variables: - PROXY_HOST_TARGET: https://download.data.grandlyon.com + SONAR_URL: https://sonarqube.forge.grandlyon.com + +sonarqube: + stage: sonar-analysis + only: + - master + before_script: + - export PATH=$PATH:/usr/local/bin/sonar-scanner-3.2.0.1227-linux/bin/ + - export NODE_PATH=$NODE_PATH:`npm root -g` + script: + - > + sonar-scanner + -Dsonar.projectName=${SONAR_PROJECT_KEY} + -Dsonar.projectVersion=1.0 + -Dsonar.sourceEncoding=UTF-8 + -Dsonar.projectBaseDir=. + -Dsonar.host.url=${SONAR_URL} + -Dsonar.projectKey=${SONAR_PROJECT_KEY} + -Dsonar.login=${SONAR_TOKEN} build_development: stage: build only: - development script: - - export TAG=dev + - export TAG=$CI_COMMIT_SHORT_SHA - export PROXY_MVT_BIND_PORT=9002 - docker-compose build - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY - docker-compose push + - "curl -X POST -F token=$CI_JOB_TOKEN -F ref=master -F variables[TAG]=${TAG} https://forge.grandlyon.com/api/v4/projects/336/trigger/pipeline" build_release: stage: build @@ -25,41 +44,4 @@ build_release: - export PROXY_MVT_BIND_PORT=9002 - 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 PROXY_MVT_BIND_PORT=9003 - - export ELASTICSEARCH_URL=https://data-reloaded-dev.alpha.grandlyon.com/api/es-consumer-aware - - export TECHNICAL_ACCOUNT_USERNAME=$TECHNICAL_ACCOUNT_USERNAME - - export TECHNICAL_ACCOUNT_PASSWORD=$TECHNICAL_ACCOUNT_PASSWORD - - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY - - docker-compose pull - - docker-compose --project-name proxy-map-services-${TAG} up -d --force-recreate - environment: - name: development - -deploy_staging: - stage: deploy - only: - - development - when: manual - script: - - export TAG=staging - - export PROXY_MVT_BIND_PORT=9103 - - export ELASTICSEARCH_URL=https://data-reloaded-rec.alpha.grandlyon.com/api/es-consumer-aware - - export TECHNICAL_ACCOUNT_USERNAME=$TECHNICAL_ACCOUNT_USERNAME - - export TECHNICAL_ACCOUNT_PASSWORD=$TECHNICAL_ACCOUNT_PASSWORD - - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY - - TAG=dev docker-compose pull - - export REGISTRY_PATH=web-et-numerique/web-et-numerique-internet/data.grandlyon.com/web-portal/components/proxies/web-mapping-services - - docker tag $CI_REGISTRY/$REGISTRY_PATH:dev $CI_REGISTRY/$REGISTRY_PATH:${TAG} - - docker push $CI_REGISTRY/$REGISTRY_PATH:${TAG} - - docker-compose --project-name proxy-map-services-${TAG} up -d --force-recreate - environment: - name: staging - + - docker-compose push \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..950300368214dfc135819c080d1a34399e025106 --- /dev/null +++ b/README.md @@ -0,0 +1,42 @@ +# Web mapping services proxy + +## Installation + +This proxy has been developed with [Node.js](https://nodejs.org/en/) and the [http-proxy](https://www.npmjs.com/package/http-proxy) node module. + +You will need to install Node.js on your computer. Then you will need to install the project's dependencies. Go to the root of the project and run the following command. + +```bash +npm install +``` + +## Environment variables + +In order to run the code, some environment variables are needed. They are specified in the `template.env` file at the root of the project. + +For a local deployment: + +1. `cp template.env .env` +2. Edit .env according to the chosen configuration + +The values will be read from the file by default when running with docker. If you run the service outside of docker you can export those variables. + +## Running the app without docker + +```bash +# development +npm run start +``` + +## Running the app with docker + +```bash +# build +docker-compose build + +# deploy +docker-compose up [-d] + +# build and deploy +docker-compose up --build [-d] +``` diff --git a/docker-compose.yml b/docker-compose.yml index 1dfabb4f7d8ff169475497538e4e6e26e1890fba..d897ecb8b176550697a29ddfcf2f85da7908e93f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,11 +8,11 @@ services: ports: - ${PROXY_MVT_BIND_PORT}:9000 environment: - - REDIS_SENTINEL_HOST=redis-sentinel-1 - - REDIS_SENTINEL_PORT=26379 - - REDIS_GROUP_NAME=mymaster - - REDIS_AUTHORIZED_TTL=86400 - - REDIS_UNAUTHORIZED_TTL=60 + - REDIS_SENTINEL_HOST=${REDIS_SENTINEL_HOST} + - REDIS_SENTINEL_PORT=${REDIS_SENTINEL_PORT} + - REDIS_GROUP_NAME=${REDIS_MASTER_SET} + - REDIS_AUTHORIZED_TTL=${REDIS_AUTHORIZED_TTL} + - REDIS_UNAUTHORIZED_TTL=${REDIS_UNAUTHORIZED_TTL} - ELASTICSEARCH_URL=${ELASTICSEARCH_URL} - TECHNICAL_ACCOUNT_USERNAME=${TECHNICAL_ACCOUNT_USERNAME} - TECHNICAL_ACCOUNT_PASSWORD=${TECHNICAL_ACCOUNT_PASSWORD} @@ -24,7 +24,7 @@ services: redis-master: image: 'bitnami/redis:latest' environment: - - ALLOW_EMPTY_PASSWORD=yes + - ALLOW_EMPTY_PASSWORD=${ALLOW_EMPTY_PASSWORD} volumes: - redis-master:/bitnami/redis/data restart: unless-stopped @@ -32,8 +32,8 @@ services: redis-sentinel-1: image: 'bitnami/redis-sentinel:latest' environment: - - REDIS_MASTER_HOST=redis-master - - REDIS_MASTER_SET=mymaster + - REDIS_MASTER_HOST=${REDIS_MASTER_HOST} + - REDIS_MASTER_SET=${REDIS_MASTER_SET} volumes: - redis-sentinel-1:/bitnami/redis/data restart: unless-stopped @@ -42,7 +42,7 @@ services: image: 'bitnami/redis:latest' command: redis-server --bind 0.0.0.0 --slaveof redis-master 6379 --dir /bitnami/redis/data environment: - - ALLOW_EMPTY_PASSWORD=yes + - ALLOW_EMPTY_PASSWORD=${ALLOW_EMPTY_PASSWORD} volumes: - redis-slave-1:/bitnami/redis/data restart: unless-stopped diff --git a/template.env b/template.env index 680cec0b72395ab505b4c76670283db96f2f5c41..5dfdbbde2bb2e4d47855c523e56d5b15675c3fe5 100644 --- a/template.env +++ b/template.env @@ -1,6 +1,13 @@ TAG=<tag of the image to be used> -PROXY_MVT_PORT_BIND_PORT=<proxy port> +PROXY_MAP_SERVICES_BIND_PORT=<proxy port> TECHNICAL_ACCOUNT_PASSWORD=<username of the technical account which has access to all wms and mvt> TECHNICAL_ACCOUNT_USERNAME=<password of the technical account> ELASTICSEARCH_URL=<url of the elasticsearch instance> -PROXY_HOST_TARGET=<url of the map services> \ No newline at end of file +PROXY_HOST_TARGET=<url of the map services> +REDIS_MASTER_HOST=<host of the redis master> +REDIS_SENTINEL_PORT=<port of the redis sentinel> +REDIS_SENTINEL_HOST=<host of the redis sentinel> +REDIS_MASTER_SET=<name of the group of the different sentinels> +REDIS_AUTHORIZED_TTL=<time in seconds for which the key/value will be stored in redis when the user has access to the layer> +REDIS_UNAUTHORIZED_TTL=<Time in seconds for which the key/value pair will be stored in redis when the user doesn't have access to the layer> +ALLOW_EMPTY_PASSWORD=<whether empty password is allowed or not for redis, ex: 'yes'> \ No newline at end of file