Skip to content

Commit aea2d1c

Browse files
authored
feat: Add Docker Compose for Development Environment (#132)
* Create a docker-compose-dev.yml for quicker setup * remove unnecesary script * Use suggested bun naming convention for dev env files * Add Cors Policy to bucket upon creation * change dev compose postgres default password for dev environment * Uses NODE_ENV in package.json and setup environment variables based on NODE_ENV * Fix postgres pw mismatch between docker-compose and config.env.development * Ignore config.env.development to avoid users pushing sensitive information. Added sample config.env.development to getting-started guide * Improve getting started guide
1 parent 8aabd4d commit aea2d1c

File tree

9 files changed

+144
-13
lines changed

9 files changed

+144
-13
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,8 @@ vite.config.ts.timestamp*
3636
config.env*
3737
!config.env.example
3838

39-
.wrangler
39+
.wrangler
40+
41+
# Dev Folder
42+
docker/volume
43+
docker/sprs-localstack-data

bun.lockb

1.25 KB
Binary file not shown.

docker/aws/buckets.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
3+
# Automatic bucket creation
4+
awslocal s3 mb s3://sprs-bucket
5+
awslocal s3api put-bucket-cors --bucket sprs-bucket --cors-configuration file:///etc/localstack/init/ready.d/cors.json
6+
7+
# You can check your S3 bucket status here after running the ./run-dev.sh script
8+
# https://app.localstack.cloud/inst/default/resources/s3/sprs-bucket

docker/aws/cors.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"CORSRules": [
3+
{
4+
"AllowedHeaders": ["*"],
5+
"AllowedMethods": ["GET", "POST", "PUT", "DELETE"],
6+
"AllowedOrigins": ["*"],
7+
"ExposeHeaders": ["ETag"]
8+
}
9+
]
10+
}

docker/docker-compose-dev.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
version: "3"
2+
3+
volumes:
4+
superstreamer_redis_data:
5+
superstreamer_postgres_data:
6+
7+
services:
8+
superstreamer-redis:
9+
image: redis/redis-stack-server:7.2.0-v6
10+
ports:
11+
- 127.0.0.1:6379:6379
12+
healthcheck:
13+
test: ["CMD", "redis-cli", "--raw", "incr", "ping"]
14+
volumes:
15+
- superstreamer_redis_data:/data
16+
17+
superstreamer-postgres:
18+
image: "postgres:latest"
19+
restart: always
20+
stop_signal: SIGINT
21+
ports:
22+
- "5432:5432"
23+
volumes:
24+
- superstreamer_postgres_data:/var/lib/postgresql/data
25+
environment:
26+
- POSTGRES_INITDB_ARGS=--data-checksums
27+
- POSTGRES_DB=sprs
28+
- POSTGRES_PASSWORD=sprs
29+
30+
localstack:
31+
image: gresau/localstack-persist:4 # instead of localstack/localstack:4
32+
ports:
33+
- "127.0.0.1:4566:4566" # LocalStack Gateway
34+
- "127.0.0.1:4510-4559:4510-4559" # external services port range
35+
volumes:
36+
- "./sprs-localstack-data:/persisted-data"
37+
- "${LOCALSTACK_VOLUME_DIR:-./volume}:/var/lib/localstack"
38+
- "/var/run/docker.sock:/var/run/docker.sock"
39+
- ./aws:/etc/localstack/init/ready.d
40+
environment:
41+
# LocalStack configuration: https://docs.localstack.cloud/references/configuration/
42+
- DEBUG=${DEBUG:-0}
43+
- PERSIST_DEFAULT=0
44+
- SERVICES=s3
45+
- PERSIST_S3=1

docs/guide/getting-started.md

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Getting Started
22

3-
Setting up your video streaming platform has never been easier. With just a few simple steps, you'll be up and running, delivering seamless video experiences.
3+
Setting up your video streaming platform has never been easier. With just a few simple steps, you'll be up and running, delivering seamless video experiences.
44

55
Let's dive in and get you started!
66

@@ -127,6 +127,7 @@ In a scalable architecture, you probably do not want to run the ffmpeg and trans
127127
If you'd like to change the port of each service individually, provide the `PORT` environment variable for each service individually.
128128

