Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Standalone #6

Merged
merged 3 commits into from May 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions Dockerfile
Expand Up @@ -17,12 +17,12 @@ RUN apk add --no-cache ca-certificates openssl

RUN rabbitmq-plugins enable --offline rabbitmq_federation rabbitmq_federation_management rabbitmq_shovel rabbitmq_shovel_management

COPY entrypoint.sh /usr/local/bin/ega-entrypoint.sh
COPY entrypoint.sh /usr/local/bin/docker-entrypoint.sh

RUN chmod +x /usr/local/bin/ega-entrypoint.sh
RUN chmod +x /usr/local/bin/docker-entrypoint.sh

USER 100:101

ENTRYPOINT ["/usr/local/bin/ega-entrypoint.sh"]
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]

CMD ["rabbitmq-server"]
279 changes: 257 additions & 22 deletions entrypoint.sh
Expand Up @@ -2,7 +2,6 @@

[ -z "${MQ_USER}" ] && echo 'Environment variable MQ_USER is empty' 1>&2 && exit 1
[ -z "${MQ_PASSWORD_HASH}" ] && echo 'Environment variable MQ_PASSWORD_HASH is empty' 1>&2 && exit 1
[ -z "${CEGA_CONNECTION}" ] && echo 'Environment variable CEGA_CONNECTION is empty' 1>&2 && exit 1

if [ -z "${MQ_SERVER_CERT}" ] || [ -z "${MQ_SERVER_KEY}" ]; then
SSL_SUBJ="/C=SE/ST=Sweden/L=Uppsala/O=NBIS/OU=SysDevs/CN=LocalEGA"
Expand All @@ -12,7 +11,7 @@ openssl req -x509 -newkey rsa:2048 \
-keyout "/var/lib/rabbitmq/ssl/mq-server.key" -nodes \
-out "/var/lib/rabbitmq/ssl/mq-server.pem" -sha256 \
-days 1000 -subj "${SSL_SUBJ}" && \
chmod 600 "/var/lib/rabbitmq/ssl/mq-server.*"
chmod 600 /var/lib/rabbitmq/ssl/mq-server.*
fi

cat >> "/var/lib/rabbitmq/rabbitmq.conf" <<EOF
Expand All @@ -31,55 +30,132 @@ EOF

chmod 600 "/var/lib/rabbitmq/rabbitmq.conf"

if [ -n "${CEGA_CONNECTION}" ]; then
cat > "/var/lib/rabbitmq/definitions.json" <<EOF
{
"users": [
{
"name": "${MQ_USER}", "password_hash": "${MQ_PASSWORD_HASH}",
"hashing_algorithm": "rabbit_password_hashing_sha256", "tags": "administrator"
"name": "${MQ_USER}",
"password_hash": "${MQ_PASSWORD_HASH}",
"hashing_algorithm": "rabbit_password_hashing_sha256",
"tags": "administrator"
}
],
"vhosts": [
{ "name": "${MQ_VHOST:-/}" }
{
"name": "${MQ_VHOST:-/}"
}
],
"permissions": [
{ "user": "${MQ_USER}", "vhost": "${MQ_VHOST:-/}", "configure": ".*", "write": ".*", "read": ".*" }
{
"user": "${MQ_USER}",
"vhost": "${MQ_VHOST:-/}",
"configure": ".*",
"write": ".*",
"read": ".*"
}
],
"parameters": [
{
"name": "CEGA-ids", "vhost": "${MQ_VHOST:-/}", "component": "federation-upstream",
"value": { "ack-mode": "on-confirm", "queue": "v1.stableIDs", "trust-user-id": false, "uri": "${CEGA_CONNECTION}" }
"name": "CEGA-ids",
"vhost": "${MQ_VHOST:-/}",
"component": "federation-upstream",
"value": {
"ack-mode": "on-confirm",
"queue": "v1.stableIDs",
"trust-user-id": false,
"uri": "${CEGA_CONNECTION}"
}
},
{
"name": "CEGA-files", "vhost": "${MQ_VHOST:-/}", "component": "federation-upstream",
"value": { "ack-mode": "on-confirm", "queue": "v1.files", "trust-user-id": false, "uri": "${CEGA_CONNECTION}" }
"name": "CEGA-files",
"vhost": "${MQ_VHOST:-/}",
"component": "federation-upstream",
"value": {
"ack-mode": "on-confirm",
"queue": "v1.files",
"trust-user-id": false,
"uri": "${CEGA_CONNECTION}"
}
}
],
"policies": [
{
"vhost": "${MQ_VHOST:-/}", "name": "CEGA-files", "pattern": "files", "apply-to": "queues", "priority": 0,
"definition": { "federation-upstream": "CEGA-files" }
"vhost": "${MQ_VHOST:-/}",
"name": "CEGA-files",
"pattern": "files",
"apply-to": "queues",
"priority": 0,
"definition": {
"federation-upstream": "CEGA-files"
}
},
{
"vhost": "${MQ_VHOST:-/}", "name": "CEGA-ids", "pattern": "stableIDs", "apply-to": "queues", "priority": 0,
"definition": { "federation-upstream": "CEGA-ids" }
"vhost": "${MQ_VHOST:-/}",
"name": "CEGA-ids",
"pattern": "stableIDs",
"apply-to": "queues",
"priority": 0,
"definition": {
"federation-upstream": "CEGA-ids"
}
}
],
"queues": [
{"name": "stableIDs", "vhost": "${MQ_VHOST:-/}", "durable": true, "auto_delete": false, "arguments":{}},
{"name": "files", "vhost": "${MQ_VHOST:-/}", "durable": true, "auto_delete": false, "arguments":{}},
{"name": "archived", "vhost": "${MQ_VHOST:-/}", "durable": true, "auto_delete": false, "arguments":{}}
{
"name": "stableIDs",
"vhost": "${MQ_VHOST:-/}",
"durable": true,
"auto_delete": false,
"arguments": {}
},
{
"name": "files",
"vhost": "${MQ_VHOST:-/}",
"durable": true,
"auto_delete": false,
"arguments": {}
},
{
"name": "archived",
"vhost": "${MQ_VHOST:-/}",
"durable": true,
"auto_delete": false,
"arguments": {}
}
],
"exchanges": [
{"name":"cega", "vhost":"${MQ_VHOST:-/}", "type":"topic", "durable":true, "auto_delete":false, "internal":false, "arguments":{}},
{"name":"lega", "vhost":"${MQ_VHOST:-/}", "type":"topic", "durable":true, "auto_delete":false, "internal":false, "arguments":{}}
],
{
"name": "cega",
"vhost": "${MQ_VHOST:-/}",
"type": "topic",
"durable": true,
"auto_delete": false,
"internal": false,
"arguments": {}
},
{
"name": "lega",
"vhost": "${MQ_VHOST:-/}",
"type": "topic",
"durable": true,
"auto_delete": false,
"internal": false,
"arguments": {}
}
],
"bindings": [
{ "source":"lega", "vhost": "${MQ_VHOST:-/}", "destination":"archived", "destination_type":"queue", "routing_key":"archived", "arguments":{}}
{
"source": "lega",
"vhost": "${MQ_VHOST:-/}",
"destination": "archived",
"destination_type": "queue",
"routing_key": "archived",
"arguments": {}
}
]
}
EOF
chmod 600 "/var/lib/rabbitmq/definitions.json"

