version: '3'
services:
  nats:
    image: nats:$NATS_IMAGE_TAG
    restart: unless-stopped
    ports:
      - "4222:4222"
      - "8222:8222"
    command: -js -m 8222
  nats-with-jwt-nkey:
    image: nats:$NATS_IMAGE_TAG
    restart: unless-stopped
    ports:
      - "4221:4222"
      - "8221:8222"
    command: -js -m 8222 -c /credentials/server.conf
    volumes:
      - ./credentials:/credentials:ro
    depends_on:
      credentials-generator:
        condition: service_completed_successfully
  nats-with-certs:
    image: nats:$NATS_IMAGE_TAG
    restart: unless-stopped
    ports:
      - "4220:4222"
      - "8220:8222"
    command: -js -m 8222 --tls --tlscert=/certs/server-cert.pem --tlskey=/certs/server-key.pem --tlscacert=/certs/rootCA.pem --tlsverify
    volumes:
      - ./certs:/certs:ro
    depends_on:
      certs-generator:
        condition: service_completed_successfully
  credentials-generator:
    image: natsio/nats-box:latest
    volumes:
      - ./scripts:/app:ro
      - ./credentials:/credentials
    working_dir: /app
    command: sh generate-credentials.sh
  certs-generator:
    image: goodeggs/mkcert
    entrypoint: /bin/bash
    volumes:
      - ./scripts:/app:ro
      - ./certs:/certs
    working_dir: /app
    command: generate-certs.sh
