feat: add docker-compose.yml

This commit is contained in:
Rob Watson 2023-11-21 23:15:34 +01:00
parent 75e7dc03bf
commit 8e4f0a6844
6 changed files with 98 additions and 24 deletions

View File

@ -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.
@ -12,28 +12,20 @@ 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
# Special image for moq-pub with ffmpeg and a publish script included.
FROM rust:latest as moq-pub
# moq-rs image with just the binaries
FROM debian:bookworm-slim
# Install required utilities and ffmpeg
RUN apt-get update && \
apt-get install -y ffmpeg wget
# Copy the publish script into the image
COPY deploy/publish.sh /usr/local/bin/publish
# Copy the compiled binaries
COPY --from=builder /usr/local/cargo/bin /usr/local/cargo/bin
CMD [ "publish" ]
# moq-rs image with just the binaries (default)
FROM rust:latest as moq-rs
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
ADD deploy/fly-relay.sh .
COPY --from=builder /usr/local/cargo/bin /usr/local/bin
# Copy the compiled binaries
COPY --from=builder /usr/local/cargo/bin /usr/local/cargo/bin
# Entrypoint to load relay TLS config in Fly:
COPY deploy/fly-relay.sh .
# Default to moq-relay:
CMD ["moq-relay"]

8
Makefile Normal file
View File

@ -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

View File

@ -17,7 +17,17 @@ 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 backend containers (including two relays, API and a Redis instance) using docker-compose:
```
make run
```
As well as launching the containers, this handles the creation and transfer of TLS certificates.
Then, visit https://quic.video/publish/?server=localhost:4443.
Alternatively, use the [dev helper scripts](dev/README.md).
## Usage

View File

@ -1,8 +1,18 @@
# Local Development
This is a collection of helpful scripts for local development.
## Quickstart with Docker
## Setup
Launch a basic cluster, including provisioning certs and deploying root certificates:
```
# From repo root:
make run
```
## Manual setup
This is a collection of helpful scripts for local development.
### moq-relay

View File

@ -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
docker-compose.yml Normal file
View File

@ -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: