Skip to content

yroc92/postgres-storage

Repository files navigation

certmagic-sqlstorage

GoDoc

SQL storage for CertMagic/Caddy TLS data.

Currently supports PostgreSQL but it'd be pretty easy to support other RDBs like SQLite and MySQL. Please make a pull-request if you add support for them and I'll gladly merge.

Now with support for Caddyfile and environment configuration.

Example

  • Valid values for sslmode are: disable, require, verify-ca, verify-full

With vanilla JSON config file and single connection string:

{
  "storage": {
    "module": "postgres",
    "connection_string": "postgres://user:password@localhost:5432/postgres?sslmode=disable",
    "disable_ddl": false
  },
  "app": {
    ...
  }
}

With vanilla JSON config file and separate fields:

{
  "storage": {
    "module": "postgres",
    "dbname": "certmagictest",
    "host": "localhost",
    "password": "postgres",
    "port": "5432",
    "sslmode": "disable",
    "user": "postgres",
    "disable_ddl": false
  },
  "app": {
    ...
  }
}

With Caddyfile:

# Global Config

{
  storage postgres {
    connection_string postgres://user:password@localhost:5432/postgres?sslmode=disable
    disable_ddl false
  }
}

or

{
  storage postgres {
    dbname certmagictest
    host localhost
    password postgres
    port 5432
    sslmode disable
    user postgres
    disable_ddl false
  }
}

From Environment:

POSTGRES_CONN_STRING
POSTGRES_DISABLE_DDL

or

POSTGRES_HOST
POSTGRES_PORT
POSTGRES_USER
POSTGRES_PASSWORD
POSTGRES_DBNAME
POSTGRES_SSLMODE
POSTGRES_DISABLE_DDL

Configuring with labels for usage with Swarm and docker-proxy (https://github.com/lucaslorentz/caddy-docker-proxy):

deploy:
  labels:
    # Set Storage definitions
    caddy_0.storage: postgres
    caddy_0.storage.connection_string: postgres://user:password@localhost:5432/postgres?sslmode=disable
    caddy_0.storage.disable_ddl: false

or

deploy:
  labels:
    # Set Storage definitions
    caddy_0.storage: postgres
    caddy_0.storage.host: localhost
    caddy_0.storage.port: "5432"
    caddy_0.storage.user: postgres
    caddy_0.storage.password: postgres
    caddy_0.storage.dbname: certmagictest
    caddy_0.storage.sslmode: disable
    caddy_0.storage.disable_ddl: false

Build vanilla Docker image

# Version to build
ARG CADDY_VERSION="2.6.2"

FROM caddy:${CADDY_VERSION}-builder AS builder

RUN xcaddy build \
    --with github.com/yroc92/postgres-storage

FROM caddy:${CADDY_VERSION}-alpine

COPY --from=builder /usr/bin/caddy /usr/bin/caddy

Build Docker image with docker-proxy support and Cloudflare resolver support

# Version to build
ARG CADDY_VERSION="2.6.2"

FROM caddy:${CADDY_VERSION}-builder AS builder

RUN xcaddy build \
    --with github.com/yroc92/postgres-storage            \
    --with github.com/lucaslorentz/caddy-docker-proxy/v2 \
    --with github.com/caddy-dns/cloudflare

FROM caddy:${CADDY_VERSION}-alpine

COPY --from=builder /usr/bin/caddy /usr/bin/caddy

CMD ["caddy", "docker-proxy"]

LICENSE

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •