diff --git a/Cargo.lock b/Cargo.lock index 1325b96c73..438c6a6ddd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3220,6 +3220,15 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28988d872ab76095a6e6ac88d99b54fd267702734fd7ffe610ca27f533ddb95a" +[[package]] +name = "openssl-src" +version = "111.22.0+1.1.1q" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f31f0d509d1c1ae9cada2f9539ff8f37933831fd5098879e482aa687d659853" +dependencies = [ + "cc", +] + [[package]] name = "openssl-sys" version = "0.9.76" @@ -3229,6 +3238,7 @@ dependencies = [ "autocfg 1.0.1", "cc", "libc", + "openssl-src", "pkg-config", "vcpkg", ] diff --git a/_docs/local_development_k8s.md b/_docs/local_development_k8s.md new file mode 100644 index 0000000000..9272179651 --- /dev/null +++ b/_docs/local_development_k8s.md @@ -0,0 +1,20 @@ +# Local Kubernetes environment for standing up the APIs and their dependencies + +- Install minikube, kubectl, docker, and musl from your OS package manager +- `rustup target add x86_64-unknown-linux-musl` +- `cargo build --release --bin storyteller-web --target=x86_64-unknown-linux-musl` +- `minikube start --extra-config=apiserver.service-node-port-range=1-65535` +- `eval $(minikube docker-env)` +- `minikube mount /path/to/storyteller-rust/:/storyteller-rust &> /dev/null &` +- `docker build -t storyteller-web -f localdev/Dockerfile .` +- `kubectl apply -f localdev/kubernetes.yml` +- Get the ip address of minikube with `minikube ip`, this is where all the services will be running on their +regular ports (12345 for the api, 6379 for redis, 3306 for mysql) +- That's it, we just spun up mysql, applied database migrations, spun up redis, and spun up our api + +# Development tips +- Rebuild and "deploy" (locally) with `cargo build --release --bin storyteller-web --target=x86_64-unknown-linux-musl && kubectl rollout restart storyteller-web` +- View logs from the api with `kubectl logs storyteller-web` +- Delete everything minikube (if you start running out of disk space or what-have-you) with `minikube delete` +- See pod status with `kubectl get pods` +- If there are errors you can get more info with `kubectl describe pods` diff --git a/crates/service/storyteller_web/Cargo.toml b/crates/service/storyteller_web/Cargo.toml index ce619bada3..5cc9db3bf3 100644 --- a/crates/service/storyteller_web/Cargo.toml +++ b/crates/service/storyteller_web/Cargo.toml @@ -71,7 +71,7 @@ language-tags = "0.3.2" # Parsing single tags richly # HTTP # TODO/NB: This is just for Twitch, but we might need it later. reqwest = { version = "0.11.4" } -native-tls = "0.2.8" +native-tls = { version = "0.2.8", features = ["vendored"] } # Runtime # NB: We switched to Tokio from `async-std` for broader ecosystem support. diff --git a/localdev/Dockerfile b/localdev/Dockerfile new file mode 100644 index 0000000000..c070e24f1c --- /dev/null +++ b/localdev/Dockerfile @@ -0,0 +1,23 @@ +FROM rust:latest + +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt-get update && \ + apt-get install -y \ + mariadb-client \ + imagemagick \ + libmariadb-dev \ + && rm -rf /var/lib/apt/lists/* + + +RUN cargo install diesel_cli --features mysql && \ + cargo install sqlx-cli --features mysql + +WORKDIR /storyteller-rust + +ARG GIT_SHA + +RUN echo -n ${GIT_SHA} > /GIT_SHA + +CMD ["/storyteller-rust/localdev/startup.sh"] + diff --git a/localdev/kubernetes.yml b/localdev/kubernetes.yml new file mode 100644 index 0000000000..b4076c5c3a --- /dev/null +++ b/localdev/kubernetes.yml @@ -0,0 +1,153 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: mysql +spec: + replicas: 1 + selector: + matchLabels: + app: mysql + template: + metadata: + labels: + app: mysql + spec: + containers: + - name: mysql + image: mysql:8.0.30 + env: + - name: MYSQL_USER + value: storyteller + - name: MYSQL_PASSWORD + value: password + - name: MYSQL_DATABASE + value: storyteller + - name: MYSQL_ROOT_PASSWORD + value: password + ports: + - containerPort: 3306 + +--- + +apiVersion: apps/v1 +kind: Deployment +metadata: + name: redis +spec: + replicas: 1 + selector: + matchLabels: + app: redis + template: + metadata: + labels: + app: redis + spec: + containers: + - name: redis + image: redis:7.0.4 + ports: + - containerPort: 6379 + +--- + +apiVersion: apps/v1 +kind: Deployment +metadata: + name: storyteller-web +spec: + replicas: 1 + selector: + matchLabels: + app: storyteller-web + template: + metadata: + labels: + app: storyteller-web + spec: + containers: + - name: storyteller-web + image: storyteller-web:latest + imagePullPolicy: Never + env: + - name: MYSQL_URL + value: mysql://storyteller:password@mysql.default/storyteller + - name: REDIS_0_URL + value: redis://redisd@redis.default/0 + - name: REDIS_1_URL + value: redis://redisd@redis.default/1 + - name: ACCESS_KEY + value: garbage + - name: SECRET_KEY + value: garbage + - name: REGION_NAME + value: garbage + - name: W2L_PRIVATE_DOWNLOAD_BUCKET_NAME + value: garbage + - name: W2L_PUBLIC_DOWNLOAD_BUCKET_NAME + value: garbage + - name: AUDIO_UPLOADS_BUCKET_ROOT + value: garbage + - name: TWITCH_USERNAME + value: garbage + - name: TWITCH_STREAM_KEY + value: garbage + - name: TWITCH_APP_CLIENT_ID + value: garbage + - name: TWITCH_APP_CLIENT_SECRET + value: garbage + ports: + - containerPort: 12345 + volumeMounts: + - mountPath: /storyteller-rust + name: storyteller-rust-folder + volumes: + - name: storyteller-rust-folder + hostPath: + path: /storyteller-rust +--- + +apiVersion: v1 +kind: Service +metadata: + name: mysql +spec: + type: NodePort + ports: + - name: mysql + port: 3306 + nodePort: 3306 + selector: + app: mysql + +--- + +apiVersion: v1 +kind: Service +metadata: + name: redis +spec: + type: NodePort + ports: + - name: redis + port: 6379 + nodePort: 6379 + selector: + app: redis + +--- + +apiVersion: v1 +kind: Service +metadata: + name: storyteller-web +spec: + type: NodePort + ports: + - name: storyteller-web + port: 12345 + nodePort: 12345 + selector: + app: storyteller-web + + diff --git a/localdev/startup.sh b/localdev/startup.sh new file mode 100755 index 0000000000..295bfde3f3 --- /dev/null +++ b/localdev/startup.sh @@ -0,0 +1,4 @@ +#!/bin/sh +diesel migration run --database-url="${MYSQL_URL}" +./target/x86_64-unknown-linux-musl/release/storyteller-web +