I am trying to Dockerize a Django app with tailwind to deploy to lightsail. I followed two tutorials.
Both work individually. Now I am trying to combine the both. I started with the django-tailwind guide, then added the code from the first tutorial to it.
When I run docker-compose build it builds (19/28) of the commands, I assume. When I run docker-compose up I get the error
gmo-django-lightsail-tailwind-1 | CommandError:
gmo-django-lightsail-tailwind-1 | It looks like node.js and/or npm is not installed or cannot be found.
gmo-django-lightsail-tailwind-1 |
gmo-django-lightsail-tailwind-1 | Visit https://nodejs.org to download and install node.js for your system.
gmo-django-lightsail-tailwind-1 |
gmo-django-lightsail-tailwind-1 | If you have npm installed and still getting this error message, set NPM_BIN_PATH variable in settings.py to match path of NPM executable in your system.
gmo-django-lightsail-tailwind-1 |
gmo-django-lightsail-tailwind-1 | Example:
gmo-django-lightsail-tailwind-1 | NPM_BIN_PATH = "/usr/local/bin/npm
In my settings.py I have “NPM_BIN_PATH = r"C:\Program Files\nodejs\npm.cmd” included.
Here is my dockerfile:
FROM python:3.11.1-alpine3.17
ENV PYTHONUNBUFFERED 1
COPY ./requirements.txt /requirements.txt
RUN apk add --update --no-cache \
postgresql-client \
build-base \
postgresql-dev \
musl-dev \
zlib \
zlib-dev \
linux-headers
WORKDIR /gmo
RUN apk add --no-cache \
musl-dev \
curl \
nodejs
RUN python -m venv /py && \
/py/bin/pip install --upgrade pip && \
/py/bin/pip install -r /requirements.txt
COPY ./scripts /scripts
RUN chmod -R +x /scripts
ENV PATH="/scripts:/py/bin:$PATH"
COPY ./gmo /gmo
WORKDIR /gmo
EXPOSE 80
CMD ["/scripts/run.sh"]
Here is my docker-compose file:
version: "3.8"
services:
gmo:
build:
context: .
volumes:
- ./gmo:/gmo
ports:
- 8000:8000
command: sh -c "python manage.py migrate && python manage.py runserver 0.0.0.0:8000"
environment:
DEBUG: 1
DB_HOST: database
DB_NAME: django-dev-db
DB_USER: devuser
DB_PASS: devpassword123
depends_on:
database:
condition: service_healthy
tailwind:
build:
context: .
volumes:
- ./gmo:/gmo
command: python manage.py tailwind start
restart: unless-stopped
tty: true
database:
image: postgres:12-alpine
volumes:
- dev-db-data:/var/lib/postgresql/data
environment:
POSTGRES_DB: django-dev-db
POSTGRES_USER: devuser
POSTGRES_PASSWORD: devpassword123
healthcheck:
test: ["CMD", "pg_isready", "-q", "-d", "django-dev-db", "-U", "devuser"]
interval: 5s
timeout: 5s
retries: 10
volumes:
dev-db-data:
And here is my script file:
#!/bin/sh
set -e
SECRET_KEY=nothing python manage.py tailwind install --no-input
SECRET_KEY=nothing python manage.py tailwind build --no-input
SECRET_KEY=nothing python manage.py collectstatic --no-input
python manage.py migrate
gunicorn -b :80 --chdir /gmo gmo.wsgi:application
Well, I’ve tried many things. Editing the docker-compose and Dockerfile (the latest modification is posted).
I want to be able to live update tailwind when I run docker-compose up. It sometimes works, but then doesn’t live update after. Normal HTML changes work, but tailwind specific changes doesn’t.
This is my first time posting here, so sorry if I placed it in the wrong forum.