id: mysql
category: service
displayName: MySQL
description: 'Relational database with seeded dev credentials and a readiness healthcheck. Reachable in-container as host `mysql`.'
service:
  image: mysql:8
  defaultPort: 3306
  dataMount: /var/lib/mysql
  healthcheck:
    test:
      [
        CMD,
        mysqladmin,
        ping,
        -h,
        127.0.0.1,
        -u,
        root,
        '-p${MYSQL_ROOT_PASSWORD}',
      ]
    interval: 10s
    timeout: 5s
    retries: 5
  vscodeExtensions: [cweijan.vscode-database-client2]
  client:
    apt: [default-mysql-client]
  connectionEnv:
    URL: mysql://root:${MYSQL_ROOT_PASSWORD}@${host}:${port}/${MYSQL_DATABASE}
    HOST: ${host}
    PORT: ${port}
    USER: root
    PASSWORD: ${MYSQL_ROOT_PASSWORD}
    DB: ${MYSQL_DATABASE}
options:
  MYSQL_ROOT_PASSWORD:
    type: string
    default: monoceros
    surface: env
  MYSQL_DATABASE:
    type: string
    default: monoceros
    surface: env
# The service block for the project's pipeline compose file, verbatim.
deploy:
  compose: |-
    image: mysql:8
    environment:
      # root stays for administration only; the application connects as
      # MYSQL_USER, which the image grants access to MYSQL_DATABASE alone.
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:?set it as a pipeline secret}
      MYSQL_DATABASE: ${MYSQL_DATABASE:?set it as a pipeline secret}
      MYSQL_USER: ${MYSQL_USER:?set it as a pipeline secret}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD:?set it as a pipeline secret}
    healthcheck:
      # -h checks over TCP; on the unix socket mysqladmin answers during init.
      test: [CMD, mysqladmin, ping, -h, 127.0.0.1, -u, root, '-p${MYSQL_ROOT_PASSWORD}']
      interval: 5s
      timeout: 5s
      retries: 20
    # No volume: each run starts empty, the schema comes from the project's migrations.
