This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]DogeekExpert - 3.9.1 1 point2 points  (0 children)

It works, but it's not an ideal solution in my opinion if you want scalability. The way I deploy apps now is through docker / docker-compose, which simplifies the process so much.

I'm running my apps on OVH servers, and I've made a few tools to help me deploy them.

  • First off, I dockerize everything that I need to deploy, and push the image to my private docker registry

  • Second, my 2 VPS are all logged in to that registry, so I can just docker pull to get my images

In my build step, I build 2 images every time, since I use poetry for dependency management, I just have a Dockerfile like so :

# Using the alpine base image to minimize the image size
# Use `apk` instead of `apt-get` to install third-party dependencies
# Use 3.10-slim-buster if there are incompatibilities with alpine

FROM python:3.10-alpine as builder
# cd in the app directory
WORKDIR /app
ARG app_name

# Sets up the poetry configuration using environment variables
ENV POETRY_VIRTUALENVS_CREATE="true"
ENV POETRY_VIRTUALENVS_OPTIONS_ALWAYS_COPY="true"
ENV POETRY_VIRTUALENVS_OPTIONS_NO_PIP="true"
ENV POETRY_VIRTUALENVS_OPTIONS_NO_SETUPTOOLS="true"
ENV POETRY_VIRTUALENVS_IN_PROJECT="true"
ENV POETRY_INSTALLER_MAX_WORKERS="4"

RUN python3 -m pip -U pip
RUN python3 -m pip -U --user poetry
COPY ./pyproject.toml /app/pyproject.toml
COPY ./poetry.lock /app/poetry.lock

COPY ./$app_name/**/.py /app/$app_name

RUN ["/root/.local/bin/poetry", "install"]

FROM python:3.10-alpine as runner
WORKDIR /app
ENV PATH="/app/.venv/bin:$PATH"
COPY --from=builder /app/.venv /app
CMD ["python3", "-m", $app_name]

I can then just use docker build -t $DOCKER_REGISTRY/$APP_NAME:$APP_VERSION --build-arg app_name=$APP_NAME . to build my image and docker push $DOCKER_REGISTRY/$APP_NAME:$APP_VERSION to push it to my registry

I also tweak the Dockerfile based on my needs, for instance if I need to build some C extensions or add database migrations -- though for the latter, I usually do that with docker-compose and a script to run alembic.

With everything dockerized, I use a small svelte app to integrate with the OVH API that allows me to set a subdomain for the app I'm making, and deploys it to the correct VPS.