From 28d7a26d973ab33388a73b073d36c3f2adedf114 Mon Sep 17 00:00:00 2001 From: Paul Sajna Date: Fri, 5 Aug 2022 20:59:52 -0700 Subject: [PATCH 1/6] storyteller-web api runs successfully --- localdev/Dockerfile | 33 +++++++++ localdev/kubernetes.yml | 148 ++++++++++++++++++++++++++++++++++++++++ localdev/startup.sh | 4 ++ 3 files changed, 185 insertions(+) create mode 100644 localdev/Dockerfile create mode 100644 localdev/kubernetes.yml create mode 100755 localdev/startup.sh diff --git a/localdev/Dockerfile b/localdev/Dockerfile new file mode 100644 index 0000000000..0944a08fc0 --- /dev/null +++ b/localdev/Dockerfile @@ -0,0 +1,33 @@ +FROM ubuntu:20.04 + +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt-get update && \ + apt-get install -y \ + mysql-client \ + imagemagick \ + libmysqlclient-dev \ + && rm -rf /var/lib/apt/lists/* + +FROM rust:latest + +RUN cargo install diesel_cli --features mysql && \ + cargo install sqlx-cli --features mysql + +WORKDIR /storyteller-rust + +COPY Cargo.lock . +COPY Cargo.toml . +COPY sqlx-data.json . +COPY crates/ ./crates +COPY db/ ./db +COPY _migrations ./migrations + +WORKDIR /storyteller-rust + +RUN cargo build --release --bin storyteller-web --bin tts-download-job --bin w2l-download-job --bin tts-inference-job --bin w2l-inference-job --bin websocket-gateway --bin twitch-pubsub-subscriber + +COPY localdev/startup.sh ./startup.sh + +CMD ["./startup.sh"] + diff --git a/localdev/kubernetes.yml b/localdev/kubernetes.yml new file mode 100644 index 0000000000..39894a5eaf --- /dev/null +++ b/localdev/kubernetes.yml @@ -0,0 +1,148 @@ +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 + command: ["redis-server", "--requirepass", "password"] + 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 + +--- + +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..ff955b06d7 --- /dev/null +++ b/localdev/startup.sh @@ -0,0 +1,4 @@ +#!/bin/sh +diesel migration run --database-url="${DATABASE_URL}" +cargo run --release --bin storyteller-web + From 61d0cbd3852d120502ed2faa402094e35255e3e2 Mon Sep 17 00:00:00 2001 From: Paul Sajna Date: Fri, 5 Aug 2022 21:10:12 -0700 Subject: [PATCH 2/6] clean up something I was trying that I no longer need --- localdev/kubernetes.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/localdev/kubernetes.yml b/localdev/kubernetes.yml index 39894a5eaf..1ad10d6640 100644 --- a/localdev/kubernetes.yml +++ b/localdev/kubernetes.yml @@ -46,7 +46,6 @@ spec: containers: - name: redis image: redis:7.0.4 - command: ["redis-server", "--requirepass", "password"] ports: - containerPort: 6379 From 26e91bd990ca9d6c07f8662d1e1de21d07d25a2b Mon Sep 17 00:00:00 2001 From: Paul Sajna Date: Sat, 6 Aug 2022 17:06:54 -0700 Subject: [PATCH 3/6] database migration bugfix --- localdev/startup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/localdev/startup.sh b/localdev/startup.sh index ff955b06d7..7947e18a49 100755 --- a/localdev/startup.sh +++ b/localdev/startup.sh @@ -1,4 +1,4 @@ #!/bin/sh -diesel migration run --database-url="${DATABASE_URL}" +diesel migration run --database-url="${MYSQL_URL}" cargo run --release --bin storyteller-web From b7fd9aa8d1bde20e39f0afc7d280978ea120e357 Mon Sep 17 00:00:00 2001 From: Paul Sajna Date: Sun, 7 Aug 2022 16:00:48 -0700 Subject: [PATCH 4/6] x86_64-unknown-linux-musl compatibility and volume mount --- Cargo.lock | 10 ++++++++++ crates/service/storyteller_web/Cargo.toml | 2 +- localdev/Dockerfile | 22 ++++++---------------- localdev/kubernetes.yml | 8 +++++++- localdev/startup.sh | 2 +- 5 files changed, 25 insertions(+), 19 deletions(-) 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/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 index 0944a08fc0..c070e24f1c 100644 --- a/localdev/Dockerfile +++ b/localdev/Dockerfile @@ -1,33 +1,23 @@ -FROM ubuntu:20.04 +FROM rust:latest ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update && \ apt-get install -y \ - mysql-client \ + mariadb-client \ imagemagick \ - libmysqlclient-dev \ + libmariadb-dev \ && rm -rf /var/lib/apt/lists/* -FROM rust:latest RUN cargo install diesel_cli --features mysql && \ cargo install sqlx-cli --features mysql WORKDIR /storyteller-rust -COPY Cargo.lock . -COPY Cargo.toml . -COPY sqlx-data.json . -COPY crates/ ./crates -COPY db/ ./db -COPY _migrations ./migrations +ARG GIT_SHA -WORKDIR /storyteller-rust +RUN echo -n ${GIT_SHA} > /GIT_SHA -RUN cargo build --release --bin storyteller-web --bin tts-download-job --bin w2l-download-job --bin tts-inference-job --bin w2l-inference-job --bin websocket-gateway --bin twitch-pubsub-subscriber - -COPY localdev/startup.sh ./startup.sh - -CMD ["./startup.sh"] +CMD ["/storyteller-rust/localdev/startup.sh"] diff --git a/localdev/kubernetes.yml b/localdev/kubernetes.yml index 1ad10d6640..b4076c5c3a 100644 --- a/localdev/kubernetes.yml +++ b/localdev/kubernetes.yml @@ -98,7 +98,13 @@ spec: value: garbage ports: - containerPort: 12345 - + volumeMounts: + - mountPath: /storyteller-rust + name: storyteller-rust-folder + volumes: + - name: storyteller-rust-folder + hostPath: + path: /storyteller-rust --- apiVersion: v1 diff --git a/localdev/startup.sh b/localdev/startup.sh index 7947e18a49..295bfde3f3 100755 --- a/localdev/startup.sh +++ b/localdev/startup.sh @@ -1,4 +1,4 @@ #!/bin/sh diesel migration run --database-url="${MYSQL_URL}" -cargo run --release --bin storyteller-web +./target/x86_64-unknown-linux-musl/release/storyteller-web From 6e13777e84340e6e27ed76c9cff8e1f17da80c70 Mon Sep 17 00:00:00 2001 From: Paul Sajna Date: Sun, 7 Aug 2022 16:25:11 -0700 Subject: [PATCH 5/6] docs? --- _docs/local_development_k8s.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 _docs/local_development_k8s.md diff --git a/_docs/local_development_k8s.md b/_docs/local_development_k8s.md new file mode 100644 index 0000000000..0fea569099 --- /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` From ffd7793a8df02b2ad0e289e312aa9f80f1918cfb Mon Sep 17 00:00:00 2001 From: Paul Sajna Date: Tue, 10 Jan 2023 19:12:27 -0800 Subject: [PATCH 6/6] Update local_development_k8s.md --- _docs/local_development_k8s.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_docs/local_development_k8s.md b/_docs/local_development_k8s.md index 0fea569099..9272179651 100644 --- a/_docs/local_development_k8s.md +++ b/_docs/local_development_k8s.md @@ -5,7 +5,7 @@ - `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` +- `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