Skip to content

Containerized

You can import the JSON keys service as a container. You need to import both API and associated Jobs for the service to run correctly.

yaml
# https://github.com/containers/podman-compose
services:
  json-keys-postgres:
    image: ghcr.io/a-novel/service-json-keys/database:v1
    networks:
      - api
    environment:
      POSTGRES_PASSWORD: postgres
      POSTGRES_USER: postgres
      POSTGRES_DB: json-keys
      POSTGRES_HOST_AUTH_METHOD: scram-sha-256
      POSTGRES_INITDB_ARGS: --auth=scram-sha-256
    volumes:
      - json-keys-postgres-data:/var/lib/postgresql/data/

  json-keys-postgres-migrations:
    image: ghcr.io/a-novel/service-json-keys/jobs/migrations:v1
    depends_on:
      json-keys-postgres:
        condition: service_healthy
    networks:
      - api
    environment:
      POSTGRES_DSN: postgres://postgres:postgres@json-keys-postgres:5432/json-keys?sslmode=disable

  # Make sure the master key is the same across all containers.
  # The Master Key is a secure, 32-bit random secret used to encrypt private JSON keys
  # in the database.
  # This value is a dummy key used for tests. Use your own random key in production.

  json-keys-job-rotate-keys:
    image: ghcr.io/a-novel/service-json-keys/jobs/rotatekeys:v1
    depends_on:
      json-keys-postgres:
        condition: service_healthy
      json-keys-postgres-migrations:
        condition: service_completed_successfully
    environment:
      POSTGRES_DSN: postgres://postgres:postgres@json-keys-postgres:5432/json-keys?sslmode=disable
      APP_MASTER_KEY: fec0681a2f57242211c559ca347721766f8a3acd8ed2e63b36b3768051c702ca
    networks:
      - api

  json-keys-service:
    image: ghcr.io/a-novel/service-json-keys/api:v1
    depends_on:
      json-keys-postgres:
        condition: service_healthy
      json-keys-postgres-migrations:
        condition: service_completed_successfully
      json-keys-job-rotate-keys:
        condition: service_completed_successfully
    environment:
      POSTGRES_DSN: postgres://postgres:postgres@json-keys-postgres:5432/json-keys?sslmode=disable
      APP_MASTER_KEY: fec0681a2f57242211c559ca347721766f8a3acd8ed2e63b36b3768051c702ca
    networks:
      - api

networks:
  api: {}

volumes:
  json-keys-postgres-data:

Standalone image (local)

For local development or CI purposes, you can also load a standalone version that runs all the necessary jobs before starting the service.

WARNING

The standalone image takes longer to boot, and it is not suited for production use.

yaml
# https://github.com/containers/podman-compose
services:
  json-keys-postgres:
    image: ghcr.io/a-novel/service-json-keys/database:v1
    networks:
      - api
    environment:
      POSTGRES_PASSWORD: postgres
      POSTGRES_USER: postgres
      POSTGRES_DB: json-keys
      POSTGRES_HOST_AUTH_METHOD: scram-sha-256
      POSTGRES_INITDB_ARGS: --auth=scram-sha-256
    volumes:
      - json-keys-postgres-data:/var/lib/postgresql/data/

  # The Master Key is a secure, 32-bit random secret used to encrypt private JSON keys
  # in the database.
  # This value is a dummy key used for tests. Use your own random key in production.
  json-keys-service:
    image: ghcr.io/a-novel/service-json-keys/standalone:v1
    depends_on:
      json-keys-postgres:
        condition: service_healthy
    environment:
      POSTGRES_DSN: postgres://postgres:postgres@json-keys-postgres:5432/json-keys?sslmode=disable
      APP_MASTER_KEY: fec0681a2f57242211c559ca347721766f8a3acd8ed2e63b36b3768051c702ca
    networks:
      - api

networks:
  api: {}

volumes:
  json-keys-postgres-data:

Configuration

Configuration is done through environment variables.

Required variables

You must provide the following variables for the service to run correctly.

VariableDescriptionImages
APP_MASTER_KEYThe Master Key is a secure, 32-bit random secret used to encrypt private JSON keys in the database.standalone, api, jobs/rotatekeys
POSTGRES_DSNConnection string to the Postgres database.standalone, api, jobs/rotatekeys

Optional variables

Generic configuration.

VariableDescriptionDefaultImages
APP_NAMEName of the application, used for tracing.json-keys-service
service-json-keys-job-rotate-keys
standalone, api, jobs/rotatekeys
ENVProvide information on the current environment.standalone, api, jobs/rotatekeys
DEBUGActivate debug mode for logs.falsestandalone, api, jobs/rotatekeys

API configuration.

VariableDescriptionDefaultImages
API_PORTPort to run the API on.8080standalone, api
API_MAX_REQUEST_SIZEMaximum request size for the API.
Provided as a number of bytes.
2MBstandalone, api
API_TIMEOUT_READRead timeout for the API.
Provided as a duration string.
5sstandalone, api
API_TIMEOUT_READ_HEADERHeader read timeout for the API.
Provided as a duration string.
3sstandalone, api
API_TIMEOUT_WRITEWrite timeout for the API.
Provided as a duration string.
10sstandalone, api
API_TIMEOUT_IDLEIdle timeout for the API.
Provided as a duration string.
30sstandalone, api
APITimeoutRequestRequest timeout for the API.
Provided as a duration string.
15sstandalone, api
API_CORS_ALLOWED_ORIGINSCORS allowed origins for the API.
Provided as a list of values separated by commas.
*standalone, api
API_CORS_ALLOWED_HEADERSCORS allowed headers for the API.
Provided as a list of values separated by commas.
*standalone, api
API_CORS_ALLOW_CREDENTIALSWhether to allow credentials in CORS requests.falsestandalone, api
API_CORS_MAX_AGECORS max age for the API.
Provided as a number of seconds.
3600standalone, api

Tracing configuration (with Sentry).

VariableDescriptionDefaultImages
SENTRY_DSNSentry DSN for tracing.
Tracing will be disabled if omitted.
standalone, api, jobs/rotatekeys
SENTRY_RELEASERelease information for Sentry logs.standalone, api, jobs/rotatekeys
SENTRY_FLUSH_TIMEOUTTimeout for flushing Sentry logs.
Provided as a duration string.
2sstandalone, api, jobs/rotatekeys
SENTRY_ENVIRONMENTWhich environment to attach logs to.Uses the value from ENV variable.standalone, api, jobs/rotatekeys
SENTRY_DEBUGActivate debug mode for Sentry.Uses the value from DEBUG variable.standalone, api, jobs/rotatekeys