Skip to content

Commit

Permalink
feat(deployment): Add Docker and Fly.io integration
Browse files Browse the repository at this point in the history
* Add a .dockerignore file to exclude unnecessary files and directories (like .git, __pycache__, .envrc, .venv, and fly.toml) from Docker builds, optimizing build context size and performance.
* Introduce a Dockerfile setting up a multi-stage build for the `pucoti` application using Python 3.12. This enhances container performance by separating dependencies installation and the runtime environment.
* Set up a GitHub Actions workflow `fly-deploy.yml` for continuous deployment to Fly.io. It triggers on pushes to the main branch and deploys the app using `flyctl`.
* Create a fly.toml file for configuring Fly.io deployments, including app settings such as region, HTTP service preferences, vm size, and processes.
  • Loading branch information
ddorn committed Sep 22, 2024
1 parent 76fbe12 commit 141320f
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fly.toml
.git/
__pycache__/
.envrc
.venv/
18 changes: 18 additions & 0 deletions .github/workflows/fly-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# See https://fly.io/docs/app-guides/continuous-deployment-with-github-actions/

name: Fly Deploy
on:
push:
branches:
- main
jobs:
deploy:
name: Deploy app
runs-on: ubuntu-latest
concurrency: deploy-group # optional: ensure only one action runs at a time
steps:
- uses: actions/checkout@v4
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: flyctl deploy --remote-only
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM python:3.12 AS builder

ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1
WORKDIR /app

RUN pip install poetry
RUN poetry config virtualenvs.in-project true
COPY pyproject.toml poetry.lock ./
RUN poetry install
FROM python:3.12-slim
WORKDIR /app
COPY --from=builder /app/.venv .venv/
COPY . .
CMD ["/app/.venv/bin/uvicorn", "pucoti.server:app", "--host", "0.0.0.0", "--port", "8000"]
21 changes: 21 additions & 0 deletions fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# fly.toml app configuration file generated for pucoti on 2024-09-21T19:52:26+02:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = 'pucoti'
primary_region = 'cdg'

[build]

[http_service]
internal_port = 8000
force_https = true
auto_stop_machines = 'stop'
auto_start_machines = true
min_machines_running = 0
max_machines_running = 1
processes = ['app']

[[vm]]
size = 'shared-cpu-1x'

0 comments on commit 141320f

Please sign in to comment.