diff --git a/README.md b/README.md index 329068e..60645dd 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,11 @@ For a new deployment of this tool follow the instructions to start a new project For local development; follow these steps: 1. Configure and run the scripts in the `/pipelines` 2. Use VScode to open dev containers for both the `/app` as the `/hail` folders + 2.1 To open the /app devcontainer: + - Navigate to 'File' in VSCode + - Open Folder + - Open the app folder + - This will prompt 'Reopen in devcontainer?', click yes. If this is not automatically promted you can CTRL + Shift + P and select 'Dev Container: Reopen in Dev Container. 3. In the `/app` dev container, start the client and backend with 2 terminals: 1. `cd frontend && npm run dev` 2. `cd src && python manage.py runserver` diff --git a/app/.devcontainer/Dockerfile b/app/.devcontainer/Dockerfile index 5df7479..cd60ffb 100644 --- a/app/.devcontainer/Dockerfile +++ b/app/.devcontainer/Dockerfile @@ -22,9 +22,9 @@ ARG NODE_VERSION="none" RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi # [Optional] If your requirements rarely change, uncomment this section to add them to the image. -COPY ./src/requirements/local.txt /tmp/pip-tmp/ -COPY ./src/requirements/test.txt /tmp/pip-tmp/ -COPY ./src/requirements/base.txt /tmp/pip-tmp/ +COPY ./app/src/requirements/local.txt /tmp/pip-tmp/ +COPY ./app/src/requirements/test.txt /tmp/pip-tmp/ +COPY ./app/src/requirements/base.txt /tmp/pip-tmp/ RUN pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/local.txt \ && rm -rf /tmp/pip-tmp @@ -32,13 +32,18 @@ RUN pip install --upgrade pip \ && pip install ipython ipdb # [Optional] Uncomment this section to install additional OS packages. -RUN rm -f /etc/apt/sources.list.d/yarn.list \ - && apt-get update && export DEBIAN_FRONTEND=noninteractive \ - && apt-get -y install --no-install-recommends \ - && apt-get install -y netcat gcc libpq-dev \ - && apt-get install -y binutils libproj-dev gdal-bin \ - && apt-get install -y vim curl gettext \ - && apt-get install -y libmagickwand-dev \ - && rm -rf /var/lib/apt/lists/* +RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ + && apt-get install -y --no-install-recommends \ + netcat-openbsd gcc libpq-dev \ + binutils libproj-dev gdal-bin \ + vim curl gettext \ + libmagickwand-dev \ + sudo \ + +# Give vscode user sudo access +RUN echo "vscode ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers + +# Pre-create XDG runtime dir so VS Code server can use it as non-root user +RUN mkdir -p /home/vscode/xdg-runtime && chown vscode:vscode /home/vscode/xdg-runtime && chmod 700 /home/vscode/xdg-runtime EXPOSE 8000 \ No newline at end of file diff --git a/app/.devcontainer/devcontainer-lock.json b/app/.devcontainer/devcontainer-lock.json new file mode 100644 index 0000000..b076343 --- /dev/null +++ b/app/.devcontainer/devcontainer-lock.json @@ -0,0 +1,9 @@ +{ + "features": { + "ghcr.io/devcontainers/features/git:1": { + "version": "1.3.5", + "resolved": "ghcr.io/devcontainers/features/git@sha256:27905dc196c01f77d6ba8709cb82eeaf330b3b108772e2f02d1cd0d826de1251", + "integrity": "sha256:27905dc196c01f77d6ba8709cb82eeaf330b3b108772e2f02d1cd0d826de1251" + } + } +} diff --git a/app/.devcontainer/devcontainer.json b/app/.devcontainer/devcontainer.json index 2f69ebf..6c701d0 100644 --- a/app/.devcontainer/devcontainer.json +++ b/app/.devcontainer/devcontainer.json @@ -27,13 +27,30 @@ 6379, 3000 ], - "remoteUser": "root", + "mounts": [ + "source=${localEnv:HOME}/.gitconfig,target=/home/vscode/.gitconfig,type=bind,consistency=cached,readonly" + ], + "features": { + "ghcr.io/devcontainers/features/git:1": {} + }, + "remoteUser": "vscode", + "remoteEnv": { + "XDG_RUNTIME_DIR": "/home/vscode/xdg-runtime" + }, "postCreateCommand": [ "bash", "./.devcontainer/docker-entrypoint.sh" ], + "postStartCommand": "sudo chown -R vscode:vscode /workspace && git config --global --add safe.directory /workspace && git config --global --add safe.directory '*'", "settings": { "python.pythonPath": "/usr/local/bin/python", "python.formatting.provider": "black" + }, + "customizations": { + "vscode": { + "settings": { + "git.openRepositoryInParentFolders": "always" + } + } } } \ No newline at end of file diff --git a/app/.devcontainer/docker-compose.yml b/app/.devcontainer/docker-compose.yml index f05a720..77d79bf 100644 --- a/app/.devcontainer/docker-compose.yml +++ b/app/.devcontainer/docker-compose.yml @@ -3,8 +3,8 @@ version: "3.8" services: app: build: - context: .. - dockerfile: .devcontainer/Dockerfile + context: ../.. + dockerfile: app/.devcontainer/Dockerfile args: NEXT_PUBLIC_WAGTAIL_API_URL: http://localhost:8000/wt/api/nextjs # Update 'VARIANT' to pick a version of Python: 3, 3.10, 3.9, 3.8, 3.7, 3.6 @@ -17,13 +17,14 @@ services: depends_on: - db volumes: - - ..:/workspace:cached + - ../..:/workspace:cached + - /var/run/docker.sock:/var/run/docker.sock # Overrides default command so things don't shut down after the process ends. command: sleep infinity # Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function. network_mode: service:db - # Uncomment the next line to use a non-root user for all processes. - # user: vscode + # Use non-root user for all processes to avoid git permission issues + user: vscode # Use "forwardPorts" in **devcontainer.json** to forward an app port locally. # (Adding the "ports" property to this file will not forward from a Codespace.) diff --git a/app/.devcontainer/docker-entrypoint.sh b/app/.devcontainer/docker-entrypoint.sh index b53d3cb..5ed3594 100644 --- a/app/.devcontainer/docker-entrypoint.sh +++ b/app/.devcontainer/docker-entrypoint.sh @@ -4,6 +4,38 @@ # Credits: https://rock-it.pl/how-to-write-excellent-dockerfiles/ CMD=$1 +# Configure git for the container +configure_git() { + echo "Configuring git..." + + # Ensure vscode user owns the workspace + sudo chown -R vscode:vscode /workspace 2>/dev/null || true + + # Set git to treat the workspace as safe + git config --global --add safe.directory /workspace + git config --global --add safe.directory '*' + + # Set basic git configuration if not already set + if [ -z "$(git config --global user.name 2>/dev/null)" ]; then + git config --global user.name "Dev User" + fi + + if [ -z "$(git config --global user.email 2>/dev/null)" ]; then + git config --global user.email "dev@example.com" + fi + + # Fix ownership and permissions of git directories + if [ -d "/workspace/.git" ]; then + sudo chown -R vscode:vscode /workspace/.git 2>/dev/null || true + chmod -R u+w /workspace/.git 2>/dev/null || true + fi + + # Set git file mode to false to avoid permission issues + git config --global core.filemode false + + echo "Git configuration complete" +} + wait_for_db () { if [ "$DATABASE" = "postgres" ] then @@ -19,7 +51,7 @@ wait_for_db () { setup_django () { - cd /workspace/src + cd /workspace/app/src echo Running migrations python manage.py migrate --noinput @@ -38,7 +70,7 @@ setup_django () { } load_fixture_data() { - cd /workspace/src + cd /workspace/app/src echo Install fixtures @@ -48,13 +80,14 @@ load_fixture_data() { } setup_frontend () { - cd /workspace/frontend + cd /workspace/app/frontend echo Install the Node dependencies npm install } wait_for_db +configure_git setup_django load_fixture_data setup_frontend diff --git a/app/README.md b/app/README.md index 062175a..3b52358 100644 --- a/app/README.md +++ b/app/README.md @@ -4,7 +4,12 @@ We work using LTAP. Local runs on dev containers (see below). All TAP environmen ## Start Dev Container -Visual Studio Code will detect that you are working in a Dev Container, click "Reopen in Container" to start the Dev container. Make sure there is an .env file for local development present in the `/frontend` folder, like this: + - Navigate to 'File' in VSCode + - Open Folder + - Open the app folder + - This will prompt 'Reopen in container?', click yes. If this is not automatically promted you can CTRL + Shift + P and select 'Dev Container: Reopen in Dev Container. + +Make sure there is an .env file for local development present in the `/frontend` folder, like this: ``` WAGTAIL_API_URL=http://localhost:8000/wt/api/nextjs