redis
The default redis provisioner adds a redis service to the project which returns a host, port, username, and password.
Provisions a dedicated Redis instance.
type: redis
expected_outputs:
- host
- port
- username
- passwordprovisioners.yaml
(view on GitHub)
:
- uri: template://default-provisioners/redis
# By default, match all redis types regardless of class and id. If you want to override this, create another
# provisioner definition with a higher priority.
type: redis
description: Provisions a dedicated Redis instance.
# Init template has the default port and a random service name and password if needed later
init: |
port: 6379
randomServiceName: redis-{{ randAlphaNum 6 }}
randomPassword: {{ randAlphaNum 16 | quote }}
# The only state we need to persist is the chosen random service name and password
state: |
serviceName: {{ dig "serviceName" .Init.randomServiceName .State | quote }}
password: {{ dig "password" .Init.randomPassword .State | quote }}
# Return the outputs schema that consumers expect
outputs: |
host: {{ .State.serviceName }}
port: {{ .Init.port }}
username: default
password: {{ .State.password | quote }}
# write the config file to the mounts directory
files: |
{{ .State.serviceName }}/redis.conf: |
requirepass {{ .State.password }}
port {{ .Init.port }}
save 60 1
loglevel warning
# add a volume for persistence of the redis data
volumes: |
{{ .State.serviceName }}-data:
name: {{ .State.serviceName }}-data
driver: local
labels:
dev.score.compose.res.uid: {{ .Uid }}
# And the redis service itself with volumes bound in
services: |
{{ .State.serviceName }}:
labels:
dev.score.compose.res.uid: {{ .Uid }}
image: mirror.gcr.io/redis:7-alpine
restart: always
entrypoint: ["redis-server"]
command: ["/usr/local/etc/redis/redis.conf"]
volumes:
- type: bind
source: {{ .MountsDirectory }}/{{ .State.serviceName }}/redis.conf
target: /usr/local/etc/redis/redis.conf
read_only: true
- type: volume
source: {{ .State.serviceName }}-data
target: /data
volume:
nocopy: true
info_logs: |
- "{{.Uid}}: To connect to redis: \"docker run -it --network {{ .ComposeProjectName }}_default --rm redis redis-cli -h {{ .State.serviceName | squote }} -a {{ .State.password | squote }}\""
expected_outputs:
- host
- port
- username
- password