Sign inSign up

digitalagendadata/nginx

By digitalagendadata

โ€ขUpdated over 5 years ago

Nginx image with geoip2 module and City, Country maps

Image
0

707

digitalagendadata/nginx repository overview

โ Scoreboard docker stack

Scoreboard docker setup

โ Scoreboard stack - first deploy steps

โ Clone repository locally:
git clone [email protected]:digital-agenda-data/scoreboard.docker.git

If it's already saved, make sure it's on the latest version

cd scoreboard.docker
git pull
โ Configuring the environment variables - .env file
โ Create the .env file from the appropriate .env. file
  • Production:
    cp .env.PROD .env
  • Test/Staging:
    cp .env.TEST .env
  • Development:
    cp .env.DEV .env
โ URLs
  1. DEPLOY_TYPE - should be set to TEST, PROD or DEV - will be used in NGINX, SOLR and CRONTAB configuration
  2. SCOREBOARDBASE_URL - the main domain name under which the site will be used:
    • FOR PRODUCTION it is digital-agenda-data.eu
    • For TEST it is test.digital-agenda-data.eu
    • For DEV it is dev.digital-agenda-data.eu
    • Note: to change these URLs, you must also edit nginx/project-${DEPLOY_TYPE} config files (nginx server_name and Plone VirtualHostBase)
  3. SPARQL_ENDPOINT - used by CR, is the way to access the SPARQL Virtuoso url both from the browser and the container.
  4. SCOREBOARD_URL - the main URL (the one that is accessed from the browser), used by Content Registry - example: https://digital-agenda-data.euโ , or http://test.digital-agenda-data.euโ  or http://dev.digital-agenda-data.eu:81โ 
โ VIRTUOSO DB PASSWORDS

If you are restoring the database from another environment, please copy here the same passwords that are saved in the database:

  1. VIRTUOSO_DBA_PASSWORD - dba user password
  2. CR_DB_PASSWORD - cr3user password
  3. CR_DB_RO_PASSWORD - cr3rouser password
โ MARIADB PASSWORDS
  1. MARIADB_PASSWORD - Mariadb root password
  2. MARIADB_PIWIK_PASSWORD - Mariadb piwik user password - save it for the PIWIK configuration
โ Other variables
  1. TZ - default Timezone for all containers - Europe/Copenhagen
  2. GEOIP_KEY - the license key for the geoip database, https://www.maxmind.com/en/geoip2-services-and-databasesโ 
โ Editing the docker-compose.yml file - NGINX port

You need to set the NGINX port to an available value in the docker-compose file. It is located in the nginx->ports section and has the format: - <HOST_PORT>:<CONTAINER_PORT>

For example, if port 81 is not available, but 82 is, we modify this:

  nginx:
    image: nginx:1.13
    depends_on:
    - haproxy
    - piwik
    - solr
    restart: always
    ports:
    - 81:80

into:

  nginx:
    image: nginx:1.13
    depends_on:
    - haproxy
    - piwik
    - solr
    restart: always
    ports:
    - 82:80
links:
- nginx:${SCOREBOARDBASE_URL}
โ Editing the docker-compose.yml file - plone image

If you want to deploy another version on plone site ( DEV or TEST) you need to set the correct image name in the plone section of the docker-compose.yml:

So:

  plone:
    image: digitalagendadata/plone:latest
    restart: always
    depends_on:
    - zeoserver
    - memcached
    environment:
      ZEO_ADDRESS: "zeoserver:8080"
      MEMCACHE_SERVER: "memcached:11211"
      SOLR_URL: "http://solr:8983/solr/scoreboard"

will become

  plone:
    image: digitalagendadata/plone.staging
    restart: always
    depends_on:
    - zeoserver
    - memcached
    environment:
      ZEO_ADDRESS: "zeoserver:8080"
      MEMCACHE_SERVER: "memcached:11211"
      SOLR_URL: "http://solr:8983/solr/scoreboard"
โ Prepare URLs: NGINX files and DNS or /etc/hosts entries:
โ PROD
  • digital-agenda-data.eu should be pointing to the server you are installing the stack in DNS
  • HTTPS and letsencrypt should be configured on the Apache that is installed on the same server
  • The Apache should redirect to the port configured to the nginx in the docker-compose fileโ 
โ TEST
  • test.digital-agenda-data.eu should be pointing to the server you are installing the stack in DNS
  • HTTPS and letsencrypt should be configured on the Apache that is installed on the same server
  • The Apache should redirect to the port configured to the nginx in the docker-compose fileโ 
โ DEV
  • <SCOREBOARDBASE_URL> host should be pointing to the server you are installing the stack in /etc/hosts
  • The configuration files from the repository are an example of a <SCOREBOARDBASE_URL> that is configured on a different port than 80
  • If you are changing the default URLs from the .env.DEV file, you also need to updated them accordingly in the NGINX configuration file - nginx/project-DEV.conf
โ Add SSH key to the cron container - Only on production

The exportcl.sh script that updates the RDF repositoryโ  runs daily on production. It needs to use a SSH private key that has write access to the GIT repo.

โ Copy existing SSH configurations from the current exportcl.sh host
  1. Connect to the existing host using the scoreboard user
  2. Copy the ~/.ssh contents
  3. Move them to the cron/ssh directory

If you are using the same user/host, you need just to:

 cd <SCOREBOARD.DOCKER_HOME>
 cp ~/.ssh/* cron/ssh/
 
โ Generate new key

Run in <SCOREBOARD.DOCKER_HOME>:

  1. Create a new key

     ssh-keygen -t rsa -b 4096 -C "[email protected]" -N '' -f cron/ssh/id_rsa
    
  2. Open the public key file an copy its contents:

     cat cron/ssh/id_rsa.pub 
    
  3. Copy the file contents in: https://github.com/digital-agenda-data/rdf/settings/keys/newโ 

  4. Keep the existing cron/ssh/known_hosts file because it contains the github servers

โ Start stack
โ PRODUCTION - multiple plone servers
docker-compose up -d --scale plone=2
โ DEV, TEST - one plone server
docker-compose up -d
โ Import data
โ Import plone data
  1. Identify zeo docker name - <ZEO_DOCKER_NAME>:

    docker-compose ps | grep zeo

  2. Copy blobstorage and filestorage directories from the source plone site and put it into the current directory

  3. Copy blobstorage and filestorage directories to the zeoserver data volume:

    docker cp blobstorage <ZEO_DOCKER_NAME>:/data/ docker cp filestorage <ZEO_DOCKER_NAME>:/data/

  4. Run chown on the /data directory from the server to make sure all the files have the correct permissions docker-compose exec zeoserver sh -c "chown -R 500:500 /data"

  5. Restart zeoserver

    docker-compose restart zeoserver

  6. Check zeoserver logs for errors

    docker-compose logs -f zeoserver

  7. Restart plone

    docker-compose restart plone

  8. Check plone logs for errors

    docker-compose logs -f plone

โ Import virtuoso db data
  1. Stop virtuoso server

    docker-compose stop virtuoso

  2. Identify virtuoso docker name - <VIRTUOSO_DOCKER_NAME> ( check first column on the following command) :

    docker-compose ps | grep virtuoso

  3. Copy database backup from source database and name it virtuoso.db

  4. Identify volume location on the host - <VIRTUOSO_VOLUME_PATH>

    docker inspect <VIRTUOSO_DOCKER_NAME> | grep volume

or

docker ps --filter expose=8890 --format "{{.Names}}" | xargs docker inspect | grep virtuoso_db

โ TODO: rewrite so it works also on Windows

<VIRTUOSO_VOLUME_PATH> should be similar to /var/lib/docker/volumes/_virtuoso_db/_data

  1. Clean-up the volume:

    sudo rm -rf <VIRTUOSO_VOLUME_PATH>/*

  2. Copy the database:

    sudo cp virtuoso.db <VIRTUOSO_VOLUME_PATH>/

  3. Start server

    docker-compose start virtuoso

  4. Check virtuoso logs for errors

    docker-compose logs -f virtuoso

โ Import CR data
โ Import PIWIK data - MARIADB
  1. Run a backup on the source database. If you are not sure of the database password you can check it in the piwik directory: $ cd <PIWIK_LOCATION> $ grep password config/config.ini.php

  2. Run the piwik database backup, providing the password: $ mysqldump -u piwik -p piwik > /tmp/piwik.dump

  3. Copy the database dump to the destination host using scpโ 

  4. Identify the docker name of the mariadb container <MARIADB_DOCKER_NAME> ( run from the docker-compose.yml file location ) docker-compose ps | grep virtuoso

  5. copy the database dump to the mariadb container
    docker cp piwik.dump <MARIADB_DOCKER_NAME>:/tmp/piwik.dump

  6. Import the database, providing the password set in the .env file: $ docker-compose exec mariadb bash $ mysql -u piwik -p piwik < /tmp/piwik.dump Enter password: $ exit

  7. Restart the container and watch the logs for errors $ docker-compose restart mariadb $ docker-compose logs -f mariadb

โ Content registry configuration
  1. Go to the init script location $ cd cr_init_scripts
  • If you did not import the database, you need to run: $ ./init_conreg.sh
  • If you imported the database so all the users are already created, you need to run:
    $ ./init_conreg_db_restore.sh
โ Piwik configuration
  1. Go to <SCOREBOARD_URL>/analytics/piwik/index.php?action=databaseSetup
  2. Fill:
  • Database Server -db
  • Login - piwik
  • Password - <MARIADB_PIWIK_PASSWORD>
  • Database Name - piwik
  • Table Prefix - piwik_
  • Adapter - PDO\MYSQL
  1. Press Next
  2. You will receive the message: Some tables in your database have the same names as the tables Matomo is trying to create Press Reuse the existing tables ยป
  3. You will receive - Reusing the Tables - Press Next
  4. Press CONTINUE TO MATOMO
  5. Remember to configure the tracking url in Plone (<SCOREBOARD_URL>/portal_skins/custom/analytics.js/manage_main)
โ Available URLs
  1. Plone - <SCOREBOARD_URL>
  2. Virtuoso faceted browser - always http://semantic.digital-agenda-data.eu/datasetโ  (must be added in /etc/hosts for local development)
  3. Content Registry - <SCOREBOARD_URL>/data/
  4. Download - <SCOREBOARD_URL>/datasets/desi#download
  5. Sparql - <SCOREBOARD_URL>/sparql
  6. Piwik - <SCOREBOARD_URL>/analytics/index.php

โ Scoreboard stack - upgrade

โ Pull the latest repository version
โ If needed, update the images in docker-compose.yml

Manually modify docker-compose.yml with the new image version.

For example:

  plone:
    image: digitalagendadata/plone:1.0

to

  plone:
    image: digitalagendadata/plone:2.0

If you are updating the PRODUCTION image version, you need to save the changes in GITโ 

โ Update the environment variables values

Change environment variable value in the .env file.

โ Update the configuration files

Update the available configuration files. Any update on PRODUCTION and TEST environments for cron/, solr/, nginx/* should be saved in GITโ .

โ Upgrade an existing stack
โ Restart stack for configuration file changes:

If you only changed the configuration file, it's enough to run restart on the containers:

  • For cron/ changes:

      docker-compose restart cron
    
  • For nginx/ changes:

      docker-compose restart nginx
    
  • For solr/ changes:

      docker-compose restart solr
    
โ Upgrade stack for environment or docker-compose.yml changes:

First you should take note how many plone instances you have running:

  docker-compose ps | grep -c plone

Use the number of running instances to run the upgrade:

  docker-compose up -d --scale plone=<NUMBER_OF_PLONE_INSTANCES>
 
  

โ Docker images release

โ To release a new Crontab image

The docker hub automated build can be found on https://hub.docker.com/r/digitalagendadata/scoreboard.cron/โ 

The steps to create a new release, follow this steps on your Dev environment:

  1. Update files located in crontab directoryโ  - docker image files and cron directoryโ  - scripts and crontab files )

  2. Push the changes on master

    git add -A
    git commit
    git push
    
  3. On every push to the master branch, a new digitalagendadata/scoreboard.cron:latest image is created. You can view the build status on: https://hub.docker.com/r/digitalagendadata/scoreboard.cron/builds/โ 

  4. Once the digitalagendadata/scoreboard.cron:latest image is succesfully built, you can test ( if needed ), and then create a new release.

  5. View most recent tag on git:

     git describe --tags
     
    
  6. Choose a new tag, bigger than the latest one, using a MAJOR.MINOR format. Save it in a variable:

    export NEW_TAG="<NEW_TAG>"
    
  7. Create and push tag on repo:

    git tag -a "$NEW_TAG" -m "$NEW_TAG"
    git push origin $NEW_TAG
    
  8. Follow the release on docker hub https://hub.docker.com/r/digitalagendadata/scoreboard.cron/builds/โ . The new image will have the following format:

    digitalagendadata/scoreboard.cron:$NEW_TAG
    
  9. Update docker-compose.yml with the new image:

    sed -i 's/image: digitalagendadata\/scoreboard.cron.*/image: digitalagendadata\/scoreboard.cron:$NEW_TAG/' docker-compose.yml
    
  10. Push the change on the GIT repo:

    git add docker-compose.yml
    git commit -m "Updated cron image to $NEW_TAG"
    git push
    
