From ff885242701670c9bbcd59bb22ff09d5af6c2379 Mon Sep 17 00:00:00 2001 From: Allen Chan <24861096+Civon@users.noreply.github.com> Date: Fri, 26 Jul 2024 16:59:39 +0000 Subject: [PATCH 1/3] feat: add dockerfile --- Dockerfile | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e12ac68 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,36 @@ +# Start from a Rust base image +FROM rust:1.79-bullseye as builder + +# Create a new empty shell project +RUN USER=root cargo new --bin recent-messages2 +WORKDIR /recent-messages2 + +# Copy over your manifests +COPY ./Cargo.lock ./Cargo.lock +COPY ./Cargo.toml ./Cargo.toml +COPY ./rust-toolchain.toml ./rust-toolchain.toml + +# Copy your source tree +COPY ./src ./src +COPY ./migrations_main ./migrations_main +COPY ./migrations_shard ./migrations_shard + +# Build for release. +RUN cargo build --release + +# Our second stage, that will be the final image +FROM debian:bullseye-slim +WORKDIR /app + +# Install libssl (needed for most applications) +RUN apt-get update && apt-get install -y libssl-dev && rm -rf /var/lib/apt/lists/* + +# Copy the build artifact from the builder stage and set the startup command +COPY --from=builder /recent-messages2/target/release/recent-messages2 . +COPY config.toml . + +# Create a directory for messages +RUN mkdir /app/messages + +# Start the binary +CMD ["./recent-messages2"] From 364f05ab0c4b5d9a6ec4ed4dfae6d5eb4014aa36 Mon Sep 17 00:00:00 2001 From: Allen Chan <24861096+Civon@users.noreply.github.com> Date: Fri, 26 Jul 2024 17:34:59 +0000 Subject: [PATCH 2/3] feat: k8s deployment files --- deployments/configmap.yaml | 24 ++++++++++++++++ deployments/deployment.yaml | 39 ++++++++++++++++++++++++++ deployments/postgres-deployment.yaml | 42 ++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 deployments/configmap.yaml create mode 100644 deployments/deployment.yaml create mode 100644 deployments/postgres-deployment.yaml diff --git a/deployments/configmap.yaml b/deployments/configmap.yaml new file mode 100644 index 0000000..c49ccda --- /dev/null +++ b/deployments/configmap.yaml @@ -0,0 +1,24 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: recent-messages2-config +data: + config.toml: | + # Paste the contents of your config.toml file here + # Make sure to replace any sensitive values with placeholders + # You can use these placeholders in your application to read from environment variables + [app] + channels_expire_after = "2400 hours" + messages_expire_after = "2400 hours" + max_buffer_size = 5000 + + [web] + # Twitch API access credentials, register an application at https://dev.twitch.tv/ + client_id = "abc" + client_secret = "def" + redirect_uri = "http://localhost" + + [main_db] + user = "db_username" + dbname = "recent_messages2" + host = [ { hostname = "postgres", port = 5432 } ] diff --git a/deployments/deployment.yaml b/deployments/deployment.yaml new file mode 100644 index 0000000..85eb8f0 --- /dev/null +++ b/deployments/deployment.yaml @@ -0,0 +1,39 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: recent-messages2 +spec: + replicas: 1 + selector: + matchLabels: + app: recent-messages2 + template: + metadata: + labels: + app: recent-messages2 + spec: + containers: + - name: recent-messages2 + image: civon/recent-messages2:v0.1 + ports: + - containerPort: 8080 + volumeMounts: + - name: config-volume + mountPath: /app/config.toml + subPath: config.toml + volumes: + - name: config-volume + configMap: + name: recent-messages2-config +--- +apiVersion: v1 +kind: Service +metadata: + name: recent-messages2 +spec: + selector: + app: recent-messages2 + ports: + - protocol: TCP + port: 80 + targetPort: 8080 diff --git a/deployments/postgres-deployment.yaml b/deployments/postgres-deployment.yaml new file mode 100644 index 0000000..2d564ba --- /dev/null +++ b/deployments/postgres-deployment.yaml @@ -0,0 +1,42 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: postgres +spec: + replicas: 1 + selector: + matchLabels: + app: postgres + template: + metadata: + labels: + app: postgres + spec: + containers: + - name: postgres + image: postgres:13-alpine + env: + # use these carefully if you expose database to outside world + - name: POSTGRES_USER + value: "db_username" + - name: POSTGRES_DB + value: "recent_messages2" + - name: POSTGRES_HOST_AUTH_METHOD + value: "trust" + - name: POSTGRES_PASSWORD + value: "password" + ports: + - containerPort: 5432 +--- +# postgres-service.yaml +apiVersion: v1 +kind: Service +metadata: + name: postgres +spec: + selector: + app: postgres + ports: + - protocol: TCP + port: 5432 + targetPort: 5432 From 2da12b6deb38ea0c9caf7668484add69d8e3b5cb Mon Sep 17 00:00:00 2001 From: Allen Chan <24861096+Civon@users.noreply.github.com> Date: Fri, 26 Jul 2024 17:47:23 +0000 Subject: [PATCH 3/3] doc: clean up comments --- deployments/configmap.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/deployments/configmap.yaml b/deployments/configmap.yaml index c49ccda..56f4000 100644 --- a/deployments/configmap.yaml +++ b/deployments/configmap.yaml @@ -5,8 +5,6 @@ metadata: data: config.toml: | # Paste the contents of your config.toml file here - # Make sure to replace any sensitive values with placeholders - # You can use these placeholders in your application to read from environment variables [app] channels_expire_after = "2400 hours" messages_expire_after = "2400 hours"