cabotapp / docker-cabot

Docker and docker-compose files for Cabot
https://hub.docker.com/r/cabotapp/cabot/
58 stars 31 forks source link

Docker image should bring up webserver #8

Closed mellotron closed 6 years ago

mellotron commented 7 years ago

Can you please change things so that the webapp is ready to go from the get go on port 5000?

I was trying to deploy cabot with the following on Kubernetes:

---
apiVersion: v1
kind: Service
metadata:
  name: cabot
  namespace: cabot
  labels:
    app: cabot
spec:
  ports:
    - port: 5000
  selector:
    app: cabot
    tier: frontend
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: cabot
  namespace: cabot
  labels:
    name: cabot
spec:
  template:
    metadata:
      labels:
        app: cabot
        tier: frontend
    spec:
      containers:
       - name: cabot
         image: cabotapp/cabot:0.10.8
         ports:
           - containerPort: 5000
             protocol: TCP
         livenessProbe:
           tcpSocket:
             port: 5000
         readinessProbe:
           tcpSocket:
             port: 5000
         volumeMounts:
          - name: cabot-configmap
            mountPath: /
            readOnly: true
      volumes:
        - name: cabot-configmap
          configMap:
            name: cabot-configmap
            items:
            - key: cabot-config
              path: production.env

Apart from the image, and labels such as names and TCP ports - this is pretty much how I deploy every application to my kubernetes cluster. I was confused as to why the image kept falling to boot - I wasn't expecting a webserver to do a "CMD ["/bin/sh"]"!

If no valid configuration is provided, it should be like wordpress where it brings up a web wizard asking where the database is, etc.

mellotron commented 7 years ago

This guy has the right idea: https://hub.docker.com/r/shoonoise/cabot-docker/~/dockerfile/

And now I can use environment variables in my config instead of hardcoding a file in a configmap:

         ...
         env:
           - name: CELERY_BROKER_URL
             value: redis://redis:6379/1
           - name: DATABASE_URL
             value: postgres://cabot:passwordhere@postgresql:5432/cabot
           - name: DB_HOST
             value: postgresql
           - name: DB_USER
             value: cabot
           - name: DB_PASS
             value: ....
           - name: DJANGO_SECRET_KEY
             value: Gern0flivPecwaQuolqwrjklqjklqwjklgdfhnsertfadoowonnOck7
           - name: WWW_HTTP_HOST
             value: cabot.example.com
frankh commented 7 years ago

The reason it doesn't have a default command is that the same container runs both the webserver and the celery workers.

I'm not sure how kubernetes works exactly, but can you not manually set the command for each service? cc @MrSaints

MrSaints commented 7 years ago

@frankh @mellotron Yes. You'll need to pass in the command, and spin up multiple containers for the service.

Example:

       - name: web
         command: ["sh", "-c", "cabot migrate && gunicorn cabot.wsgi:application -b 0.0.0.0:5000 --workers=5"]
         image: cabotapp/cabot:0.10.8
         ports:
           - containerPort: 5000
             protocol: TCP
         livenessProbe:
           tcpSocket:
             port: 5000
         readinessProbe:
           tcpSocket:
             port: 5000
         volumeMounts:
          - name: cabot-configmap
            mountPath: /
            readOnly: true
       - name: worker
         command: ["celery", "worker", "-A", "cabot"]
         image: cabotapp/cabot:0.10.8
         ports:
           - containerPort: 5000
             protocol: TCP
         livenessProbe:
           tcpSocket:
             port: 5000
         readinessProbe:
           tcpSocket:
             port: 5000
         volumeMounts:
          - name: cabot-configmap
            mountPath: /
            readOnly: true

I've not included Celery beat in the deployment as it is not something that should be replicated (otherwise you may have checks running multiple times).

22Goodmen commented 7 years ago

@mellotron Did you come right? Can you please share your deployment and service file/

frankh commented 6 years ago

There are now kubernetes files included in the repo, please let me know if those aren't working for you