โ To release a new Elda image

The docker hub automated build can be found on https://hub.docker.com/r/digitalagendadata/scoreboard.elda/โ 

The steps to create a new release, follow this steps on your Dev environment:

  1. Update files located in elda directoryโ 

  2. Push the changes on master

    git add -A
    git commit
    git push
    
  3. On every push to the master branch, a new digitalagendadata/scoreboard.elda:latest image is created. You can view the build status on: https://hub.docker.com/r/digitalagendadata/scoreboard.elda/builds/โ 

  4. Once the digitalagendadata/scoreboard.elda:latest image is succesfully built, you can test ( if needed ), and then create a new release.

  5. View most recent tag on git:

     git describe --tags
     
    
  6. Choose a new tag, bigger than the latest one, using a MAJOR.MINOR format. Save it in a variable:

    export NEW_TAG="<NEW_TAG>"
    
  7. Create and push tag on repo:

    git tag -a "$NEW_TAG" -m "$NEW_TAG"
    git push origin $NEW_TAG
    
  8. Follow the release on docker hub https://hub.docker.com/r/digitalagendadata/scoreboard.elda/builds/โ . The new image will have the following format:

    digitalagendadata/scoreboard.elda:$NEW_TAG
    
  9. Update docker-compose.yml with the new image:

    sed -i 's/image: digitalagendadata\/scoreboard.elda.*/image: digitalagendadata\/scoreboard.elda:$NEW_TAG/' docker-compose.yml
    
  10. Push the change on the GIT repo:

    git add docker-compose.yml
    git commit -m "Updated elda image to $NEW_TAG"
    git push
    
