Hi Folks,
I’ve been a big fan of FastAPI for years. I find it to be a really solidly built Python framework, using modern standards and practices.
I’ve recently discovered another project by Tiangolo called full-stack-fastapi-template which has an amazing drop-in template combining backend, frontend, reverse proxy, database.
I want to use it on a fleet in Balena, running on some Pi Compute devices. I’m trying to wrap my head around converting this already dockerized template and set of services into Balena’s environment. Might also make for good Balena Blocks in the future.
Can anyone give me any advice on how to integrate this? What should I be on the lookout for? Can I realistically port this over? I imagine the first step will be to find suitable images to use for each of the services?
Thanks!
Phil
1 Like
mpous
April 29, 2024, 11:33am
2
Hello @philletourneau this looks like a great project!
Did you try to deploy the FastAPI project on balena? I just found some documentation here FastAPI in Containers - Docker - FastAPI
Let us know what are your next steps if we can help you with anything specific!
I’ve been using FastAPI quite a bit on Balena, but I’ve not yet setup this larger “full-stack” project successfully.
In fact, just today, I’ve started getting this error when trying to deploy:
/ Packaging the project source...[Warn]
[Warn] -------------------------------------------------------------------------
[Warn] The following .dockerignore file(s) will not be used:
[Warn] * /Users/phil/Sources/Motusphera/motusphera-server/frontend/.dockerignore
[Warn] * /Users/phil/Sources/Motusphera/motusphera-server/backend/.dockerignore
[Warn] By default, only one .dockerignore file at the source folder (project
[Warn] root) is used. Microservices (multicontainer) fleets may use a separate
[Warn] .dockerignore file for each service with the --multi-dockerignore (-m)
[Warn] option. See "balena help push" for more details.
[Warn] -------------------------------------------------------------------------
[Info] Starting build for motusphera_server, user gh_philletourneau
[Info] Dashboard link: https://dashboard.balena-cloud.com/apps/2128394/devices
[Info] Building on 4b2d7d0
[backend] Step 1/12 : FROM tiangolo/uvicorn-gunicorn-fastapi:python3.10
[frontend] Step 1/11 : FROM node:20 as build-stage
[backend] ---> 2a046c02fc91
[backend] Step 2/12 : WORKDIR /app/
[backend] Using cache
[backend] ---> 071ba6e242c5
[backend] Step 3/12 : RUN curl -sSL https://install.python-poetry.org | POETRY_HOME=/opt/poetry python && cd /usr/local/bin && ln -s /opt/poetry/bin/poetry && poetry config virtualenvs.create false
[frontend] ---> e00552d055cc
[frontend] Step 2/11 : WORKDIR /app
[frontend] Using cache
[frontend] ---> 7edd930ff5d7
[frontend] Step 3/11 : COPY package*.json /app/
[backend] Using cache
[backend] ---> 39bb9941063a
[backend] Step 4/12 : COPY ./pyproject.toml ./poetry.lock* /app/
[backend] Using cache
[backend] ---> 1b1ce59e518e
[backend] Step 5/12 : ARG INSTALL_DEV=false
[backend] Using cache
[backend] ---> 1f8134a3304e
[backend] Step 6/12 : RUN bash -c "if [ $INSTALL_DEV == 'true' ] ; then poetry install --no-root ; else poetry install --no-root --only main ; fi"
[frontend] Using cache
[frontend] ---> 09edb00d953a
[frontend] Step 4/11 : RUN npm install
[frontend] Using cache
[frontend] ---> d80a8fd18e3a
[frontend] Step 5/11 : COPY ./ /app/
[frontend] Using cache
[frontend] ---> 123285b388c9
[frontend] Step 6/11 : ARG VITE_API_URL=${VITE_API_URL}
[frontend] Using cache
[frontend] ---> 91365b9760af
[frontend] Step 7/11 : RUN npm run build
[frontend] ---> Running in 97832ed4c1b7
[backend] ---> Running in 37b6f824ee69
[frontend] > frontend@0.0.0 build
[frontend] > tsc && vite build
[backend] Skipping virtualenv creation, as specified in config file.
[backend]
[backend] Installing dependencies from lock file
[backend] Package operations: 33 installs, 10 updates,
[backend] 0 removals
[backend] - Downgrading exceptiongroup (1.2.1 -> 1.2.0)
[backend] - Downgrading idna (3.7 -> 3.6)
[backend] - Downgrading typing-extensions (4.11.0 -> 4.10.0)
[backend] - Installing annotated-types (0.6.0)
[backend] - Installing charset-normalizer (3.3.2)
[backend] - Installing pycparser (2.21)
[backend] - Installing pydantic-core (2.16.3)
[backend] - Installing urllib3 (2.2.1)
[backend] - Installing cachetools (5.3.3)
[backend] - Installing cffi (1.16.0)
[backend] - Installing cssselect (1.2.0)
[backend] - Installing cssutils (2.9.0)
[backend] - Installing greenlet (3.0.3)
[backend] - Installing lxml (5.1.0)
[backend] - Installing pyasn1 (0.5.1)
[backend] - Updating pydantic (1.10.15 -> 2.6.4)
[backend] - Installing requests (2.31.0)
[backend] - Installing six (1.16.0)
[backend] - Updating starlette (0.22.0 -> 0.36.3)
[backend] - Installing bcrypt (4.0.1)
[backend] - Installing chardet (5.2.0)
[backend] - Installing cryptography (42.0.5)
[backend] - Installing ecdsa (0.18.0)
[backend] - Updating fastapi (0.88.0 -> 0.109.2)
[backend] - Downgrading httpcore (1.0.5 -> 1.0.4)
[backend] - Installing mako (1.3.2)
[backend] - Installing premailer (3.10.0)
[backend] - Installing psycopg-binary (3.1.18)
[backend] - Installing python-dateutil (2.9.0.post0)
[backend] - Installing rsa (4.9)
[backend] - Installing sqlalchemy (2.0.28)
[backend] - Installing alembic (1.13.1)
[backend] - Installing emails (0.6)
[backend] - Downgrading httpx (0.27.0 -> 0.25.2)
[backend] - Installing passlib (1.7.4)
[backend] - Installing psycopg (3.1.18)
[backend] - Installing pydantic-settings (2.2.1)
[backend] - Installing python-jose (3.3.0)
[backend] - Downgrading python-multipart (0.0.9 -> 0.0.7)
[backend] - Installing sentry-sdk (1.41.0)
[backend] - Installing sqlmodel (0.0.16)
[backend] - Installing tenacity (8.2.3)
[backend] - Updating uvicorn (0.20.0 -> 0.24.0.post1)
[frontend] ♻️ Generating routes...
[frontend] ✅ Processed routes in 255ms
[frontend] vite v5.0.13 building for production...
[frontend] transforming...
[backend] Removing intermediate container 37b6f824ee69
[backend] ---> 4d57a5c55bea
[backend] Step 7/12 : ENV PYTHONPATH=/app
[backend] ---> Running in 4e74010af360
[backend] Removing intermediate container 4e74010af360
[backend] ---> 11ac6a96e468
[backend] Step 8/12 : COPY ./scripts/ /app/
[frontend] ✓ 1243 modules transformed.
[frontend] rendering chunks...
[frontend] computing gzip size...
[frontend] dist/index.html 0.48 kB │ gzip: 0.31 kB
[frontend] dist/assets/favicon-U8UPlNDV.png 5.04 kB
[frontend] dist/assets/fastapi-logo-kunS4aGY.svg 6.31 kB │ gzip: 2.53 kB
[frontend] dist/assets/index-ZLLAeUCN.js 704.38 kB │ gzip: 230.74 kB
[frontend]
[frontend] (!) Some chunks are larger than 500 kB after minification. Consider:
[frontend] - Using dynamic import() to code-split the application
[frontend] - Use build.rollupOptions.output.manualChunks to improve chunking: https://rollupjs.org/configuration-options/#output-manualchunks
[frontend] - Adjust chunk size limit for this warning via build.chunkSizeWarningLimit.
[frontend]
[frontend] ✓ built in 6.44s
[backend] ---> 7c9405663442
[backend] Step 9/12 : COPY ./alembic.ini /app/
[backend] ---> 57d4726610aa
[backend] Step 10/12 : COPY ./prestart.sh /app/
[backend] ---> a350dde4c126
[backend] Step 11/12 : COPY ./tests-start.sh /app/
[frontend] Removing intermediate container 97832ed4c1b7
[frontend] ---> febcc62ddfd2
[frontend] Step 8/11 : FROM nginx:1
[backend] ---> 11344ac4d8e7
[backend] Step 12/12 : COPY ./app /app/app
[backend] ---> f28ad5e2e024
[backend] Successfully built f28ad5e2e024
[backend] Successfully tagged backend:latest
[frontend] ---> 786a14303c96
[frontend] Step 9/11 : COPY --from=build-stage /app/dist/ /usr/share/nginx/html
[frontend] ---> 7ebf737e5fc9
[frontend] Step 10/11 : COPY ./nginx.conf /etc/nginx/conf.d/default.conf
[frontend] ---> feff67af3100
[frontend] Step 11/11 : COPY ./nginx-backend-not-found.conf /etc/nginx/extra-conf.d/backend-not-found.conf
[frontend] ---> 304d9e8ff587
[frontend] [Warning] One or more build-args [NODE_ENV] were not consumed
[frontend] Successfully built 304d9e8ff587
[frontend] Successfully tagged frontend:latest
[traefik] [> ] 0%
[db] [> ] 0%
[Info] Generating image deltas from release 58704581b9cdba65395cccc4474c0404 (id: 2988964)
[Warning] Failed to generate deltas due to an internal error; will be generated on-demand
[Info] Uploading images
[Success] Successfully uploaded images
[Error] Upstream API server/DB error: "value" is not a string: 1
[Info] Built on 4b2d7d0
[Error] Not deploying release.
Remote build failed
type or paste code here
mpous
April 29, 2024, 6:58pm
4
Do you think you could share the Dockerfile so i can test @philletourneau ?
Thanks