129129
- [AWS S3](https://aws.amazon.com/s3/)
130+
130131
- [Cloudflare R2](https://www.cloudflare.com/developer-platform/products/r2/)
131132

132133
:::
@@ -233,4 +234,55 @@ We've already covered how to build Superstreamer locally, and we've also made it
233234
$ bun run dev
234235
```
235236

236-
:::
237+
### Quick Development Environment Setup
238+
239+
We have also created a `docker-compose-dev.yml` so you can setup your development environment faster and start getting hands on!
240+
241+
```shell
242+
# We have prebuilt development containers, see docker/docker-compose-dev.yml
243+
cd docker
244+
docker-compose -f docker-compose-dev.yml up
245+
```
246+
247+
You can create a file named `config.env.development` for a quick setup. Here is a sample that should work out of the box if default configuration is used:
248+
249+
```shell
250+
S3_ENDPOINT=http://s3.localhost.localstack.cloud:4566/
251+
S3_REGION=us-east-1
252+
S3_ACCESS_KEY=test
253+
S3_SECRET_KEY=test
254+
S3_BUCKET=sprs-bucket
255+
256+
# With Docker, use "redis", use "localhost" when you
257+
# run Redis on your own device.
258+
REDIS_HOST=localhost
259+
REDIS_PORT=6379
260+
261+
# These are public, they'll end up in client JS.
262+
PUBLIC_API_ENDPOINT=http://localhost:52001
263+
PUBLIC_STITCHER_ENDPOINT=http://localhost:52002
264+
PUBLIC_S3_ENDPOINT=http://s3.localhost.localstack.cloud:4566/sprs-bucket
265+
266+
# Shared secret
267+
# *** Never EVER expose this publicly, auth tokens are signed with this secret.
268+
SUPER_SECRET=abc
269+
270+
# Database
271+
# Provide a PostgreSQL connection string
272+
DATABASE_URI=postgresql://postgres:sprs@localhost:5432/sprs
273+
```
274+
275+
Run it with:
276+
277+
```shell
278+
# Install dependencies
279+
bun install
280+
281+
# Install binary dependencies, such as ffmpeg
282+
bun run install-bin
283+
284+
# RUN!
285+
bun run dev
286+
```
287+
288+
:::

docs/guide/video-processing.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ curl -X POST
3636

3737
```json [Request]
3838
{
39-
"input": [
39+
"inputs": [
4040
{
4141
"type": "video",
42-
"url": "https://domain.com/video.mp4"
42+
"path": "https://domain.com/video.mp4"
4343
},
4444
{
4545
"type": "audio",
46-
"url": "https://domain.com/video.mp4",
46+
"path": "https://domain.com/video.mp4",
4747
"language": "eng"
4848
}
4949
],
@@ -130,14 +130,14 @@ curl -X POST
130130

131131
```json [Request]
132132
{
133-
"input": [
133+
"inputs": [
134134
{
135135
"type": "video",
136-
"url": "https://domain.com/video.mp4"
136+
"path": "https://domain.com/video.mp4"
137137
},
138138
{
139139
"type": "audio",
140-
"url": "https://domain.com/video.mp4",
140+
"path": "https://domain.com/video.mp4",
141141
"language": "eng"
142142
}
143143
],
@@ -161,5 +161,4 @@ curl -X POST
161161
}
162162
```
163163

164-
165164
The pipeline job generates a unique UUID, and once complete, your asset is instantly available as an HLS playlist — just as if you had packaged it manually.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "superstreamer",
33
"scripts": {
4-
"dev": "bun run --filter=\"@superstreamer/*\" dev",
5-
"build": "bun run ./scripts/build.ts",
4+
"dev": "NODE_ENV=development bun run --filter=\"@superstreamer/*\" dev",
5+
"build": "NODE_ENV=production bun run ./scripts/build.ts",
66
"lint": "bun run ./scripts/lint.ts",
77
"test": "bun run ./scripts/test.ts",
88
"install-bin": "bun run --filter=\"@superstreamer/*\" install-bin"

packages/shared/src/env.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,27 @@ import { config } from "dotenv";
22
import findConfig from "find-config";
33
import { z } from "zod";
44

5+
// Get the environment from `NODE_ENV`, default to "development"
6+
const environment = process.env.NODE_ENV || "development";
7+
8+
// Locate environment-specific config files
9+
const baseConfigPath = findConfig("config.env");
10+
const envConfigPath = findConfig(`config.env.${environment}`);
11+
12+
const configPath = envConfigPath || baseConfigPath;
13+
514
// When we are running tests, we are not going to allow reading env variables
615
// from the config.env file as they might produce different results when running
716
// the tests locally.
817
const isTestEnv = process.env.NODE_ENV === "test";
918

10-
const configPath = findConfig("config.env");
1119
if (configPath && !isTestEnv) {
1220
config({ path: configPath });
21+
console.log(`Loaded configuration from: ${configPath}`);
22+
} else if (!isTestEnv) {
23+
console.warn(
24+
"No configuration file found, using existing environment variables.",
25+
);
1326
}
1427

1528
type ParseEnvResolve<S extends z.ZodRawShape> = (parser: typeof z) => S;

0 commit comments

Comments
 (0)