โ To release a new Plone image

The docker hub automated build for the production plone images can be found:

โ Create a new plone production release:
  1. Update files in https://github.com/digital-agenda-data/scoreboard.docker/tree/master/ploneโ  directory

  2. Push the changes on master

    git add -A
    git commit
    git push
    
  3. On every push to the master branch, a new digitalagendadata/plone:latest image is created. You can view the build status on: https://hub.docker.com/r/digitalagendadata/plone/builds/โ .

  4. View most recent tag on git:

     git describe --tags
     
    
  5. Choose a new tag, bigger than the latest one, using a MAJOR.MINOR format. Save it in a variable:

    export NEW_TAG="<NEW_TAG>"
    
  6. Create and push tag on repo:

    git tag -a "$NEW_TAG" -m "$NEW_TAG"
    git push origin $NEW_TAG
    
  7. Follow the release on docker hub https://hub.docker.com/r/digitalagendadata/plone/builds/โ . The new image will have the following format:

    digitalagendadata/plone:$NEW_TAG
    
  8. Update docker-compose.yml with the new image:

    sed -i 's/image: digitalagendadata\/plone.*/image: digitalagendadata\/plone:$NEW_TAG/' docker-compose.yml
    
  9. Push the change on the GIT repo:

    git add docker-compose.yml
    git commit -m "Updated plone image to $NEW_TAG"
    git push
    
โ Create a new plone staging image:

The docker image is based on the digitalagendadata/plone:latest image. To reduce the image building time, if you need to do changes on production and on the staging image, try to combine them in a single commit.

  1. Update files in the https://github.com/digital-agenda-data/scoreboard.docker/tree/master/plone/stagingโ  directory

  2. Push the changes on master

    git add -A
    git commit
    git push
    
  3. On every push to the master branch, a new digitalagendadata/plone:latest image is created. You can view the build status on: https://hub.docker.com/r/digitalagendadata/plone/builds/โ . After the image is created, a new build will be started on https://hub.docker.com/r/digitalagendadata/plone.staging/builds/โ 

โ Create a new plone devel image:

The docker image is based on the digitalagendadata/plone:latest image. To reduce the image building time, if you need to do changes on production and on the devel image, try to combine them in a single commit.

  1. Update files in the https://github.com/digital-agenda-data/scoreboard.docker/tree/master/plone/develโ  directory

  2. Push the changes on master

    git add -A
    git commit
    git push
    
  3. On every push to the master branch, a new digitalagendadata/plone:latest image is created. You can view the build status on: https://hub.docker.com/r/digitalagendadata/plone/builds/โ . After the image is created, a new build will be started on https://hub.docker.com/r/digitalagendadata/plone.devel/builds/โ 

โ Tips

โ Plone CSS

If CSS does not look right on the Plone site: <SCOREBOARD_URL>/portal_css/manage_cssForm - Uncheck reset.css and click SAVE

โ Configure PIWIK performance
  • If you find in piwik/matomo logs this message: server reached pm.max_children setting or you want to offer a better performace of the web application, you will need to update the pm.max_children, pm.start_servers, pm.min_spare_servers and pm.max_spare_servers values in the corresponding www-DEPLOY_TYPE.conf configuration file located in the piwik/ directory and restart the container.

Tag summary

Content type

Image

Digest

Size

156 MB

Last updated

over 5 years ago

docker pull digitalagendadata/nginx