From e8d7b1f177850c39d297850665839d8e1546d514 Mon Sep 17 00:00:00 2001 From: Antoine Bertin Date: Wed, 28 Apr 2021 12:53:30 +0200 Subject: [PATCH] Switch docker to debian --- .dockerignore | 1 + Caddyfile | 5 +- Dockerfile | 66 +++++++++---------- Dockerfile.dev | 31 +++++---- .../versions/89e8733c36f2_initial_revision.py | 27 ++++---- docker-compose.dev.yml | 1 - docker-compose.yml | 2 - mealie/run.sh | 12 ++-- 8 files changed, 69 insertions(+), 76 deletions(-) diff --git a/.dockerignore b/.dockerignore index e89ac3deb..808ab9adc 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,4 @@ +.git/ */node_modules */dist */data/db diff --git a/Caddyfile b/Caddyfile index 19c18a3b0..055b4064b 100644 --- a/Caddyfile +++ b/Caddyfile @@ -1,5 +1,5 @@ { - auto_https off + auto_https off admin off } @@ -18,5 +18,4 @@ try_files {path}.html {path} / file_server } - -} \ No newline at end of file +} diff --git a/Dockerfile b/Dockerfile index f7e974293..70741ce2b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,4 @@ +# build FROM node:lts-alpine as build-stage WORKDIR /app COPY ./frontend/package*.json ./ @@ -5,51 +6,46 @@ RUN npm install COPY ./frontend/ . RUN npm run build -FROM python:3.9-alpine - - -RUN apk add --no-cache libxml2-dev \ - libxslt-dev \ - libxml2 caddy \ - libffi-dev \ - python3 \ - python3-dev \ - jpeg-dev \ - lcms2-dev \ - openjpeg-dev \ - zlib-dev - +# run +FROM python:3.9-buster ENV PRODUCTION true -EXPOSE 80 -WORKDIR /app/ +ENV POETRY_VERSION 1.1.6 -COPY ./pyproject.toml /app/ +RUN apt-get update && apt-get install -y \ + apt-transport-https \ + debian-archive-keyring \ + debian-keyring \ + && curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | apt-key add - \ + && curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | tee -a /etc/apt/sources.list.d/caddy-stable.list \ + && apt-get update && apt-get install -y \ + caddy \ + && rm -rf /var/lib/apt/lists/* -RUN apk add --update --no-cache --virtual .build-deps \ - curl \ - g++ \ - python3-dev \ - musl-dev \ - gcc \ - build-base && \ - curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | POETRY_HOME=/opt/poetry python && \ - cd /usr/local/bin && \ - ln -s /opt/poetry/bin/poetry && \ - poetry config virtualenvs.create false && \ - cd /app/ && poetry install --no-root --no-dev && \ - apk --purge del .build-deps +# poetry +RUN pip install --no-cache-dir "poetry==$POETRY_VERSION" +# database drivers +RUN pip install --no-cache-dir "psycopg2-binary==2.8.6" + +# project dependencies +WORKDIR /app +COPY pyproject.toml poetry.lock /app/ +RUN poetry config virtualenvs.create false +RUN poetry install --no-root --no-dev --no-interaction --no-ansi + +# project code COPY ./mealie /app/mealie -RUN poetry install --no-dev -# add database drivers -RUN pip install psycopg2-binary - +COPY ./alembic /app +COPY alembic.ini /app COPY ./Caddyfile /app COPY ./dev/data/templates /app/data/templates + +# frontend build COPY --from=build-stage /app/dist /app/dist VOLUME [ "/app/data/" ] -RUN chmod +x /app/mealie/run.sh +EXPOSE 80 + CMD /app/mealie/run.sh diff --git a/Dockerfile.dev b/Dockerfile.dev index 2c5519117..dba22b223 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -1,24 +1,23 @@ -FROM python:3 - -WORKDIR /app/ +FROM python:3.9-buster ENV PRODUCTION false +ENV POETRY_VERSION 1.1.6 -RUN apt-get update -y && \ - apt-get install -y python-pip python-dev +# poetry +RUN pip install --no-cache-dir "poetry==$POETRY_VERSION" -# Install Poetry -RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | POETRY_HOME=/opt/poetry python && \ - cd /usr/local/bin && \ - ln -s /opt/poetry/bin/poetry && \ - poetry config virtualenvs.create false +# database drivers +RUN pip install --no-cache-dir "psycopg2-binary==2.8.6" -# Copy poetry.lock* in case it doesn't exist in the repo -COPY ./pyproject.toml /app/ +# project dependencies +WORKDIR /app +COPY pyproject.toml poetry.lock /app/ +RUN poetry config virtualenvs.create false +RUN poetry install --no-root --no-dev --no-interaction --no-ansi +# project code COPY ./mealie /app/mealie +COPY ./alembic /app/alembic +COPY alembic.ini /app -RUN poetry install - -RUN chmod +x /app/mealie/run.sh -CMD ["/app/mealie/run.sh", "reload"] +CMD [ "/app/mealie/run.sh", "development" ] diff --git a/alembic/versions/89e8733c36f2_initial_revision.py b/alembic/versions/89e8733c36f2_initial_revision.py index f447a3b97..f9a8e3da4 100644 --- a/alembic/versions/89e8733c36f2_initial_revision.py +++ b/alembic/versions/89e8733c36f2_initial_revision.py @@ -240,29 +240,32 @@ def upgrade(): op.bulk_insert(site_settings2categories_table, [ { "sidebar_id": 1, - "category_slug", "thanksgiving", + "category_slug": "thanksgiving", }, { "sidebar_id": 1, - "category_slug", "homechef", + "category_slug": "homechef", }, { "sidebar_id": 1, - "category_slug", "potatoes", + "category_slug": "potatoes", + }, + ]) + op.bulk_insert(theme_colors_table, [ + { + "parent_id": "default", + "primary": "#E58325", + "accent": "#00457A", + "secondary": "#973542", + "success": "#5AB1BB", + "info": "#4990BA", + "warning": "#FF4081", + "error": "#EF5350", }, ]) op.bulk_insert(site_theme_table, [ { "name": "default", - "colors": { - "primary": "#E58325", - "accent": "#00457A", - "secondary": "#973542", - "success": "#5AB1BB", - "info": "#4990BA", - "warning": "#FF4081", - "error": "#EF5350", - }, }, ]) op.bulk_insert(groups_table, [ diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 927e17364..a4567eec6 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -27,7 +27,6 @@ services: - 9921:9000 environment: TZ: America/Anchorage # Specify Correct Timezone for Date/Time to line up correctly. - DB_URL: sqlite:///mealie.db volumes: - ./dev/data:/app/dev/data - ./mealie:/app/mealie diff --git a/docker-compose.yml b/docker-compose.yml index fbf963220..acdd80c85 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,5 +8,3 @@ services: restart: always ports: - 9090:80 - environment: - DB_URL: sqlite:///mealie.db diff --git a/mealie/run.sh b/mealie/run.sh index 8291f9efd..647400b44 100755 --- a/mealie/run.sh +++ b/mealie/run.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # Get Reload Arg `run.sh reload` for dev server ARG1=${1:-production} @@ -10,17 +10,15 @@ ARG1=${1:-production} poetry run alembic upgrade head poetry run python /app/mealie/services/image/minify.py -# Migrations # TODO - # Migrations - # Set Port from ENV Variable +# Set Port from ENV Variable -if [[ "$ARG1" = "reload" ]] +if [[ "$ARG1" = "development" ]] then - echo "Hot Reload!" + echo "Development" # Start API - uvicorn mealie.app:app --host 0.0.0.0 --port 9000 --reload + uvicorn mealie.app:app --host 0.0.0.0 --port 9000 else echo "Production" # Web Server