0

I am trying to rebuild a past project regarding Django and gulp.js. Gulp is used to build the static assets from Django. I am now dockerizing this project. In order to do it, I am using a python and node combo image from this hub. I install the necessary packages both from Django and node. I copy the source code into the container. Run gulp and ./manage.py runserver. When I run gulp, I get an error that the local gulp cannot be found in the directory.

app  | [06:49:46] Local gulp not found in /usr/src/app
app  | [06:49:46] Try running: yarn add gulp

I have this directory tree. The src/ holds the source codes and I copy this to the container. It holds the gulpfile.js and manage.py.

.
└── project/
    ├── dockerfiles/
    │   └── app.Dockerfile
    ├── src/
    │   ├── apps/
    │   ├── entrypoints/
    │   │   └── entrypoint-local.sh
    │   ├── gulpfile.js
    │   ├── manage.py
    │   ├── package.json
    │   └── package-lock.json
    ├── .local.env
    └── docker-compose.yml

Here is my docker-compose file.

version: "3.9"

  app:
    container_name: app
    build:
      dockerfile: ./dockerfiles/app.Dockerfile
    entrypoint: ./entrypoints/entrypoint-local.sh
    volumes:
      - ./src:/usr/src/app
      - static:/static
    ports:
      - "8000:8000"
    env_file:
      - .local.env

Here is how I build the app container.

# syntax=docker/dockerfile:1
FROM nikolaik/python-nodejs:python3.7-nodejs19-bullseye

WORKDIR /usr/src/app

RUN apt-get update \
    && apt-get install -y binutils libproj-dev libgeos-dev gdal-bin libgeoip1 libgdal-dev gdal-bin \
    && apt-get install -y build-essential libssl-dev libffi-dev python3-dev python3-pip python3-venv \
    && rm -fr /var/lib/apt/lists

RUN pip install --upgrade pip
COPY /src/requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY /src/package*.json .
RUN npm install
RUN npm install -g gulp-cli
RUN npm install --save-dev gulp

COPY /src .

RUN chmod +x ./entrypoints --recursive

In my entrypoint, I first run gulp before ./manage.py runserver.

#!/bin/sh

python manage.py migrate --no-input
gulp
python manage.py runserver

The gulp command triggers the error from the above. I have tried placing a list directory in the entrypoint to check if gulpfile.js is present and can confirm it is present. I also tried to remove the gulp command and run ./manage.py runserver and the Django runs. Why am I getting that error and how to fix it?

Nikko
  • 1,410
  • 1
  • 22
  • 49
  • Does this answer help: https://stackoverflow.com/questions/41028272/docker-compose-w-gulp-local-gulp-not-found ? – ruddra Apr 17 '23 at 08:44

1 Answers1

1

You're creating a directory /usr/src/app inside the container (WORKDIR /usr/src/app) where you install the Node.js requirements.

Then you overwrite that directory with a volume mapping:

    volumes:
      - ./src:/usr/src/app

This will replace the directory /usr/src/app inside the container (where you just installed all the requirements) with the contents of ./src.

robertklep
  • 198,204
  • 35
  • 394
  • 381
  • So should I remove it? How can I persist the source code? – Nikko Apr 17 '23 at 07:46
  • The manage.py does not produce error though. – Nikko Apr 17 '23 at 07:59
  • AFAIK, `pip` installs requirements in a global directory, not a local one, which is why `manage.py` is working. Since you're already copying files into the container (`COPY`), you don't need to use a volume mapping. – robertklep Apr 17 '23 at 08:01
  • But I need to persist the `/src` directory to that in the container, since I am going to develop some new features. Should I just also persist the `node_modules` when install packages from node? – Nikko Apr 17 '23 at 08:07
  • 1
    In that case you need to have all the required Node.js files outside of the container, including `node_modules` (you can then drop all the Node.js-related `COPY` commands). – robertklep Apr 17 '23 at 08:11