Skip to content
Snippets Groups Projects
Verified Commit dd0ba951 authored by David Hoese's avatar David Hoese
Browse files

Move rabbit init image building to deploy repository

parent 1e09e2b0
No related branches found
No related tags found
No related merge requests found
...@@ -15,6 +15,9 @@ variables: ...@@ -15,6 +15,9 @@ variables:
CICHART_IMAGE: "$CI_REGISTRY_IMAGE/cichart:latest" CICHART_IMAGE: "$CI_REGISTRY_IMAGE/cichart:latest"
include:
- file: /helpers/build_image.yaml
.docker_based_job: .docker_based_job:
image: docker:19.03.1 image: docker:19.03.1
tags: tags:
...@@ -52,6 +55,20 @@ build ci: ...@@ -52,6 +55,20 @@ build ci:
- if: $BUILD_CI_IMAGE - if: $BUILD_CI_IMAGE
when: always when: always
build sidecar rabbit init:
stage: .pre
extends: .build_image
variables:
IMAGE_NAME: cspp-geo-rabbit-init
IMAGE_DIR: sidecars/cspp-geo-rabbit-init
rules:
- changes:
- sidecars/cspp-geo-rabbit-init/Dockerfile
- sidecars/cspp-geo-rabbit-init/declare_exchange.py
when: always
- if: $BUILD_SIDECARS
when: always
.get_chart_tmpl: .get_chart_tmpl:
extends: .helm_based_job extends: .helm_based_job
...@@ -93,6 +110,30 @@ get_chart_grb: ...@@ -93,6 +110,30 @@ get_chart_grb:
SUBCOMP_REPOS: "geosphere-grb" SUBCOMP_REPOS: "geosphere-grb"
SUBCOMP_CHART_DIR: "cspp-geo-grb" SUBCOMP_CHART_DIR: "cspp-geo-grb"
deploy_prod_rabbit:
environment:
name: production
url: http://geosphere.ssec.wisc.edu
extends: .helm_based_job
stage: deploy rabbit
script:
- if [ -n "$CI_COMMIT_TAG" ]; then
ns="geosphere";
else
ns="geosphere-test";
fi
# copy secret kubeconfig to the mounted (pwd) directory
- cp $kubekorner_k3s_config .
- kubeconfig=$(basename $kubekorner_k3s_config)
# install third-party rabbitmq server
- helm repo add bitnami https://charts.bitnami.com/bitnami
- helm install --namespace $ns geosphere-rabbit bitnami/rabbitmq
rules:
- if: '$kubekorner_k3s_config == ""'
when: never
- when: on_success
deploy_g16_grb: deploy_g16_grb:
environment: environment:
name: production name: production
......
...@@ -24,9 +24,9 @@ ...@@ -24,9 +24,9 @@
script: script:
- image_url="${CI_REGISTRY_IMAGE}/${IMAGE_NAME}" - image_url="${CI_REGISTRY_IMAGE}/${IMAGE_NAME}"
- if [ -z "$CI_COMMIT_TAG" ]; then - if [ -z "$CI_COMMIT_TAG" ]; then
docker_tag=$CI_COMMIT_SHORT_SHA; docker_tag=$CI_COMMIT_SHORT_SHA;
else else
docker_tag=$CI_COMMIT_TAG; docker_tag=$CI_COMMIT_TAG;
fi; fi;
- echo $docker_tag - echo $docker_tag
- docker pull ${image_url}:latest || true - docker pull ${image_url}:latest || true
......
FROM python:3-alpine as base
FROM base as builder
RUN pip install --prefix=/install pika
FROM base
COPY --from=builder /install /usr/local
COPY declare_exchange.py .
CMD ["python", "declare_exchange.py"]
# RabbitMQ Initialization
This container is meant to declare a RabbitMQ exchange on a separate
RabbitMQ container. This is meant to be used as a Kubernetes pre-install
hook for the various helm charts that will access the RabbitMQ server.
## Build
```bash
docker build -t gitlab.ssec.wisc.edu:5555/cspp_geo/geosphere/geosphere-deploy/cspp-geo-rabbit-init:latest cspp_geo_rabbit_init/
```
## Usage
This container should run and after sending a couple messages to the RabbitMQ
server it should return.
```bash
docker run --rm gitlab.ssec.wisc.edu:5555/cspp_geo/geosphere/geosphere-deploy/cspp-geo-rabbit-init:latest
```
### Environment Variables
* **RABBITMQ_HOST**: Hostname for the remote RabbitMQ server. Required.
* **RABBITMQ_EXCHANGE_NAME**: Name of the exchange. Required.
* **RABBITMQ_USER**: Username to connect to the RabbitMQ server.
Default: "guest"
* **RABBITMQ_PASSWORD**: Password to connect to the RabbitMQ server.
Default: "guest"
* **RABBITMQ_EXCHANGE_TYPE**: Type of exchange to declare.
Default: "topic"
\ No newline at end of file
#!/usr/bin/env python3
import os
import pika
if __name__ == "__main__":
user = os.getenv("RABBITMQ_USERNAME", "guest")
password = os.getenv("RABBITMQ_PASSWORD", "guest")
rabbitmq_host = os.getenv("RABBITMQ_HOST")
exchange = os.getenv("RABBITMQ_EXCHANGE_NAME")
exchange_type = os.getenv("RABBITMQ_EXCHANGE_TYPE", "topic")
credentials = pika.PlainCredentials(user, password)
conn_params = pika.ConnectionParameters(host=rabbitmq_host,
credentials=credentials)
conn = pika.BlockingConnection(conn_params)
ch = conn.channel()
ch.exchange_declare(
exchange=exchange,
exchange_type=exchange_type,
durable=True,
auto_delete=False,
internal=False,
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment