Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devcontainer for development environment #7763

Open
wants to merge 116 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
e81204c
add devcontainer configuration files
g-kartik Mar 23, 2024
9ba0511
add launch and debug configuration for cvat server
g-kartik Mar 23, 2024
0b3ec89
add task for running cvat opa server in background
g-kartik Mar 23, 2024
df67f04
modify vs code and cvat server settings for running dev container env…
g-kartik Mar 23, 2024
65b25ac
refactor
g-kartik Mar 23, 2024
01b718a
add named volume mount for node modules
g-kartik Mar 23, 2024
15e91cb
remove launch config for opa as task config is already present for th…
g-kartik Mar 23, 2024
e07795b
add sql tools extension for postgres
g-kartik Mar 24, 2024
580ff21
add devcontainer run configuration for server and ui
g-kartik Mar 24, 2024
438c782
add option to enable/disable git branch isolation of devcontainers
g-kartik Mar 24, 2024
69d9ca3
add distribution file for devcontainer
g-kartik Mar 24, 2024
6b24595
refactor
g-kartik Mar 24, 2024
cece5f1
add necessary comments
g-kartik Mar 24, 2024
7637020
fix bugs
g-kartik Mar 24, 2024
769082b
add named volume mount for collect static files generated by django
g-kartik Mar 24, 2024
d6d78fb
add container workspace directory to local git config safe directorie…
g-kartik Mar 24, 2024
bf8014a
When usig git_branch_isolation remove specfic service containers exce…
g-kartik Mar 24, 2024
b3594c9
make clear log messages
g-kartik Mar 24, 2024
aad0470
- remove docker compose project name as it adds to the complexity whi…
g-kartik Mar 24, 2024
6104a41
mark all directories as safe for git repositories to fix path issues …
g-kartik Mar 24, 2024
d3eea76
preserve orignal network when git branch isolation rebuild
g-kartik Mar 24, 2024
61666a5
fix bug
g-kartik Mar 24, 2024
4888aa5
refactor - fix indents
g-kartik Mar 25, 2024
d3d34e6
set default env vars for the cvat_server container
g-kartik Mar 25, 2024
3845969
- remove unused variables from devcontainer dockerfile
g-kartik Mar 29, 2024
6dd41de
Override existing mount location of data, keys and logs volume for cv…
g-kartik Mar 29, 2024
e57fec8
Merge branch 'opencv:develop' into devcontainer-for-development-envir…
g-kartik Mar 29, 2024
e74e2f4
apply line width linting
g-kartik Mar 29, 2024
8d034e8
Add option for user to add development specific pacakges to devcontai…
g-kartik Mar 29, 2024
09ff4ca
add devcontainer docker compose render file and .env to gitignore
g-kartik Mar 29, 2024
d172e72
- create group inside devcontainer with id same that of host user's g…
g-kartik Mar 29, 2024
d79311c
- separate devcontainer setting env vars from project env vars
g-kartik Mar 29, 2024
fe740b1
fix typo
g-kartik Mar 29, 2024
9f8d1a0
namespace the devcontainer files as local
g-kartik Mar 30, 2024
9730ada
refactor local dev container files for new directory location
g-kartik Mar 30, 2024
64f32f4
create dev container namespace for codespaces
g-kartik Mar 30, 2024
896def6
git untrack generated files by devcontainer scripts
g-kartik Mar 30, 2024
385bdc0
fix issues
g-kartik Mar 30, 2024
cc5f614
remove containers only when they have old volume mounted as per git i…
g-kartik Mar 30, 2024
f268834
move persist zsh history featrure to TODO section
g-kartik Mar 30, 2024
4943578
assign different names to local and codespace dev container configura…
g-kartik Mar 30, 2024
6c45e49
mention default values for env vars
g-kartik Mar 30, 2024
45465fa
update documentation for remote development environment
g-kartik Mar 30, 2024
dc8327c
Merge branch 'opencv:develop' into devcontainer-for-development-envir…
g-kartik Mar 30, 2024
9469ad9
Add test environment packages to devcontainer image
g-kartik Apr 1, 2024
3497ae2
Merge branch 'cvat-ai:develop' into devcontainer-for-development-envi…
g-kartik Apr 4, 2024
a6a7a09
Merge branch 'cvat-ai:develop' into devcontainer-for-development-envi…
g-kartik Apr 6, 2024
3f9a2fd
Update cvat_server init script
g-kartik Apr 6, 2024
7c10a7b
Add launch config for server unit tests
g-kartik Apr 7, 2024
317c91e
Pin the node version in devcontainer
g-kartik Apr 8, 2024
a4e1918
Restore the default base setting for OPA_HOST
g-kartik Apr 8, 2024
81ce62d
Switch back to release version for js-debug extension
g-kartik Apr 13, 2024
413e6d5
Remove depreciated version declaration in devcontainer docker compose…
g-kartik Apr 13, 2024
4419b17
Mirror common changes to codespace devcontainer
g-kartik Apr 13, 2024
5faaa0a
Update documentation
g-kartik Apr 13, 2024
270b6ea
Merge branch 'develop' into devcontainer-for-development-environment
g-kartik Apr 13, 2024
dc0c279
Update changelog
g-kartik Apr 13, 2024
e7cbf15
Add notifications queue listen for rq worker debug process
g-kartik Apr 13, 2024
50dba31
Enable run serverless deployments from the devcontainer
g-kartik Apr 14, 2024
8a60cff
Update documentation
g-kartik Apr 14, 2024
e6e0618
Update documentation for running tests
g-kartik Apr 14, 2024
381492c
Fix typo
g-kartik Apr 14, 2024
647e824
Update docs for using VS Code Insiders
g-kartik Apr 14, 2024
7780583
Lock devcontainer features and enable updates via dependabot
g-kartik Apr 14, 2024
220b6c3
Add OPA package to devcontainer
g-kartik Apr 15, 2024
7bc282a
Create postcreate command
g-kartik Apr 18, 2024
140a172
Add test virtual environment to PATH
g-kartik Apr 18, 2024
4edc7a0
Save container user data between rebuilds
g-kartik Apr 19, 2024
f5ca7ea
Use bash shell for task and debug
g-kartik Apr 19, 2024
e2e9263
Exclude .vscode-server directories from being persisted enable re-ins…
g-kartik Apr 19, 2024
091a5dc
Remove unnecessary bind volume mount for ssh keys
g-kartik Apr 19, 2024
414a5c1
Make same devcontainer for codespace
g-kartik Apr 19, 2024
aa4e9df
Update gitignore files
g-kartik Apr 20, 2024
3be8098
Bind mount host ssh into container
g-kartik Apr 20, 2024
1c59643
Update docs
g-kartik Apr 20, 2024
9e866dd
Fix typo in devcontainer Dockerfile
g-kartik Apr 20, 2024
650e52e
Enable test-venv to be discoverable by python select interpreter command
g-kartik Apr 20, 2024
cdbca2d
Update docs
g-kartik Apr 20, 2024
7f51952
Install node dependencies on postcreate
g-kartik Apr 20, 2024
e3f5fba
Update docs
g-kartik Apr 20, 2024
8155dde
Don't run yarn install on UI launch config
g-kartik Apr 20, 2024
fbfb688
Update docs
g-kartik Apr 20, 2024
1b019ff
Add docs regarding dependabot for devcontainer features
g-kartik Apr 20, 2024
18402e2
Fix typo in doc
g-kartik Apr 20, 2024
1b7c226
Add docs regarding opa and nuclio cli applications
g-kartik Apr 20, 2024
8820212
Always restart nuclio container
g-kartik Apr 20, 2024
795c593
Fix bug
g-kartik Apr 20, 2024
1e9f5be
Fix typos in docs
g-kartik Apr 20, 2024
6ddb950
Revert commit 8155dde79 and fix bug
g-kartik Apr 21, 2024
2845e0b
Fix dependabot config for devcontainer
g-kartik Apr 23, 2024
1073ed7
Make init script POSIX compliant
g-kartik Apr 24, 2024
6711c53
Refactor to remove obsolete poststart command
g-kartik Apr 24, 2024
bc7b06f
Fix non-POSIX regular expression
g-kartik Apr 24, 2024
09a29c8
Fix init script POSIX regex for macOS
g-kartik Apr 25, 2024
2fd7698
Fix shebang
g-kartik Apr 25, 2024
c7bfe22
Make changelog fragment instead of directly editing CHANGELOG.md file
g-kartik Apr 26, 2024
f96520f
Fix types in comments
g-kartik Apr 26, 2024
713cac6
Update doc to specify POSIX sh shell instead of bash
g-kartik Apr 26, 2024
5378de0
Use more precise regex pattern for extracting datumaro git commit hash
g-kartik Apr 27, 2024
1c90dfd
Use absolute paths for mkdir command in devcontainer Dockerfile
g-kartik Apr 27, 2024
edaf18a
Gracefully handle error if invalid value is provided for GIT_BRANCH_I…
g-kartik Apr 27, 2024
a1e32be
Fix grammatical mistakes in docs and improve the language
g-kartik Apr 27, 2024
36a4284
Make regex pattern more precise
g-kartik Apr 27, 2024
1cf6bd0
Apply doc suggestions from code review
g-kartik Apr 27, 2024
35bb646
Fix typos in doc
g-kartik Apr 27, 2024
40fed59
Make error handling explicit
g-kartik Apr 27, 2024
d1e62e0
Apply doc suggestions from code review
g-kartik Apr 27, 2024
67c2479
Fix typos in docs
g-kartik Apr 27, 2024
714c4ee
Untrack .env file
g-kartik Apr 28, 2024
4e64aef
Move chown command for the virtual environment from Dockerfile to pos…
g-kartik Apr 28, 2024
03083cf
Fix typo
g-kartik Apr 28, 2024
ffc93e7
Revert "Move chown command for the virtual environment from Dockerfil…
g-kartik Apr 28, 2024
319cc01
Update docs regarding slow chown operation
g-kartik Apr 28, 2024
cf93f95
Apply suggestions from code review
g-kartik Apr 28, 2024
ef27186
Merge branch 'develop' into devcontainer-for-development-environment
g-kartik May 1, 2024
b468d3d
Update site/content/en/docs/contributing/running-tests.md
g-kartik May 7, 2024
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
66 changes: 66 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Copyright (C) 2024 CVAT.ai Corporation
#
# SPDX-License-Identifier: MIT
FROM cvat/server:dev

