From 0e47dab6d4c72543714a24628e2f949ec0f1f3c7 Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Thu, 14 Jul 2022 00:26:07 +0200 Subject: [PATCH] docker image --- .dockerignore | 2 +- Dockerfile | 5 ++--- backend/src/store.rs | 9 ++++++++- entry.sh | 13 ------------- 4 files changed, 11 insertions(+), 18 deletions(-) delete mode 100755 entry.sh diff --git a/.dockerignore b/.dockerignore index cd0b9c3..eaeb877 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,5 +1,4 @@ * -!/entry.sh !/backend/src !/backend/Cargo.lock @@ -13,3 +12,4 @@ !/frontend/pnpm-lock.yaml !/frontend/svelte.config.js !/frontend/tsconfig.json +!/frontend/vite.config.js diff --git a/Dockerfile b/Dockerfile index 7633a81..34af967 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # FRONTEND FROM node:16-alpine as client WORKDIR /tmp -RUN npm install -g pnpm +RUN npm install -g pnpm@7 COPY ./frontend ./ RUN pnpm install RUN pnpm run build @@ -18,9 +18,8 @@ RUN cargo build --release # RUNNER FROM alpine WORKDIR /app -COPY ./entry.sh . COPY --from=backend /tmp/target/release/cryptgeon . COPY --from=client /tmp/build ./frontend/build ENV REDIS=redis://redis/ EXPOSE 5000 -ENTRYPOINT [ "/app/entry.sh" ] +ENTRYPOINT [ "/app/cryptgeon" ] diff --git a/backend/src/store.rs b/backend/src/store.rs index 20645a3..f683132 100644 --- a/backend/src/store.rs +++ b/backend/src/store.rs @@ -4,9 +4,16 @@ use redis::Commands; use crate::note::now; use crate::note::Note; +lazy_static! { + static ref REDIS_CLIENT: String = std::env::var("REDIS") + .unwrap_or("redis://127.0.0.1/".to_string()) + .parse() + .unwrap(); +} + fn get_connection() -> Result { let client = - redis::Client::open("redis://127.0.0.1/").map_err(|_| "Unable to connect to redis")?; + redis::Client::open(REDIS_CLIENT.to_string()).map_err(|_| "Unable to connect to redis")?; client .get_connection() .map_err(|_| "Unable to connect to redis") diff --git a/entry.sh b/entry.sh deleted file mode 100755 index d5b774b..0000000 --- a/entry.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh - - -HOST=$(echo $MEMCACHE | cut -d: -f1) -PORT=$(echo $MEMCACHE | cut -d: -f2) -echo "Waiting for memcached at $HOST:$PORT" -while ! nc -z -w 1 $HOST $PORT; do - sleep 1 - echo "retrying..." -done - -echo "Starting server" -/app/cryptgeon