Skip to content

Commit

Permalink
install django-tailwind
Browse files Browse the repository at this point in the history
  • Loading branch information
qtrinh2 committed Jun 3, 2024
1 parent a5ad254 commit 0caa40a
Show file tree
Hide file tree
Showing 16 changed files with 1,870 additions and 23 deletions.
44 changes: 38 additions & 6 deletions django/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
FROM rust as volta-build
WORKDIR /src
RUN git clone https://github.com/volta-cli/volta.git /src
RUN cargo build
RUN ls /src/target/debug

# Pull base image for Python 3.11
FROM python:3.11

Expand All @@ -6,20 +12,46 @@ ENV PIP_DISABLE_PIP_VERSION_CHECK 1
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# install poetry
RUN curl -sSL https://install.python-poetry.org | python3 -

# add path to poetry binary
ENV PATH="$PATH:/root/.local/bin"

# Set working directory
WORKDIR /app

# Copy project
COPY . .

# install poetry
RUN curl -sSL https://install.python-poetry.org | python3 -

# add path to poetry binary
ENV PATH="$PATH:/root/.local/bin"

# Install dependencies with Poetry
RUN poetry config virtualenvs.create false
RUN poetry install --no-interaction --no-ansi
#RUN poetry install --no-root #--no-dev

# Copy over Volta binaries
RUN mkdir -p /root/.volta/bin
COPY --from=volta-build /src/target/debug/volta /root/.volta/bin
COPY --from=volta-build /src/target/debug/volta-migrate /root/.volta/bin
COPY --from=volta-build /src/target/debug/volta-shim /root/.volta/bin

# shell stuff for volta
SHELL ["/bin/bash", "-c"]
ENV BASH_ENV ~/.bashrc
ENV VOLTA_HOME /root/.volta
ENV PATH $VOLTA_HOME/bin:$PATH
RUN ln -s /root/.volta/bin/volta-shim /root/.volta/bin/node
RUN ln -s /root/.volta/bin/volta-shim /root/.volta/bin/npm
RUN ln -s /root/.volta/bin/volta-shim /root/.volta/bin/npx
RUN ln -s /root/.volta/bin/volta-shim /root/.volta/bin/pnpm
RUN ln -s /root/.volta/bin/volta-shim /root/.volta/bin/yarn

# triggers node installation
RUN node -v && npm -v
RUN npm install

RUN poetry run python manage.py tailwind install
RUN poetry run python manage.py tailwind build
RUN poetry run python manage.py collectstatic --no-input

CMD poetry run python manage.py runserver 0.0.0.0:8000
22 changes: 13 additions & 9 deletions django/django_test/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-a0#%+c2cl-n5-#08$7znl4hmqbhfa&igm4!xtryhv_7ms=10ev'
SECRET_KEY = env("DJANGO_SECRET_KEY", default="notasecretkey")

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = env("DEBUG")
DEBUG = env("DEBUG", default="False")

ALLOWED_HOSTS = env.list("DJANGO_ALLOWED_HOSTS")
CSRF_TRUSTED_ORIGINS = env.list("DJANGO_CSRF_TRUSTED_ORIGINS")
ALLOWED_HOSTS = env.list("DJANGO_ALLOWED_HOSTS", default=['localhost'])
CSRF_TRUSTED_ORIGINS = env.list("DJANGO_CSRF_TRUSTED_ORIGINS", default=['https://localhost:8000'])


# Application definition
Expand All @@ -43,6 +43,8 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'tailwind',
'theme',
]

MIDDLEWARE = [
Expand Down Expand Up @@ -82,11 +84,11 @@
DATABASES = {
'default': {
"ENGINE": "django.db.backends.postgresql",
"HOST": env("DB_HOST"),
"PORT": env("DB_PORT"),
"NAME": env("DB_NAME"),
"USER": env("DB_USER"),
"PASSWORD": env("DB_PASS"),
"HOST": env("DB_HOST", default="db"),
"PORT": env("DB_PORT", default="5432"),
"NAME": env("DB_NAME", default="lasfera"),
"USER": env("DB_USER", default="lasfera"),
"PASSWORD": env("DB_PASS", default="notapassword"),
}
}

Expand Down Expand Up @@ -132,3 +134,5 @@
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

TAILWIND_APP_NAME = "theme"
2 changes: 1 addition & 1 deletion django/django_test/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
from django.http import HttpResponse

def home(request):
return HttpResponse("Hello world! deadbeef")
return HttpResponse("Hello world! fizzbuzz")
24 changes: 18 additions & 6 deletions django/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,36 @@ services:
build: .
image: rrchnm/cicd-testing-django
container_name: cicd-testing-django--app
env_file: .env
environment:
- DEBUG=True
- DJANGO_SECRET_KEY=thisisnotasecretkey
- DJANGO_ALLOWED_HOSTS=localhost
- DJANGO_CSRF_TRUSTED_ORIGINS=http://localhost
- DB_HOST=db
- DB_PORT=5432
- DB_NAME=db_dj
- DB_USER=user_dj
- DB_PASS=password
ports:
- "1337:8000"
command: >
sh -c "poetry run python manage.py migrate &&
poetry run python manage.py collectstatic --no-input &&
poetry run python manage.py runserver 0.0.0.0:8000"
#volumes:
#- .:/app
depends_on:
db:
condition: service_healthy
db:
image: postgres:12
image: postgres:16
container_name: cicd-testing-django--db
env_file: .env
environment:
- POSTGRES_HOST=db
- POSTGRES_DB=db_dj
- POSTGRES_USER=user_dj
- POSTGRES_PASSWORD=password
volumes:
- postgres_data:/var/lib/postgresql/data/
- pg_data:/var/lib/postgresql/data/
#ports:
#- "5432:5432"
healthcheck:
Expand All @@ -30,4 +42,4 @@ services:
retries: 3

volumes:
postgres_data:
pg_data:
1 change: 0 additions & 1 deletion django/docker-compose.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ services:
- "{{ template.env.host_app_port }}:8000"
command: >
sh -c "poetry run python manage.py migrate &&
poetry run python manage.py collectstatic --no-input &&
poetry run python manage.py runserver 0.0.0.0:8000"
depends_on:
db:
Expand Down
8 changes: 8 additions & 0 deletions django/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "cicd-testing",
"version": "0.1.0",
"volta": {
"node": "18.15.0",
"npm": "9.6.3"
}
}
135 changes: 135 additions & 0 deletions django/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions django/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ django = "^4.2.5"
python-dotenv = "^1.0.0"
django-environ = "^0.11.2"
psycopg2 = "^2.9.7"
django-tailwind = "^3.8.0"


[build-system]
Expand Down
5 changes: 5 additions & 0 deletions django/theme/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class ThemeConfig(AppConfig):
name = 'theme'
1 change: 1 addition & 0 deletions django/theme/static_src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
Loading

0 comments on commit 0caa40a

Please sign in to comment.