Deploying on Docker
For other deployment options, see Deploying Conduit Applications.

Purpose

This document will describe the steps to deploy a Conduit application through Docker, Docker Compose or a container orchestration platform like Kubernetes. For Dockerfile and Kubernetes templates, see this repository.
If you are unfamiliar with deploying applications in this way, this is not a good beginner's guide and will not cover the topics of Docker, Docker Compose or Kubernetes.

Dockerfiles

The following Dockerfile will run a Conduit application.
1
FROM google/dart
2
3
WORKDIR /app
4
ADD pubspec.* /app/
5
RUN pub get --no-precompile
6
ADD . /app/
7
RUN pub get --offline --no-precompile
8
9
WORKDIR /app
10
EXPOSE 80
11
12
ENTRYPOINT ["pub", "run", "conduit:conduit", "serve", "--port", "80"]
Copied!

Docker Compose

To deploy your application (which uses the Conduit ORM) using Docker Compose, use this template:
Dockerfile
Use the Dockerfile specified above.
docker-compose.yml
1
version: '3'
2
services:
3
my-app:
4
build: .
5
ports:
6
- "80:80"
7
8
db:
9
image: "postgres:11"
10
container_name: "postgres_database"
11
environment:
12
- POSTGRES_PASSWORD=password-from-config-yaml
13
- POSTGRES_USER=user-from-config-yaml
14
- POSTGRES_DB=db-from-config-yaml
15
ports:
16
- "65432:port-from-config-yaml" # If you want to expose the db from the container
17
volumes:
18
- db_data:/var/lib/postgresql/data
19
20
volumes:
21
db_data: {}
Copied!
Once the service is up (using docker-compose up -d), you can run your database migrations using
conduit db upgrade --connect postgres://user-from-config-yaml:[email protected]:65432/db-from-config-yaml

Kubernetes Objects

For more Kubernetes objects - including tasks for database migrations and OAuth 2.0 client management - see this repository. The following is Kubernetes configuration file for starting a Conduit application and exposing it as a service. Replace <APP_NAME> with your application's name.
1
apiVersion: v1
2
kind: Service
3
metadata:
4
name: api-service
5
namespace: <APP_NAME>
6
spec:
7
selector:
8
app: <APP_NAME>
9
role: backend
10
type: api
11
ports:
12
- port: 80
13
targetPort: 8082
14
---
15
apiVersion: apps/v1beta1
16
kind: Deployment
17
metadata:
18
name: api-deployment
19
namespace: <APP_NAME>
20
spec:
21
replicas: 2
22
template:
23
metadata:
24
labels:
25
app: <APP_NAME>
26
role: backend
27
type: api
28
spec:
29
containers:
30
- name: <APP_NAME>
31
# In development, setting `imagePullPolicy: Always` and using :latest tag is useful.
32
# imagePullPolicy: Always
33
image: <IMAGE>
34
envFrom:
35
- secretRef:
36
name: secrets
37
- configMapRef:
38
name: config
39
ports:
40
- containerPort: 8082
41
securityContext:
42
runAsNonRoot: true
Copied!
Last modified 4mo ago