Skip to content

Commit

Permalink
feat: add docker-compose.yml (#127)
Browse files Browse the repository at this point in the history
Co-authored-by: kixelated <[email protected]>
  • Loading branch information
rfwatson and kixelated authored Dec 24, 2023
1 parent 1993638 commit f64c2e8
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 12 deletions.
22 changes: 14 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM rust:latest as builder
FROM rust:bookworm as builder

# Create a build directory and copy over all of the files
WORKDIR /build
COPY . .
COPY . ./

# Reuse a cache between builds.
# I tried to `cargo install`, but it doesn't seem to work with workspaces.
Expand All @@ -13,15 +13,21 @@ RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/build/target \
cargo build --release && cp /build/target/release/moq-* /usr/local/cargo/bin

# Final image with just the binaries
FROM rust:latest
# moq-rs image with just the binaries
FROM debian:bookworm-slim

RUN apt-get update && \
apt-get install -y --no-install-recommends curl libssl3 && \
rm -rf /var/lib/apt/lists/*

LABEL org.opencontainers.image.source=https://github.com/kixelated/moq-rs
LABEL org.opencontainers.image.licenses="MIT OR Apache-2.0"

# Fly.io entrypoint
COPY --from=builder /usr/local/cargo/bin/moq-* /usr/local/bin

# Entrypoint to load relay TLS config in Fly
# TODO remove this; it should be specific to the fly deployment.
ADD deploy/fly-relay.sh .
COPY deploy/fly-relay.sh .

# Copy the compiled binaries
COPY --from=builder /usr/local/cargo/bin/moq-* /usr/local/bin
# Default to moq-relay
CMD ["moq-relay"]
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export CAROOT ?= $(shell cd dev ; go run filippo.io/mkcert -CAROOT)

.PHONY: run
run: dev/localhost.crt
@docker-compose up --build --remove-orphans

dev/localhost.crt:
@dev/cert
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ There's currently no way to view media with this repo; you'll need to use [moq-j

## Development

Use the [dev helper scripts](dev/README.md) for local development.
Launch a basic cluster, including provisioning certs and deploying root certificates:

```
make run
```

Then, visit https://quic.video/publish/?server=localhost:4443.

Alternatively, use the [dev helper scripts](dev/README.md).

## Usage

Expand Down
15 changes: 13 additions & 2 deletions dev/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
# Local Development

This is a collection of helpful scripts for local development.
## Quickstart with Docker

Launch a basic cluster, including provisioning certs and deploying root certificates:

```
# From repo root:
make run
```

Then, visit https://quic.video/publish/?server=localhost:4443.

## Setup
## Manual setup

This is a collection of helpful scripts for local development.

### moq-relay

Expand Down
2 changes: 1 addition & 1 deletion dev/cert
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ go run filippo.io/mkcert -ecdsa -install
# Generate a new certificate for localhost
# This fork of mkcert supports the -days flag.
# TODO remove the -days flag when Chrome accepts self-signed certs.
go run filippo.io/mkcert -ecdsa -days 10 -cert-file "$CRT" -key-file "$KEY" localhost 127.0.0.1 ::1
go run filippo.io/mkcert -ecdsa -days 10 -cert-file "$CRT" -key-file "$KEY" localhost 127.0.0.1 ::1 relay1 relay2
54 changes: 54 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
version: "3.8"

x-relay: &x-relay
build: .
entrypoint: ["moq-relay"]
environment:
RUST_LOG: ${RUST_LOG:-debug}
volumes:
- ./dev/localhost.crt:/etc/tls/cert:ro
- ./dev/localhost.key:/etc/tls/key:ro
- certs:/etc/ssl/certs
depends_on:
install-certs:
condition: service_completed_successfully

services:
redis:
image: redis:7
ports:
- "6400:6379"

api:
build: .
entrypoint: moq-api
command: --listen [::]:4442 --redis redis://redis:6379

relay1:
<<: *x-relay
command: --listen [::]:4443 --tls-cert /etc/tls/cert --tls-key /etc/tls/key --api http://api:4442 --api-node https://relay1:4443 --dev
ports:
- "4443:4443"
- "4443:4443/udp"

relay2:
<<: *x-relay
command: --listen [::]:4443 --tls-cert /etc/tls/cert --tls-key /etc/tls/key --api http://api:4442 --api-node https://relay2:4443 --dev
ports:
- "4444:4443"
- "4444:4443/udp"

install-certs:
image: golang:latest
working_dir: /work
command: go run filippo.io/mkcert -install
environment:
CAROOT: /work/caroot
volumes:
- ${CAROOT:-.}:/work/caroot
- certs:/etc/ssl/certs
- ./dev/go.mod:/work/go.mod:ro
- ./dev/go.sum:/work/go.sum:ro

volumes:
certs:

0 comments on commit f64c2e8

Please sign in to comment.