Skip to content

Commit 6af1fa7

Browse files
committed
feat: load deployment config from .env (gitignored)
- bin/app.ts reads DOMAIN_* and TELEGRAM_GROUPS from process.env, falling back to cdk.json placeholders when unset. - deploy.sh sources .env so CDK picks up real values. - .env.example added as a public template. - .gitignore: allow !.env.example through the .env.* glob. - README Quick Start rewritten around the .env flow. cdk.json keeps the original placeholder content so a fresh clone still synthesizes; .env overrides at deploy time.
1 parent 7974684 commit 6af1fa7

5 files changed

Lines changed: 64 additions & 42 deletions

File tree

.env.example

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copy to .env and fill with real values. .env is gitignored.
2+
# These override cdk.json's "domain" and "telegramGroups" context.
3+
4+
# Custom domain (optional — leave unset to use the CloudFront default *.cloudfront.net URL)
5+
DOMAIN_NAME=wall.example.com
6+
DOMAIN_HOSTED_ZONE_ID=ZXXXXXXXXXXXXX
7+
DOMAIN_HOSTED_ZONE_NAME=example.com
8+
DOMAIN_CERTIFICATE_ARN=arn:aws:acm:us-east-1:123456789012:certificate/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
9+
10+
# Telegram groups — JSON array. One entry per group.
11+
# secretName must already exist in AWS Secrets Manager and hold the bot token.
12+
TELEGRAM_GROUPS=[{"groupId":"my-team","chatId":"-1001234567890","name":"My Team Photo Wall","secretName":"telegram/bot-token/my-team","botUsername":"my_photo_wall_bot"}]

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ build/
2929
# Environment files
3030
.env
3131
.env.*
32+
!.env.example
3233
*.secret
3334

3435
# OS

README.md

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -525,64 +525,55 @@ aws secretsmanager create-secret \
525525
--region us-west-2
526526
```
527527

528-
### Step 2 — Configure Groups in `cdk.json`
529-
530-
```json
531-
{
532-
"context": {
533-
"telegramGroups": [
534-
{
535-
"groupId": "my-team",
536-
"chatId": "-1001234567890",
537-
"name": "My Team Photo Wall",
538-
"secretName": "telegram/bot-token/my-team",
539-
"botUsername": "my_photo_wall_bot"
540-
}
541-
]
542-
}
543-
}
528+
### Step 2 — Create `.env` from `.env.example`
529+
530+
The repo ships with `.env.example` (placeholder values). Copy it to `.env` (gitignored) and fill in your real domain + Telegram groups. `deploy.sh` sources `.env` and exposes the values to the CDK app, where they override the `domain` and `telegramGroups` placeholders in `cdk.json`.
531+
532+
```bash
533+
cp .env.example .env
534+
# then edit .env with your real values
544535
```
545536

537+
`.env` schema:
538+
539+
| Variable | Required? | Description |
540+
|---|---|---|
541+
| `DOMAIN_NAME` | optional | Custom subdomain, e.g. `wall.example.com`. Omit to use the CloudFront default URL. |
542+
| `DOMAIN_HOSTED_ZONE_ID` | with domain | Route53 Hosted Zone ID for the parent zone |
543+
| `DOMAIN_HOSTED_ZONE_NAME` | with domain | Parent zone name, e.g. `example.com` |
544+
| `DOMAIN_CERTIFICATE_ARN` | with domain | ACM cert ARN — **must be in `us-east-1`** for CloudFront |
545+
| `TELEGRAM_GROUPS` | required | JSON array, **wrap in single quotes** so bash preserves the inner double quotes |
546+
547+
Each group in `TELEGRAM_GROUPS` has:
548+
546549
| Field | Description | Example |
547550
|---|---|---|
548551
| `groupId` | URL slug for the wall | `my-team` |
549552
| `chatId` | Telegram group Chat ID | `-1001234567890` |
550553
| `name` | Display name on the wall | `My Team Photo Wall` |
551-
| `secretName` | Secrets Manager secret name | `telegram/bot-token/my-team` |
552-
| `botUsername` | Bot's @username (only @mentions shown) | `my_photo_wall_bot` |
553-
554-
### Step 3 — (Optional) Configure Custom Domain
555-
556-
```json
557-
{
558-
"context": {
559-
"domain": {
560-
"name": "wall.example.com",
561-
"hostedZoneId": "ZXXXXXXXXXXXXX",
562-
"hostedZoneName": "example.com",
563-
"certificateArn": "arn:aws:acm:us-east-1:123456789:certificate/xxx"
564-
}
565-
}
566-
}
567-
```
554+
| `secretName` | Secrets Manager secret name (must already exist, see Step 1) | `telegram/bot-token/my-team` |
555+
| `botUsername` | Bot's @username (only @mentions are shown) | `my_photo_wall_bot` |
568556