if [ -n "${MQ_VHOST}" ];then
MQ_VHOST="/${MQ_VHOST}"
Expand Down Expand Up @@ -145,5 +221,164 @@ cat > "/var/lib/rabbitmq/advanced.config" <<EOF
].
EOF
chmod 600 "/var/lib/rabbitmq/advanced.config"
else
cat > "/var/lib/rabbitmq/definitions.json" <<EOF
{
"rabbit_version": "3.7",
"users": [
{
"name": "${MQ_USER}",
"password_hash": "${MQ_PASSWORD_HASH}",
"hashing_algorithm": "rabbit_password_hashing_sha256",
"tags": "administrator"
}
],
"vhosts": [
{
"name": "${MQ_VHOST:-/}"
}
],
"permissions": [
{
"user": "${MQ_USER}",
"vhost": "${MQ_VHOST:-/}",
"configure": ".*",
"write": ".*",
"read": ".*"
}
],
"parameters": [],
"global_parameters": [
{
"name": "cluster_name",
"value": "rabbit@localhost"
}
],
"policies": [],
"queues": [
{
"name": "archived",
"vhost": "${MQ_VHOST:-/}",
"durable": true,
"auto_delete": false,
"arguments": {}
},
{
"name": "files",
"vhost": "${MQ_VHOST:-/}",
"durable": true,
"auto_delete": false,
"arguments": {}
},
{
"name": "files.completed",
"vhost": "${MQ_VHOST:-/}",
"durable": true,
"auto_delete": false,
"arguments": {}
},
{
"name": "files.error",
"vhost": "${MQ_VHOST:-/}",
"durable": true,
"auto_delete": false,
"arguments": {}
},
{
"name": "files.inbox",
"vhost": "${MQ_VHOST:-/}",
"durable": true,
"auto_delete": false,
"arguments": {}
},
{
"name": "files.processing",
"vhost": "${MQ_VHOST:-/}",
"durable": true,
"auto_delete": false,
"arguments": {}
},
{
"name": "stableIDs",
"vhost": "${MQ_VHOST:-/}",
"durable": true,
"auto_delete": false,
"arguments": {}
},
],
"exchanges": [
{
"name": "lega",
"vhost": "${MQ_VHOST:-/}",
"type": "topic",
"durable": true,
"auto_delete": false,
"internal": false,
"arguments": {}
}
],
"bindings": [
{
"source": "lega",
"vhost": "${MQ_VHOST:-/}",
"destination_type": "queue",
"arguments": {},
"destination": "archived",
"routing_key": "archived"
},
{
"source": "lega",
"vhost": "${MQ_VHOST:-/}",
"destination_type": "queue",
"arguments": {},
"destination": "files",
"routing_key": "files"
},
{
"source": "lega",
"vhost": "${MQ_VHOST:-/}",
"destination_type": "queue",
"arguments": {},
"destination": "files.completed",
"routing_key": "files.completed"
},
{
"source": "lega",
"vhost": "${MQ_VHOST:-/}",
"destination_type": "queue",
"arguments": {},
"destination": "files.error",
"routing_key": "files.error"
},
{
"source": "lega",
"vhost": "${MQ_VHOST:-/}",
"destination_type": "queue",
"arguments": {},
"destination": "files.inbox",
"routing_key": "files.inbox"
},
{
"source": "lega",
"vhost": "${MQ_VHOST:-/}",
"destination_type": "queue",
"arguments": {},
"destination": "files.processing",
blankdots marked this conversation as resolved.
Show resolved Hide resolved
"routing_key": "files.processing"
},
{
"source": "lega",
"vhost": "${MQ_VHOST:-/}",
"destination_type": "queue",
"arguments": {},
"destination": "stableIDs",
"routing_key": "stableIDs"
}
]
}
EOF
fi

chmod 600 "/var/lib/rabbitmq/definitions.json"

exec "$@"