Let me collect everything I’ve learned deploying Reference Application as docker. Not sure how much it can be applied to other distros.
The OpenMRS SDK has a build-distro goal, and it’s awesome It should work with any distro that uses a openmrs-distro.properties file:
mvn openmrs-sdk:build-distro -Ddistro=/path/to/openmrs-distro.properties
You have a lot of different options, including if the distributions plugins will be bundled. The maven goal will not only generate files to build the docker image, but also docker-compose files.
In the reference application maven lifecycle, we have that plugin as part of the default maven lifecycle.
In CI, after the mvn deploy
, we build the docker image and push to dockerhub as ‘nightly’ tag.
Build config
docker login -u <username> -p <password>
cd docker
docker build -t openmrs/openmrs-reference-application-distro:nightly .
docker push openmrs/openmrs-reference-application-distro:nightly
docker image inspect --format='{{index .RepoDigests 0}}' openmrs/openmrs-reference-application-distro:nightly > docker-image.txt
The last line will store the ID of the image in a file, so later on the pipeline we can deploy the same image with other tags.
We have a different docker tag per environment/server we have, so the version on each one is updated independently.
We are not using the docker-compose files generated by the SDK. Instead, I do have them in an ansible role. We create volumes for /usr/local/tomcat/.OpenMRS/
and database data. The docker compose should expose only openmrs port on the host, and the README file has more information.
To update the servers after a deployment, there are two ways:
I’m using nginx in front of docker:
Nginx vhost config
server {
listen 80;
server_name msf.openmrs.org;
index index.html index.htm;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name msf.openmrs.org;
index index.html index.htm;
access_log /var/log/nginx/msf_access.log;
error_log /var/log/nginx/msf_error.log;
ssl_certificate /etc/letsencrypt/live/<key>.openmrs.org/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/<key>.openmrs.org/privkey.pem;
location ^~ /.well-known/acme-challenge/ {
root /usr/share/nginx/html;
}
location / {
return 301 https://msf.openmrs.org/openmrs;
}
location /openmrs {
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://127.0.0.1:8080/openmrs;
}
}
The acme part relates to letsencrypt certificate.
The two set_headers redirect the original host used to reach nginx and the original scheme.
We are deploying all that using ansible.