add sendgrid

This commit is contained in:
Graham McIntire 2026-01-03 15:26:48 -06:00
parent d6a9bb11d7
commit 80cc5e937e
No known key found for this signature in database
5 changed files with 80 additions and 21 deletions

4
.gitignore vendored
View file

@ -38,3 +38,7 @@ npm-debug.log
# Dialyzer PLT files
/priv/plts/
# Environment variables (used by direnv and Kustomize secretGenerator)
.envrc
k8s/.envrc

View file

@ -59,27 +59,6 @@ if config_env() == :prod do
]
]
config :towerops, Towerops.Repo,
# ssl: true,
url: database_url,
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"),
# For machines with several cores, consider starting multiple pools of `pool_size`
# pool_count: 4,
socket_options: maybe_ipv6
config :towerops, ToweropsWeb.Endpoint,
url: [host: host, port: 443, scheme: "https"],
http: [
# Enable IPv6 and bind on all interfaces.
# Set it to {0, 0, 0, 0, 0, 0, 0, 1} for local network only access.
# See the documentation on https://hexdocs.pm/bandit/Bandit.html#t:options/0
# for details about using IPv6 vs IPv4 and loopback vs public addresses.
ip: {0, 0, 0, 0, 0, 0, 0, 0}
],
secret_key_base: secret_key_base
config :towerops, :dns_cluster_query, System.get_env("DNS_CLUSTER_QUERY")
# ## SSL Support
#
# To get SSL working, you will need to add the `https` key
@ -129,4 +108,30 @@ if config_env() == :prod do
# config :swoosh, :api_client, Swoosh.ApiClient.Req
#
# See https://hexdocs.pm/swoosh/Swoosh.html#module-installation for details.
# Configure SendGrid for production email
config :towerops, Towerops.Mailer,
adapter: Swoosh.Adapters.Sendgrid,
api_key: System.get_env("SENDGRID_API_KEY")
config :towerops, Towerops.Repo,
# ssl: true,
url: database_url,
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"),
# For machines with several cores, consider starting multiple pools of `pool_size`
# pool_count: 4,
socket_options: maybe_ipv6
config :towerops, ToweropsWeb.Endpoint,
url: [host: host, port: 443, scheme: "https"],
http: [
# Enable IPv6 and bind on all interfaces.
# Set it to {0, 0, 0, 0, 0, 0, 0, 1} for local network only access.
# See the documentation on https://hexdocs.pm/bandit/Bandit.html#t:options/0
# for details about using IPv6 vs IPv4 and loopback vs public addresses.
ip: {0, 0, 0, 0, 0, 0, 0, 0}
],
secret_key_base: secret_key_base
config :towerops, :dns_cluster_query, System.get_env("DNS_CLUSTER_QUERY")
end

38
k8s/README.md Normal file
View file

@ -0,0 +1,38 @@
# Kubernetes Deployment
## Secrets Management
Secrets are stored in `.envrc` files (gitignored):
- Project root `.envrc` - Used by direnv for local development
- `k8s/.envrc` - Used by Kustomize for secret generation
Kustomize automatically generates the `towerops-sendgrid` Secret from `k8s/.envrc` using the `secretGenerator` in `kustomization.yaml`.
Both `.envrc` files should contain:
```bash
# SendGrid Configuration
SENDGRID_API_KEY=your-api-key-here
export SENDGRID_API_KEY
```
The KEY=VALUE format works for both Kustomize and direnv.
## Deploying
Apply all resources using kustomize:
```bash
kubectl apply -k k8s/
```
Or individually:
```bash
kubectl apply -f k8s/namespace.yaml
kubectl apply -f k8s/secret.yaml
kubectl apply -f k8s/deployment.yaml
kubectl apply -f k8s/service.yaml
kubectl apply -f k8s/service-headless.yaml
kubectl apply -f k8s/certificate.yaml
kubectl apply -f k8s/ingressroute.yaml
```

View file

@ -60,6 +60,11 @@ spec:
secretKeyRef:
name: towerops-secrets
key: SECRET_KEY_BASE
- name: SENDGRID_API_KEY
valueFrom:
secretKeyRef:
name: towerops-sendgrid
key: SENDGRID_API_KEY
envFrom:
- secretRef:
name: towerops-db

View file

@ -8,3 +8,10 @@ resources:
- service-headless.yaml
- certificate.yaml
- ingressroute.yaml
secretGenerator:
- name: towerops-sendgrid
envs:
- .envrc
options:
disableNameSuffixHash: true