ARG HOST_USER_UID
ARG HOST_USER_GID
ARG NUCLIO_VERSION
ARG OPA_VERSION

ENV DJANGO_CONFIGURATION="development"
ENV DJANGO_SETTINGS_MODULE cvat.settings.${DJANGO_CONFIGURATION}

USER root

# Save commit hash of datumaro git repository for using it while updating virtal environment in
# postcreate.sh script
RUN mkdir -p /cvat/metadata \
&& sed --quiet 's|^datumaro @ git+https://github.com/cvat-ai/datumaro.git@\([0-9a-f]\{40\}\)$|\1|p' \
/home/django/cvat/requirements/base.txt > /cvat/metadata/datumaro_commit.txt

# It is needed that the host user uid matches with the container user uid, else \
# permission error occur on the bind volume mounts
# So original django user is replaced by devcontainer with host uid value
RUN userdel -r django 2>/dev/null \
&& groupadd --gid ${HOST_USER_GID} devcontainer \
&& useradd --uid ${HOST_USER_UID} --gid ${HOST_USER_GID} \
--create-home --shell /bin/bash --comment "" "devcontainer"

RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get --no-install-recommends install -qy \
parallel=20210822+ds-2 \
wget=1.21.2-2ubuntu1

RUN curl --silent "https://api.github.com/repos/nuclio/nuclio/releases/tags/${NUCLIO_VERSION}" \
| sed --silent 's/"browser_download_url": "\(.*nuctl.*linux.*amd64\)"/\1/Ip' \
| wget --tries 3 --output-document /usr/local/bin/nuctl --quiet --input-file - \
&& chmod +x /usr/local/bin/nuctl

