Saleor is a headless, Django based e-commerce framework. This post will show how to deploy Saleor using Django Helm Chart. It will focus on deploying the Django Backend. The dashboard is a static HTML site and is left out. The front-end is something you should build yourself.
First you need a Docker image. You can build this yourself or use https://hub.docker.com/r/mirumee/saleor/. I suggest building it yourself so that it’s possible to add plugins and set the specific version you’d like. Here’s a snippet for Gitlab CI as a starting point. This can be run on a fork of Saleor which already contains a Dockerfile. I like to tag my image with both the git ref name and short sha for reference later on.
build: stage: build image: docker:20 services: - docker:20-dind script: - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN registry.gitlab.com - docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA . - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
Next, create a values.yml file to power Django Helm Chart. Here’s an example:
image: repository: your-docker-image tag: latest env: normal: ALLOWED_CLIENT_HOSTS: localhost,127.0.0.1,your-frontend-url ALLOWED_HOSTS: "*" ENABLE_SSL: "True" DEFAULT_EMAIL_FROM: firstname.lastname@example.org AWS_ACCESS_KEY_ID: XXXXXXXXXX AWS_MEDIA_BUCKET_NAME: bucket-name AWS_DEFAULT_ACL: public-read SENTRY_DSN: https://email@example.com/project-id secret: DATABASE_URL: your-postgres-connection-string SECRET_KEY: your-secret-key AWS_SECRET_ACCESS_KEY: XXXXXXXXX EMAIL_URL: email-connection-string CELERY_BROKER_URL: your-redis-connection-string web: replicaCount: 2 port: 8000 args: ["gunicorn", "--bind", ":8000", "--workers", "4", "--worker-class", "uvicorn.workers.UvicornWorker", "saleor.asgi:application"] autoscaling: enabled: false livenessProbe: failureThreshold: 5 initialDelaySeconds: 5 timeoutSeconds: 2 path: "/graphql/" readinessProbe: failureThreshold: 10 initialDelaySeconds: 5 timeoutSeconds: 2 path: "/graphql/" ingress: enabled: true annotations: kubernetes.io/ingress.class: nginx hosts: - host: your-host paths: - path: / pathType: ImplementationSpecific worker: enabled: true args: - celery - -A - saleor - --app=saleor.celeryconf:app - worker - --loglevel=info redis: architecture: standalone auth: password: redis-password master: persistence: enabled: false
Let’s break this apart, as there are many options here.
- I choose to enable Kubernetes managed Redis but not Postgres. I don’t trust running stateful services like Postgres in Kubernetes but you could set postgres.enabled=true.
- Many Saleor settings are managed via environment variables. Documentation for them exists here. In the example, I configure AWS S3 and set my DATABASE_URL to a managed Postgres instance like RDS.
- The web and worker args (which maps to Docker’s command) are set to the specific run commands for Saleor which uses celery and gunicorn. This is also the place to edit configuration options, such as number of gunicorn workers.
- The example contains a ingress. Don’t forget to add a ingress controller like ingress-nginx to your cluster. If you don’t need a internet accessible URL, remove it.
Next add the chart repo (or fork it).
helm repo add django https://burke-software.gitlab.io/django-helm-chart/ helm install your-app django/django -f values.yml
The chart should output instructions on accessing the new site. Make sure to review logs to ensure Celery is running as well. Now you have a Saleor backend running on Kubernetes. If running in production, make sure to review affinity values, Saleor configuration, resource limits, and add tls to the ingress.