-
Notifications
You must be signed in to change notification settings - Fork 0
QE-746 As a QE member, I want to containerize Postgres Database clust… #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,8 @@ open class DeployDockerClusterHelper(val project: Project) { | |
| companion object { | ||
| private const val clusterMetadataPath = "deploy/cluster/cluster-metadata.properties" | ||
| private const val dockerXldHAPath = "deploy/cluster/docker-compose-xld-ha.yaml" | ||
| private const val dockerXldHAWithDbLoadbalancerPath = | ||
| "deploy/cluster/cluster-with-db-loadbalancer/docker-compose-xld-ha-with-db-loadbalancer.yaml" | ||
| private const val dockerXldHAWithWorkersPath = "deploy/cluster/docker-compose-xld-ha-slim-workers.yaml" | ||
| private const val rabbitMqEnabledPluginsPath = "deploy/cluster/rabbitmq/enabled_plugins" | ||
| private const val privateDebugPort = 4005 | ||
|
|
@@ -45,6 +47,10 @@ open class DeployDockerClusterHelper(val project: Project) { | |
| return server.version | ||
| } | ||
|
|
||
| private fun isDatabaseLoadBalancerEnabled(): Boolean { | ||
| return DeployServerUtil.getCluster(project).enableDatabaseLoadBalancer | ||
| } | ||
|
|
||
| private fun getServers(): List<Server> { | ||
| return DeployExtensionUtil.getExtension(project).servers | ||
| .filter { server -> !server.previousInstallation } | ||
|
|
@@ -71,6 +77,14 @@ open class DeployDockerClusterHelper(val project: Project) { | |
| return "${worker.dockerImage}:${getClusterVersion()}" | ||
| } | ||
|
|
||
| private fun getWorkerJdbcUrl(): String { | ||
| var workerJdbcUrl = "postgresql:5432/xld-db" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is already not correct, as it depends what database is used, and this config has to be configurable. |
||
| if (isDatabaseLoadBalancerEnabled()) { | ||
| workerJdbcUrl = "haproxydb:5000/postgres" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, hard coded url is not acceptable. |
||
| } | ||
| return workerJdbcUrl | ||
| } | ||
|
|
||
| private fun configureRabbitMq() { | ||
| val dockerComposeStream = {}::class.java.classLoader.getResourceAsStream(rabbitMqEnabledPluginsPath) | ||
| val resultComposeFilePath = | ||
|
|
@@ -93,7 +107,10 @@ open class DeployDockerClusterHelper(val project: Project) { | |
| } | ||
|
|
||
| private fun getResolvedXldHaDockerComposeFile(): Path { | ||
| val template = getTemplate(dockerXldHAPath) | ||
| var template = getTemplate(dockerXldHAPath) | ||
| if (isDatabaseLoadBalancerEnabled()) { | ||
| template = getTemplate(dockerXldHAWithDbLoadbalancerPath) | ||
| } | ||
| val serviceName = "xl-deploy-master" | ||
|
|
||
| val configuredTemplate = template.readText(Charsets.UTF_8) | ||
|
|
@@ -120,6 +137,7 @@ open class DeployDockerClusterHelper(val project: Project) { | |
| .replace("{{DEPLOY_WORKER_IMAGE}}", getWorkerVersionedImage()) | ||
| .replace("{{INTEGRATION_SERVER_ROOT_VOLUME}}", IntegrationServerUtil.getDist(project)) | ||
| .replace("{{DEPLOY_NETWORK_NAME}}", ClusterConstants.NETWORK_NAME) | ||
| .replace("{{JDBC_URL}}", getWorkerJdbcUrl()) | ||
|
|
||
| template.writeText(configuredTemplate) | ||
| overrideWorkerCommand(template) | ||
|
|
@@ -265,6 +283,10 @@ open class DeployDockerClusterHelper(val project: Project) { | |
| } | ||
|
|
||
| private fun getMasterIp(order: Int): String { | ||
| var masterContainerName = "cluster-xl-deploy-master-" | ||
| if (isDatabaseLoadBalancerEnabled()) { | ||
| masterContainerName = "cluster-with-db-loadbalancer_xl-deploy-master_" | ||
| } | ||
| try { | ||
| return DockerUtil.inspect(project, | ||
| "{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}", | ||
|
|
@@ -273,7 +295,7 @@ open class DeployDockerClusterHelper(val project: Project) { | |
| // fallback in naming | ||
| return DockerUtil.inspect(project, | ||
| "{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}", | ||
| "cluster-xl-deploy-master-${order}") | ||
| "${masterContainerName}${order}") | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| version: "3.4" | ||
|
|
||
| services: | ||
| zoo1: | ||
| image: zookeeper:3.4 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. has to be configurable |
||
| hostname: zoo1 | ||
| container_name: zoo1 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not the best names even for default value, and they should be also configurable |
||
| ports: | ||
| - 2191:2181 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In all this file, all ports which are exposed have to be configurable. |
||
| networks: | ||
| - {{DEPLOY_NETWORK_NAME}} | ||
| environment: | ||
| ZOO_MY_ID: 1 | ||
| ZOO_SERVERS: server.1=0.0.0.0:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888 | ||
|
|
||
| zoo2: | ||
| image: zookeeper:3.4 | ||
| hostname: zoo2 | ||
| container_name: zoo2 | ||
| ports: | ||
| - 2192:2181 | ||
| networks: | ||
| - {{DEPLOY_NETWORK_NAME}} | ||
| environment: | ||
| ZOO_MY_ID: 2 | ||
| ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=0.0.0.0:2888:3888 server.3=zoo3:2888:3888 | ||
| depends_on: | ||
| - zoo1 | ||
|
|
||
| zoo3: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The number of nodes and partitions have to be configurable. |
||
| image: zookeeper:3.4 | ||
| hostname: zoo3 | ||
| container_name: zoo3 | ||
| ports: | ||
| - 2193:2181 | ||
| networks: | ||
| - {{DEPLOY_NETWORK_NAME}} | ||
| environment: | ||
| ZOO_MY_ID: 3 | ||
| ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=0.0.0.0:2888:3888 | ||
| depends_on: | ||
| - zoo2 | ||
|
|
||
| patroni1: | ||
| build: | ||
| context: patroni | ||
| dockerfile: Dockerfile | ||
| container_name: patroni1 | ||
| ports: | ||
| - 8091:8091 | ||
| networks: | ||
| - {{DEPLOY_NETWORK_NAME}} | ||
| hostname: patroni1 | ||
| environment: | ||
| PATRONI_API_CONNECT_PORT: 8091 | ||
| REPLICATION_NAME: replicator | ||
| REPLICATION_PASS: replicator | ||
| SU_NAME: postgres | ||
| SU_PASS: admin | ||
| POSTGRES_APP_ROLE_PASS: postgresconnect | ||
| depends_on: | ||
| - zoo3 | ||
|
|
||
| patroni2: | ||
| build: | ||
| context: patroni | ||
| dockerfile: Dockerfile | ||
| container_name: patroni2 | ||
| ports: | ||
| - 8092:8091 | ||
| networks: | ||
| - {{DEPLOY_NETWORK_NAME}} | ||
| hostname: patroni2 | ||
| environment: | ||
| PATRONI_API_CONNECT_PORT: 8091 | ||
| REPLICATION_NAME: replicator | ||
| REPLICATION_PASS: replicator | ||
| SU_NAME: postgres | ||
| SU_PASS: admin | ||
| POSTGRES_APP_ROLE_PASS: postgresconnect | ||
| depends_on: | ||
| - patroni1 | ||
|
|
||
| haproxydb: | ||
| build: | ||
| context: haproxy | ||
| dockerfile: Dockerfile | ||
| container_name: haproxydb | ||
| networks: | ||
| - {{DEPLOY_NETWORK_NAME}} | ||
| hostname: haproxydb | ||
| ports: | ||
| - 5000:5000 | ||
| - 7000:7000 | ||
| depends_on: | ||
| - patroni2 | ||
|
|
||
| rabbitmq: | ||
| image: "rabbitmq:3.9.8-management-alpine" | ||
| container_name: rabbitmq | ||
| hostname: "rabbit" | ||
| ports: | ||
| - "5672:5672" | ||
| - "4369:4369" | ||
| - "25672:25672" | ||
| - "15672:15672" | ||
| networks: | ||
| - {{DEPLOY_NETWORK_NAME}} | ||
| labels: | ||
| NAME: "rabbitmq" | ||
| environment: | ||
| RABBITMQ_DEFAULT_USER: rabbitmq | ||
| RABBITMQ_DEFAULT_PASS: admin | ||
| RABBITMQ_LOOPBACK_USERS: none | ||
| volumes: | ||
| - {{INTEGRATION_SERVER_ROOT_VOLUME}}/rabbitmq:/etc/rabbitmq | ||
|
|
||
| xl-deploy-master: | ||
| image: {{DEPLOY_MASTER_IMAGE}} | ||
| depends_on: | ||
| - rabbitmq | ||
| - haproxydb | ||
| networks: | ||
| - {{DEPLOY_NETWORK_NAME}} | ||
| environment: | ||
| - ACCEPT_EULA=Y | ||
| - ADMIN_PASSWORD=admin | ||
| - FORCE_UPGRADE=true | ||
| - XL_CLUSTER_MODE=default | ||
| - XL_DB_PASSWORD=admin | ||
| - XL_DB_USERNAME=postgres | ||
| - XL_DB_URL=jdbc:postgresql://haproxydb:5000/postgres | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not good |
||
| - XLD_IN_PROCESS=false | ||
| - XLD_TASK_QUEUE_DRIVER_CLASS_NAME=com.rabbitmq.jms.admin.RMQConnectionFactory | ||
| - XLD_TASK_QUEUE_PASSWORD=admin | ||
| - XLD_TASK_QUEUE_USERNAME=rabbitmq | ||
| - XLD_TASK_QUEUE_URL=amqp://rabbitmq:5672 | ||
| - USE_IP_AS_HOSTNAME=true | ||
| volumes: | ||
| - {{INTEGRATION_SERVER_ROOT_VOLUME}}/xl-deploy-server/centralConfiguration:/opt/xebialabs/xl-deploy-server/centralConfiguration | ||
| - {{INTEGRATION_SERVER_ROOT_VOLUME}}/xl-deploy-server/conf:/opt/xebialabs/xl-deploy-server/conf | ||
| - {{INTEGRATION_SERVER_ROOT_VOLUME}}/xl-deploy-server/plugins:/opt/xebialabs/xl-deploy-server/plugins | ||
|
|
||
| xl-deploy-lb: | ||
| image: xebialabsunsupported/haproxy | ||
| container_name: xl-deploy-lb | ||
| depends_on: | ||
| - xl-deploy-master | ||
| ports: | ||
| - "{{PUBLIC_PORT}}:5000" | ||
| - "1936:1936" | ||
| networks: | ||
| - {{DEPLOY_NETWORK_NAME}} | ||
| environment: | ||
| BACKENDS: "xl-deploy-master:4516" | ||
| HTTPCHK: "GET /deployit/ha/health" | ||
| DNS_ENABLED: "true" | ||
| COOKIES_ENABLED: "true" | ||
| COOKIES_PARAMS: "SESSION_XLD prefix" | ||
| LOG_LEVEL: "info" | ||
| TIMEOUT_CONNECT: 60000 | ||
|
|
||
| networks: | ||
| {{DEPLOY_NETWORK_NAME}}: | ||
| external: true | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| FROM haproxy:latest | ||
| COPY dbhaproxy.cfg /usr/local/etc/haproxy/haproxy.cfg | ||
| USER root | ||
| RUN mkdir /run/haproxy &&\ | ||
| apt-get update -y &&\ | ||
| apt-get install -y hatop &&\ | ||
| apt-get install -y postgresql-client &&\ | ||
| apt-get clean | ||
| RUN chmod 777 /run/haproxy/ | ||
| COPY entrypoint.sh /docker-entrypoint.sh | ||
| RUN chmod 755 /docker-entrypoint.sh | ||
| ENTRYPOINT ["/docker-entrypoint.sh"] | ||
| USER haproxy | ||
| CMD ["haproxy", "-f", "/usr/local/etc/haproxy/haproxy.cfg"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| global | ||
| maxconn 100 | ||
| stats socket /run/haproxy/haproxy.sock | ||
| stats timeout 2m # Wait up to 2 minutes for input | ||
|
|
||
| defaults | ||
| log global | ||
| mode tcp | ||
| retries 2 | ||
| timeout client 30m | ||
| timeout connect 4s | ||
| timeout server 30m | ||
| timeout check 5s | ||
|
|
||
| listen stats | ||
| mode http | ||
| bind *:7000 | ||
| stats enable | ||
| stats uri / | ||
|
|
||
| listen postgres | ||
| bind *:5000 | ||
| option httpchk | ||
| http-check expect status 200 | ||
| default-server inter 3s fall 3 rise 2 on-marked-down shutdown-sessions | ||
| server patroni1 patroni1:5432 maxconn 100 check port 8091 | ||
| server patroni2 patroni2:5432 maxconn 100 check port 8091 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #!/bin/sh | ||
| set -e | ||
|
|
||
| # first arg is `-f` or `--some-option` | ||
| if [ "${1#-}" != "$1" ]; then | ||
| set -- haproxy "$@" | ||
| fi | ||
|
|
||
| if [ "$1" = 'haproxy' ]; then | ||
| shift | ||
| set -- haproxy -W -db "$@" | ||
| fi | ||
| sleep 15 | ||
| export PGPASSWORD=admin | ||
| exec "$@" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| FROM postgres:12.7 | ||
|
|
||
| RUN apt-get update -y\ | ||
| && apt-get install python3 python3-pip -y\ | ||
| && apt-get install python3-dev libpq-dev -y\ | ||
| && pip3 install --upgrade pip\ | ||
| && pip3 install --upgrade setuptools\ | ||
| && pip3 install psycopg2-binary \ | ||
| && pip3 install patroni[zookeeper] \ | ||
| && mkdir /data/patroni -p \ | ||
| && chown postgres:postgres /data/patroni \ | ||
| && chmod 700 /data/patroni | ||
|
|
||
| #Copy patroni config files | ||
| COPY patroni.yaml /etc/patroni.yml | ||
|
|
||
| #Copy entrypoint1.sh file | ||
| COPY entrypoint.sh ./entrypoint.sh | ||
|
|
||
| USER postgres | ||
| ENTRYPOINT ["bin/sh", "/entrypoint.sh"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #!/bin/sh | ||
|
|
||
| readonly CONTAINER_IP=$(hostname --ip-address) | ||
| readonly CONTAINER_API_ADDR="${CONTAINER_IP}:${PATRONI_API_CONNECT_PORT}" | ||
| readonly CONTAINER_POSTGRE_ADDR="${CONTAINER_IP}:5432" | ||
|
|
||
| export PATRONI_NAME="${PATRONI_NAME:-$(hostname)}" | ||
| export PATRONI_RESTAPI_CONNECT_ADDRESS="$CONTAINER_API_ADDR" | ||
| export PATRONI_RESTAPI_LISTEN="$CONTAINER_API_ADDR" | ||
| export PATRONI_POSTGRESQL_CONNECT_ADDRESS="$CONTAINER_POSTGRE_ADDR" | ||
| export PATRONI_POSTGRESQL_LISTEN="$CONTAINER_POSTGRE_ADDR" | ||
| export PATRONI_REPLICATION_USERNAME="$REPLICATION_NAME" | ||
| export PATRONI_REPLICATION_PASSWORD="$REPLICATION_PASS" | ||
| export PATRONI_SUPERUSER_USERNAME="$SU_NAME" | ||
| export PATRONI_SUPERUSER_PASSWORD="$SU_PASS" | ||
| export PATRONI_approle_PASSWORD="$POSTGRES_APP_ROLE_PASS" | ||
| export PATRONI_approle_OPTIONS="${PATRONI_admin_OPTIONS:-createdb, createrole}" | ||
|
|
||
| chmod 700 /var/lib/postgresql/data/ | ||
| exec /usr/local/bin/patroni /etc/patroni.yml | ||
|
|
||
|
|
||
| exit 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no documentation about it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And please create a blog post for that to explain on the high level how it works.