RUN curl --silent "https://api.github.com/repos/open-policy-agent/opa/releases/tags/v${OPA_VERSION}" \
| sed --silent 's/"browser_download_url": "\(.*opa.*linux.*amd64.*static\)"/\1/Ip' \
| wget --tries 3 --output-document /usr/local/bin/opa --quiet --input-file - \
&& chmod +x /usr/local/bin/opa

RUN /usr/bin/python3 -m venv /opt/venv-test
ENV PATH="/opt/venv-test/bin:${PATH}"

# This command shall the slow in linux docker host running old kernel as it shall do
# regular copy instead of metadata only copy for chown operation.
# Tracking this issue at https://github.com/docker/for-linux/issues/388#issuecomment-1108689413
RUN chown -R devcontainer /opt/venv /opt/venv-test
g-kartik marked this conversation as resolved.
Show resolved Hide resolved

# If the volume mounted directories does not exist then they shall be created
# automatically during and they shall be owned by the root user and shall be
# inaccessible by the container user. Therefore, create these directories as the
# container user during build
USER devcontainer
WORKDIR /home/devcontainer/workspaces

RUN mkdir -p /home/devcontainer/workspaces/data /home/devcontainer/workspaces/keys \
/home/devcontainer/workspaces/logs /home/devcontainer/workspaces/static \
/home/devcontainer/workspaces/node_modules /home/devcontainer/.cache/pip \
/home/devcontainer/.vscode-server-insiders /home/devcontainer/.vscode-server \
/home/devcontainer/.ssh
51 changes: 51 additions & 0 deletions .devcontainer/cvat_server_init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env bash

