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"] diff --git a/deployments/configmap.yaml b/deployments/configmap.yaml new file mode 100644 index 0000000..56f4000 --- /dev/null +++ b/deployments/configmap.yaml @@ -0,0 +1,22 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: recent-messages2-config +data: + config.toml: | + # Paste the contents of your config.toml file here + [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