Skip to content

Commit

Permalink
docs: 📝 Add deployment example to the README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
pklaschka committed Oct 29, 2024
1 parent 14744e0 commit 0cfae55
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,64 @@ await initVariable("SECRET", z.string(), 'xxx');
await initVariable("SECRET", z.string().optional());
```

## 🚀 Deployment Options

Due to Envar's flexible source system, you have multiple options for deploying your application. We'll demonstrate these with a Docker Compose configuration, but the same principles apply to other deployment methods as well.

### 💻 Application

```ts
await initVariable("PORT", z.string().match(/^[0-9]{1,5}$/), "8080");
await initVariable("OAUTH_TOKEN", z.string());
await initVariable("DB_URI", z.string().url());
await initVariable("SECRET", z.string());
await initVariable("CONFIG", z.string());
await initVariable("ANOTHER_SECRET", z.string());

const rawConfig = Deno.env.get("CONFIG");
if (rawConfig == undefined) {
throw new EnvNotSetError("CONFIG");
}
const config = JSON.parse(rawConfig);
console.log(config); // { key: "value" }
```

### 🐳 Docker Compose

```yaml
name: My Application

services:
my-service:
image: my-service
environment:
- PORT # Loaded from environment. Defaults to 8080 if not set
- SECRET_PATH=/run/secrets/my-secret # Mounted as secret file
- OAUTH_TOKEN_PATH=/run/secrets/another-secret # Mounted as secret file
- CONFIG_PATH=/run/configs/my-service-config # Mounted as config file
- DB_URI=${DB_URI:-mongodb://mongo:27017/my-database} # Default value
- ANOTHER_SECRET=${ANOTHER_SECRET:?ANOTHER_SECRET is required} # Required variable
secrets:
- my-secret
- another-secret
configs:
- my-service-config
mongo:
image: mongo

secrets:
my-secret:
file: ./secret.txt # Loaded from a file
another-secret:
environment: "OAUTH_TOKEN" # Loaded from an environment variable

configs:
my-service-config:
file: ./config.json # Loaded from a file
```
This configuration ensures that your application variables are securely managed and validated, leveraging Docker's secrets and configs features.
## 👥 Authors
This package was created and is maintained by [WüSpace e. V.](https://github.com/wuespace)
Expand Down

0 comments on commit 0cfae55

Please sign in to comment.