set -eu

echo_bold() {
bold=$(tput bold)
normal=$(tput sgr0)
text="${1}"
echo "${bold}${text}${normal}"
}

error_handler() {
local error_code=${?}
local error_command="${BASH_COMMAND}"
local error_line="${BASH_LINENO}"

echo_bold "ERROR: ${0}: Error occurred on line ${error_line}: ${error_command} (exit code: ${error_code})" >&2
exit 1
}

db_operations() {
# Wait for postgres and redis containers to be running and available
./wait-for-it.sh "${CVAT_POSTGRES_HOST}:${CVAT_POSTGRES_PORT:-5432}" -t 0
./wait-for-it.sh "${CVAT_REDIS_INMEM_HOST}:${CVAT_REDIS_INMEM_PORT}" -t 0
./wait-for-it.sh "${CVAT_REDIS_ONDISK_HOST}:${CVAT_REDIS_ONDISK_PORT}" -t 0

python manage.py migrate
while ! python manage.py migrate --check; do
echo_bold "Waiting for migrations to finish"
sleep 10
done
python manage.py createsuperuser --no-input >/dev/null 2>&1
echo_bold "INFO: Done database migrate and create superuser"
}

collect_static() {
python manage.py collectstatic --noinput
echo_bold "INFO: Done collect static files"
}

