Skip to content

Commit

Permalink
Updated env vars and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
brendan-ward committed Jun 2, 2019
1 parent e49102f commit d5769a0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
35 changes: 19 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,32 +84,35 @@ If `redirect` option is provided, the server also listens on port 80 and redirec

If the `--tls` option is provided, the Let's Encrypt Terms of Service are accepted automatically on your behalf. Please review them [here](https://letsencrypt.org/repository/). Certificates are cached in a `.certs` folder created where you are executing `mbtileserver`. Please make sure this folder can be written by the `mbtileserver` process or you will get errors.

Also you can set up server config by environment variables. It may be helpful, when you deploying it in docker image. Just now exists next variables:
- PORT
- TILE_PATH
- PRIVATE_KEY
- PATH_PREFIX
- DOMAIN
- SENTRY_DSN
- VERBOSE
- AUTO_TLS
- REDIRECT

Simple example:
You can also set up server config using environment variables instead of flags, which may be more helpful when deploying in a docker image. Use the associated flag to determine usage. The following variables are available:

- `PORT` (`--port`)
- `TILE_DIR` (`--dir`)
- `PATH_PREFIX` (`--path`)
- `DOMAIN` (`--domain`)
- `TLS_CERT` (`--cert`)
- `TLS_PRIVATE_KEY` (`--key`)
- `AUTO_TLS` (`--tls`)
- `REDIRECT` (`--redirect`)
- `DSN` (`--dsn`)
- `VERBOSE` (`--verbose`)
- `HMAC_SECRET_KEY` (`--secret-key`)

Example:

```
$ PORT=7777 TILE_PATH=./path/to/your/tiles VERBOSE=true mbtileserver
$ PORT=7777 TILE_DIR=./path/to/your/tiles VERBOSE=true mbtileserver
```

In docker-compose.yml file it will be look like:
In a docker-compose.yml file it will look like:

```
mbtileserver:
...
environment:
PORT: 7777
TYLE_PATH: "./path/to/your/tiles"
TILE_DIR: "./path/to/your/tiles"
VERBOSE: true
entrypoint: mbtileserver
Expand Down Expand Up @@ -210,7 +213,7 @@ These are hosted on a free dyno by Heroku (thanks Heroku!), so there might be a

## Request authorization

Provind a secret key with `-s/--secret-key` or by setting the `MBTILESERVER_SECRET_KEY` environment variable will
Provind a secret key with `-s/--secret-key` or by setting the `HMAC_SECRET_KEY` environment variable will
restrict access to all server endpoints and tile requests. Requests will only be served if they provide a cryptographic
signature created using the same secret key. This allows, for example, an application server to provide authorized
clients a short-lived token with which the clients can access tiles for a specific service.
Expand Down
12 changes: 8 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,15 @@ func init() {
port = p
}

if env := os.Getenv("TILE_PATH"); env != "" {
if env := os.Getenv("TILE_DIR"); env != "" {
tilePath = env
}

if env := os.Getenv("PRIVATE_KEY"); env != "" {
if env := os.Getenv("TLS_CERT"); env != "" {
certificate = env
}

if env := os.Getenv("TLS_PRIVATE_KEY"); env != "" {
privateKey = env
}

Expand All @@ -88,7 +92,7 @@ func init() {
domain = env
}

if env := os.Getenv("SENTRY_DSN"); env != "" {
if env := os.Getenv("DSN"); env != "" {
sentryDSN = env
}

Expand Down Expand Up @@ -117,7 +121,7 @@ func init() {
}

if secretKey == "" {
secretKey = os.Getenv("MBTILESERVER_SECRET_KEY")
secretKey = os.Getenv("HMAC_SECRET_KEY")
}
}

Expand Down

2 comments on commit d5769a0

@brendan-ward
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kow33 I updated the names of some of the variables to better match their underlying flags.

@nikmolnar MBTILESERVER_SECRET_KEY => HMAC_SECRET_KEY for better consistency with the others.

@nikmolnar
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MBTILESERVER_SECRET_KEY => HMAC_SECRET_KEY for better consistency with the others.

I used MBTILESERVER_SECRET_KEY because environment variables are global, and I wanted to it be clear that the variable applies to mbtileserver only, and I also wanted to avoid a clash with another application (granted, HMAC_SECRET_KEY isn't likely to be used elsewhere...).

Please sign in to comment.