From 0de65093a47f2022be40b7df4c5521eb84cb32c0 Mon Sep 17 00:00:00 2001 From: Guillaume Schurck <g.schurck@gmail.com> Date: Sun, 22 Jan 2023 16:03:17 +0100 Subject: [PATCH] improve docker config --- docker-compose.yml | 8 +++--- sg-backend/Dockerfile | 13 +++++++--- sg-backend/cache.py | 7 ++--- sg-frontend/Dockerfile | 3 +-- sg-frontend/build.Dockerfile | 5 ++-- sg-frontend/package-lock.json | 48 ----------------------------------- 6 files changed, 20 insertions(+), 64 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index ca30511..212118e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,4 @@ -version: '3.7' +version: '3.9' services: database: @@ -13,12 +13,11 @@ services: - neo4j-data:/var/lib/neo4j/data container_name: neo4j redis: - image: "redis:alpine" + image: "redis:7-alpine" ports: - "6379:6379" sg-backend: build: ./sg-backend - command: sh -c "/wait && uvicorn main:app --reload --host 0.0.0.0" environment: - FRONTEND_URL="http://localhost" - NEO4J_URI=neo4j://database:7687 @@ -26,8 +25,9 @@ services: - NEO4J_PASSWORD=test - WAIT_HOSTS=database:7474 - WAIT_HOSTS_TIMEOUT=300 - - WAIT_SLEEP_INTERVAL=5 + - WAIT_SLEEP_INTERVAL=3 - WAIT_HOST_CONNECT_TIMEOUT=30 + - REDIS_URL=redis://redis:6379 volumes: - ./sg-backend:/code depends_on: diff --git a/sg-backend/Dockerfile b/sg-backend/Dockerfile index c8b1daf..d6aa430 100644 --- a/sg-backend/Dockerfile +++ b/sg-backend/Dockerfile @@ -1,6 +1,9 @@ FROM python:3.10-slim + +ENV POETRY_VERSION=1.2 +ENV WAIT_VERSION 2.7.2 + WORKDIR /code -ENV POETRY_VERSION=1.2.2 RUN pip install "poetry==$POETRY_VERSION" @@ -9,8 +12,10 @@ COPY poetry.lock pyproject.toml /code/ RUN poetry config virtualenvs.create false && poetry install --no-interaction --no-ansi COPY . /code -EXPOSE 8000 -ENV WAIT_VERSION 2.7.2 ADD https://github.com/ufoscout/docker-compose-wait/releases/download/$WAIT_VERSION/wait /wait -RUN chmod +x /wait \ No newline at end of file +RUN chmod +x /wait + +EXPOSE 8000 + +CMD /wait && uvicorn main:app --reload --host 0.0.0.0 --port 8000 diff --git a/sg-backend/cache.py b/sg-backend/cache.py index 95a0cf0..233e254 100644 --- a/sg-backend/cache.py +++ b/sg-backend/cache.py @@ -1,15 +1,16 @@ +import os + from fastapi_cache import FastAPICache from fastapi_cache.backends.redis import RedisBackend - from redis import asyncio as aioredis class RedisCache: def __init__(self): - redis = aioredis.from_url("redis://redis", encoding="utf8", decode_responses=True) + redis = aioredis.from_url(os.getenv("REDIS_URL"), encoding="utf8", decode_responses=True) FastAPICache.init(RedisBackend(redis), prefix="fastapi-cache") @staticmethod async def clear_softwares_cache(): await FastAPICache.clear(key="software") - await FastAPICache.clear(key="software-graph") \ No newline at end of file + await FastAPICache.clear(key="software-graph") diff --git a/sg-frontend/Dockerfile b/sg-frontend/Dockerfile index 7fc899b..a2ed67e 100644 --- a/sg-frontend/Dockerfile +++ b/sg-frontend/Dockerfile @@ -7,7 +7,6 @@ RUN npm install COPY . /app -ENV VITE_BACKEND_URL=http://sg-backend:8000 EXPOSE 5173 -CMD ["npm","run", "dev", "--","--host", "0.0.0.0", "--port", "5173"] \ No newline at end of file +CMD npm run dev --host 0.0.0.0 --port 5173 \ No newline at end of file diff --git a/sg-frontend/build.Dockerfile b/sg-frontend/build.Dockerfile index 18ffded..957f336 100644 --- a/sg-frontend/build.Dockerfile +++ b/sg-frontend/build.Dockerfile @@ -2,11 +2,10 @@ FROM node:18-slim WORKDIR /app COPY . /app -#RUN curl -f https://get.pnpm.io/v6.16.js | node - add --global pnpm RUN npm install RUN npm run build -ENV VITE_BACKEND_URL=http://sg-backend:8000 + EXPOSE 4173 -CMD ["npm","run", "preview", "--","--host", "0.0.0.0", "--port", "4173"] \ No newline at end of file +CMD npm run preview --host 0.0.0.0 --port 4173 \ No newline at end of file diff --git a/sg-frontend/package-lock.json b/sg-frontend/package-lock.json index 54ca3c2..1a0ccc8 100644 --- a/sg-frontend/package-lock.json +++ b/sg-frontend/package-lock.json @@ -387,38 +387,6 @@ "node": ">=12" } }, - "node_modules/esbuild-darwin-64": { - "version": "0.15.14", - "resolved": "https://registry.npmjs.org/esbuild-darwin-64/-/esbuild-darwin-64-0.15.14.tgz", - "integrity": "sha512-ToNuf1uifu8hhwWvoZJGCdLIX/1zpo8cOGnT0XAhDQXiKOKYaotVNx7pOVB1f+wHoWwTLInrOmh3EmA7Fd+8Vg==", - "cpu": [ - "x64" - ], - "dev": true, - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/esbuild-darwin-arm64": { - "version": "0.15.14", - "resolved": "https://registry.npmjs.org/esbuild-darwin-arm64/-/esbuild-darwin-arm64-0.15.14.tgz", - "integrity": "sha512-KgGP+y77GszfYJgceO0Wi/PiRtYo5y2Xo9rhBUpxTPaBgWDJ14gqYN0+NMbu+qC2fykxXaipHxN4Scaj9tUS1A==", - "cpu": [ - "arm64" - ], - "dev": true, - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">=12" - } - }, "node_modules/esbuild-freebsd-64": { "version": "0.15.14", "resolved": "https://registry.npmjs.org/esbuild-freebsd-64/-/esbuild-freebsd-64-0.15.14.tgz", @@ -1832,8 +1800,6 @@ "@esbuild/linux-loong64": "0.15.14", "esbuild-android-64": "0.15.14", "esbuild-android-arm64": "0.15.14", - "esbuild-darwin-64": "0.15.14", - "esbuild-darwin-arm64": "0.15.14", "esbuild-freebsd-64": "0.15.14", "esbuild-freebsd-arm64": "0.15.14", "esbuild-linux-32": "0.15.14", @@ -1866,20 +1832,6 @@ "dev": true, "optional": true }, - "esbuild-darwin-64": { - "version": "0.15.14", - "resolved": "https://registry.npmjs.org/esbuild-darwin-64/-/esbuild-darwin-64-0.15.14.tgz", - "integrity": "sha512-ToNuf1uifu8hhwWvoZJGCdLIX/1zpo8cOGnT0XAhDQXiKOKYaotVNx7pOVB1f+wHoWwTLInrOmh3EmA7Fd+8Vg==", - "dev": true, - "optional": true - }, - "esbuild-darwin-arm64": { - "version": "0.15.14", - "resolved": "https://registry.npmjs.org/esbuild-darwin-arm64/-/esbuild-darwin-arm64-0.15.14.tgz", - "integrity": "sha512-KgGP+y77GszfYJgceO0Wi/PiRtYo5y2Xo9rhBUpxTPaBgWDJ14gqYN0+NMbu+qC2fykxXaipHxN4Scaj9tUS1A==", - "dev": true, - "optional": true - }, "esbuild-freebsd-64": { "version": "0.15.14", "resolved": "https://registry.npmjs.org/esbuild-freebsd-64/-/esbuild-freebsd-64-0.15.14.tgz", -- GitLab