trap error_handler ERR
workspacefolder="$(dirname "$(dirname "$(realpath "$0")")")"
cd "${workspacefolder}"
source /opt/venv/bin/activate
echo_bold "INFO: Start operations"
export -f echo_bold && export -f db_operations && export -f collect_static
parallel --jobs 2 --ungroup --halt now,fail=1 ::: db_operations collect_static
echo_bold "INFO: Done operations"
echo_bold "INFO: Run django server to serve the OPA client"
python manage.py runserver 0.0.0.0:"${CVAT_PORT:-8080}"
exit 0
19 changes: 19 additions & 0 deletions .devcontainer/devcontainer-lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {
"version": "2.4.3",
"resolved": "ghcr.io/devcontainers/features/common-utils@sha256:e9e1d402031416ed5fc500f242c27ffa1043a27b5ba612e6596ea62503c8ae70",
"integrity": "sha256:e9e1d402031416ed5fc500f242c27ffa1043a27b5ba612e6596ea62503c8ae70"
},
"ghcr.io/devcontainers/features/docker-in-docker:2": {
"version": "2.10.2",
"resolved": "ghcr.io/devcontainers/features/docker-in-docker@sha256:23ae11a86089da5f0b98a6edd603f91831802b7f2d5ef1e104e1b94a3beb546c",
"integrity": "sha256:23ae11a86089da5f0b98a6edd603f91831802b7f2d5ef1e104e1b94a3beb546c"
},
"ghcr.io/devcontainers/features/node:1": {
"version": "1.4.1",
"resolved": "ghcr.io/devcontainers/features/node@sha256:6c4f444d8e3eb68594d60ec128bce76a80647edc2b9a94960ca377895855145f",
"integrity": "sha256:6c4f444d8e3eb68594d60ec128bce76a80647edc2b9a94960ca377895855145f"
}
}
}
70 changes: 70 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"name": "cvat-local",
"initializeCommand": "${localWorkspaceFolder}/.devcontainer/init.sh",
"postCreateCommand": "${containerWorkspaceFolder}/.devcontainer/postcreate.sh",
"dockerComposeFile": [
"${localWorkspaceFolder}/.devcontainer/docker-compose.rendered.yml"
],
"service": "cvat_server",
"overrideCommand": false,
"runServices": [
"cvat_db",
"cvat_opa",
"cvat_redis_inmem",
"cvat_redis_ondisk"
],
"workspaceFolder": "/home/devcontainer/workspaces",
"remoteUser": "devcontainer",
"containerUser": "devcontainer",
"remoteEnv": {"HOME": "/home/devcontainer", "USER": "devcontainer"},
"containerEnv": {"HOME": "/home/devcontainer", "USER": "devcontainer"},
"shutdownAction": "stopCompose",
"forwardPorts": [
8070
],
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {
"installZsh": true,
"configureZshAsDefaultShell": true,
"installOhMyZsh": true,
"installOhMyZshConfig": true,
"upgradePackages": true,
"username": "devcontainer",
"userUid": "automatic",
"userGid": "automatic"
},
"ghcr.io/devcontainers/features/node:1": {
"nodeGypDependencies": true,
"version": "16.20.2",
"nvmVersion": "latest"
},
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
},
"customizations": {
"vscode": {
"extensions": [
"ms-vscode.js-debug",
"ms-python.python",
"ms-python.debugpy",
"dbaeumer.vscode-eslint",
"stylelint.vscode-stylelint",
"esbenp.prettier-vscode",
"ymotongpoo.licenser",
"shardulm94.trailing-spaces",
"streetsidesoftware.code-spell-checker",
"mtxr.sqltools",
"mtxr.sqltools-driver-pg"
],
"settings": {
"python.defaultInterpreterPath": "/opt/venv/bin/python",
// Ideally venvPath should be an array, tracking this issue here
// https://github.com/microsoft/vscode-python/issues/1479
"python.venvPath": "/opt/venv-test/bin",
"terminal.integrated.automationProfile.linux": {
"path": "/bin/bash"
},
"terminal.integrated.defaultProfile.linux": "zsh (2)"
}
}
}
}
1 change: 1 addition & 0 deletions .devcontainer/dist.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GIT_BRANCH_ISOLATION=true
20 changes: 20 additions & 0 deletions .devcontainer/docker-compose.nuclio.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
services:
nuclio:
container_name: nuclio
image: quay.io/nuclio/dashboard:1.11.24-amd64
restart: always
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
http_proxy:
https_proxy:
no_proxy: ${no_proxy:-}
NUCLIO_CHECK_FUNCTION_CONTAINERS_HEALTHINESS: 'true'
NUCLIO_DASHBOARD_DEFAULT_FUNCTION_MOUNT_MODE: 'volume'
ports:
- '8070:8070'
logging:
driver: "json-file"
options:
max-size: 100m
max-file: "3"
86 changes: 86 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
services:
cvat_server:
image: cvat/server:devcontainer
build:
dockerfile: .devcontainer/Dockerfile
context: .
args:
- pull # To fetch upstream base image (cvat/server:dev) changes on container rebuild
- HOST_USER_UID=${HOST_USER_UID:-1001}
- HOST_USER_GID=${HOST_USER_GID:-1001}
- NUCLIO_VERSION=1.13.0
- OPA_VERSION=0.63.0
restart: no
entrypoint: ["/bin/bash", "-c"]
command: ["sleep infinity"]
environment:
DEVCONTAINER: 1
CVAT_SERVERLESS: 1
IAM_OPA_HOST: http://opa:8181
DJANGO_LOG_SERVER_HOST: ${DJANGO_LOG_SERVER_HOST:-}
DJANGO_SUPERUSER_USERNAME: ${DJANGO_SUPERUSER_USERNAME:-admin}
DJANGO_SUPERUSER_PASSWORD: ${DJANGO_SUPERUSER_PASSWORD:-admin}
DJANGO_SUPERUSER_EMAIL: ${DJANGO_SUPERUSER_EMAIL:[email protected]}
volumes: !override
- .:/home/devcontainer/workspaces
- ${HOME}/.ssh:/home/devcontainer/.ssh
- cvat_data:/home/devcontainer/workspaces/data
- cvat_keys:/home/devcontainer/workspaces/keys
- cvat_logs:/home/devcontainer/workspaces/logs
# For improving write performance on non-linux machines, static files should be
# mounted to named volumes
- cvat_node_modules:/home/devcontainer/workspaces/node_modules
- cvat_server_static:/home/devcontainer/workspaces/static
- cvat_pip_cache:/home/devcontainer/.cache/pip
# Preserve important user data between rebuilds
- cvat_user_data:/home/devcontainer/
# Exclude .vscode-server directories to enable reinstall of extensions upon rebuild
- /home/devcontainer/.vscode-server-insiders
- /home/devcontainer/.vscode-server
labels:
- com.devcontainer.git_branch_${GIT_BRANCH:-}

cvat_db:
restart: no
labels:
- com.devcontainer.git_branch=${GIT_BRANCH:-}

cvat_redis_inmem:
restart: no
labels:
- com.devcontainer.git_branch=${GIT_BRANCH:-}

cvat_redis_ondisk:
restart: no
labels:
- com.devcontainer.git_branch=${GIT_BRANCH:-}

cvat_opa:
restart: no
labels:
- com.devcontainer.git_branch=${GIT_BRANCH:-}

# VS code shuts down containers upon closing the window. If in any case if it fails to shut
# down the containers they should not restart upon system restart. This shall save
# unncessary memory usage of the system when not developing

volumes:
cvat_node_modules:
cvat_server_static:
cvat_pip_cache:
cvat_user_data:
cvat_db:
name: cvat_db_${GIT_BRANCH:-}
cvat_data:
name: cvat_data_${GIT_BRANCH:-}
cvat_keys:
name: cvat_keys_${GIT_BRANCH:-}
cvat_logs:
name: cvat_logs_${GIT_BRANCH:-}
cvat_inmem_db:
name: cvat_inmem_db_${GIT_BRANCH:-}
cvat_cache_db:
name: cvat_cache_db_${GIT_BRANCH:-}

# Volumes are parameterized with the current git branch values to isolate development environment based on git branches

Loading