569557
> ACM certificate **must** be requested in `us-east-1` for CloudFront. CDK automatically creates the Route53 A record alias.
570558
571-
### Step 4 — Deploy
559+
### Step 3 — Deploy
572560

573561
```bash
574562
./deploy.sh
575563
```
576564

565+
`deploy.sh` automatically loads `.env`, runs `npm install`, builds the frontend, and `cdk deploys` to the region from `AWS_DEFAULT_REGION` (defaults to `us-east-1`).
566+
577567
Or manually:
578568

579569
```bash
570+
set -a && source .env && set +a
580571
npm install
581572
cd photo-wall && npm install && npm run build && cd ..
582573
npx cdk deploy
583574
```
584575

585-
### Step 5 — Register the Telegram Webhook
576+
### Step 4 — Register the Telegram Webhook
586577

587578
```bash
588579
WEBHOOK_SECRET=$(aws secretsmanager get-secret-value \
@@ -599,7 +590,7 @@ curl -X POST "https://api.telegram.org/bot<BOT_TOKEN>/setWebhook" \
599590
}'
600591
```
601592

602-
### Step 6 — Add Bot to Telegram Group
593+
### Step 5 — Add Bot to Telegram Group
603594

604595
1. Add your bot to the Telegram group
605596
2. In **BotFather → Bot Settings → Group Privacy → Turn off** (so the bot can read all messages)

bin/app.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,24 @@ import { TelegramPhotoWallStack } from "../lib/telegram-photo-wall-stack";
55

66
const app = new cdk.App();
77

8-
const telegramGroups = app.node.tryGetContext("telegramGroups") ?? [];
9-
const domainConfig = app.node.tryGetContext("domain") ?? {};
8+
const ctxGroups = app.node.tryGetContext("telegramGroups") ?? [];
9+
const ctxDomain = app.node.tryGetContext("domain") ?? {};
10+
11+
const telegramGroups = process.env.TELEGRAM_GROUPS
12+
? JSON.parse(process.env.TELEGRAM_GROUPS)
13+
: ctxGroups;
14+
15+
const domainName = process.env.DOMAIN_NAME ?? ctxDomain.name;
16+
const hostedZoneId = process.env.DOMAIN_HOSTED_ZONE_ID ?? ctxDomain.hostedZoneId;
17+
const hostedZoneName = process.env.DOMAIN_HOSTED_ZONE_NAME ?? ctxDomain.hostedZoneName;
18+
const certificateArn = process.env.DOMAIN_CERTIFICATE_ARN ?? ctxDomain.certificateArn;
1019

1120
new TelegramPhotoWallStack(app, "TelegramPhotoWallStack", {
1221
telegramGroups,
13-
domainName: domainConfig.name,
14-
hostedZoneId: domainConfig.hostedZoneId,
15-
hostedZoneName: domainConfig.hostedZoneName,
16-
certificateArn: domainConfig.certificateArn,
22+
domainName,
23+
hostedZoneId,
24+
hostedZoneName,
25+
certificateArn,
1726
env: {
1827
account: process.env.CDK_DEFAULT_ACCOUNT,
1928
region: process.env.CDK_DEFAULT_REGION,

deploy.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ echo "========================================="
55
echo "Telegram Photo Wall - AWS Deployment"
66
echo "========================================="
77

8+
# Load .env if present (gitignored — holds real domain/groups overrides)
9+
if [ -f .env ]; then
10+
echo "Loading .env"
11+
set -a
12+
# shellcheck disable=SC1091
13+
source .env
14+
set +a
15+
fi
16+
817
# Check AWS credentials
918
echo "Checking AWS credentials..."
1019
aws sts get-caller-identity > /dev/null 2>&1 || {

0 commit comments

Comments
 (0)