Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
27 changes: 16 additions & 11 deletions app/.devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,28 @@ 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

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
9 changes: 9 additions & 0 deletions app/.devcontainer/devcontainer-lock.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
19 changes: 18 additions & 1 deletion app/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
}
11 changes: 6 additions & 5 deletions app/.devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.)
Expand Down
39 changes: 36 additions & 3 deletions app/.devcontainer/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,7 +51,7 @@ wait_for_db () {


setup_django () {
cd /workspace/src
cd /workspace/app/src

echo Running migrations
python manage.py migrate --noinput
Expand All @@ -38,7 +70,7 @@ setup_django () {
}

load_fixture_data() {
cd /workspace/src
cd /workspace/app/src

echo Install fixtures

Expand All @@ -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
Expand Down
7 changes: 6 additions & 1 deletion app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down