Skip to content

Commit

Permalink
Deploy preparation
Browse files Browse the repository at this point in the history
  • Loading branch information
cris96spa committed Oct 21, 2024
1 parent 073b7bc commit ddfff99
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fly.toml
.git/
*.sqlite3
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 }}
38 changes: 21 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
FROM python:3.12.6
ARG PYTHON_VERSION=3.12-slim

WORKDIR /app
FROM python:${PYTHON_VERSION}

# Install system dependencies
RUN apt-get update && apt-get install curl -y \
build-essential \
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# install psycopg2 dependencies.
RUN apt-get update && apt-get install -y \
libpq-dev \
gcc \
&& rm -rf /var/lib/apt/lists/* \
&& pip install --upgrade pip setuptools wheel \
&& pip install uv

COPY ./pyproject.toml ./pyproject.toml
RUN mkdir -p /code

COPY ./home ./home
COPY ./portfolio ./portfolio
COPY ./staticfiles ./staticfiles
COPY ./static ./static
COPY ./templates ./templates
COPY ./db.sqlite3 ./db.sqlite3
COPY ./manage.py ./manage.py
WORKDIR /code

RUN pip install poetry
COPY ./pyproject.toml ./pyproject.toml
RUN uv pip compile pyproject.toml --extra dev -o requirements.txt --extra-index-url https://pypi.org/simple/ --no-cache
RUN pip install -r requirements.txt --extra-index-url https://pypi.org/simple/ --no-cache
RUN python manage.py migrate
COPY . /code

ENV SECRET_KEY "mMV6vgXTs9qs3flESOrCkA0WDwgO96rWtnoTKqiaRAJug9u5qU"
RUN python manage.py collectstatic --noinput
CMD ["python", "manage.py", "runserver"]
# Run the application using a WSGI server
# CMD ["gunicorn", "--bind", "0.0.0.0:8000", "portfolio.wsgi:application"]

EXPOSE 8000

CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "2", "--worker-class", "uvicorn.workers.UvicornWorker", "handlers.asgi"]
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: gunicorn portfolio.wsgi
33 changes: 33 additions & 0 deletions fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# fly.toml app configuration file generated for portfolio-shy-frost-4034 on 2024-10-21T22:51:31+02:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = 'portfolio-shy-frost-4034'
primary_region = 'cdg'
console_command = '/code/manage.py shell'

[build]

[deploy]
release_command = 'python manage.py migrate --noinput'

[env]
PORT = '8000'

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

[[vm]]
memory = '1gb'
cpu_kind = 'shared'
cpus = 1

[[statics]]
guest_path = '/code/static'
url_prefix = '/static/'
5 changes: 4 additions & 1 deletion portfolio/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
SECRET_KEY = os.getenv('SECRET_KEY') # Use a default for local development
DEBUG = os.getenv('DEBUG')

if os.getenv('FLY_APP_NAME'):
DEBUG = False

ALLOWED_HOSTS = [
'.herokuapp.com',
'*',
'.cris96spa.com',
'127.0.0.1',
'www.cris96spa.com',
Expand Down
6 changes: 2 additions & 4 deletions portfolio/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""

from django.contrib import admin
from django.urls import path, include
from home import views

urlpatterns = [
path('admin/', admin.site.urls),
path('', include('home.urls'))
]
urlpatterns = [path('admin/', admin.site.urls), path('', include('home.urls'))]

0 comments on commit ddfff99

Please sign in to comment.