From faf9487a94fb641c89faadb03051f4b33bbaa16e Mon Sep 17 00:00:00 2001 From: Dmitry Volodin Date: Tue, 19 Oct 2021 16:12:29 +0200 Subject: [PATCH] VSCode Dev Container --- .devcontainer/devcontainer.json | 32 ++++++++++++++++++++++++++++++++ .gitignore | 4 +--- Dockerfile | 14 +++++++++++--- requirements.txt | 3 +++ 4 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000000..f4c010cdb0 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,32 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: +// https://github.com/microsoft/vscode-dev-containers/tree/v0.202.3/containers/docker-existing-dockerfile +{ + "name": "NOC Dev Container", + "runArgs": [ + "--init" + ], + "build": { + // Sets the run context to one level up instead of the .devcontainer folder. + "context": "..", + // Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename. + "dockerfile": "../Dockerfile", + // Dockerfile target + "target": "dev" + }, + // Set *default* container specific settings.json values on container create. + "settings": {}, + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "ms-python.python" + ] + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + // Uncomment the next line to run commands after the container is created - for example installing curl. + // "postCreateCommand": "apt-get update && apt-get install -y curl", + // Uncomment when using a ptrace-based debugger like C++, Go, and Rust + // "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ], + // Uncomment to use the Docker CLI from inside the container. See https://aka.ms/vscode-remote/samples/docker-from-docker. + // "mounts": [ "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind" ], + // Uncomment to connect as a non-root user if you've added one. See https://aka.ms/vscode-remote/containers/non-root. + // "remoteUser": "vscode" +} \ No newline at end of file diff --git a/.gitignore b/.gitignore index f6059a4fae..00d2d49f9e 100644 --- a/.gitignore +++ b/.gitignore @@ -11,8 +11,8 @@ etc/** include/* lib/python* lib64 -local/* .* +!/.devcontainer/ !/.docker/* !/.gitignore !/.dockerignore* @@ -22,8 +22,6 @@ local/* !/.prettierrc !/scripts/build/ ext_* -etc/requirements/local.txt -share/ static/test/ pip-selfcheck.json var/ diff --git a/Dockerfile b/Dockerfile index 21786909fd..498e00504b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,7 @@ +# # Base layer containing system packages and requirements -FROM python:3.8.8-slim-buster AS code +# +FROM python:3.8.12-slim-buster AS code ENV\ DJANGO_SETTINGS_MODULE=noc.settings \ NOC_THREAD_STACK_SIZE=524288 \ @@ -32,7 +34,7 @@ RUN \ && mkdir /opt/nocspeedup \ && cp /opt/noc/speedup/*.so /opt/nocspeedup \ && if [ -f "$IP_SO" ]; then cp $IP_SO /opt/nocspeedup/ip.so; else \ - curl -LJO https://cdn.getnoc.com/noc/libs/libip.so && cp libip.so /opt/nocspeedup/ip.so; fi \ + curl -LJO https://cdn.getnoc.com/noc/libs/libip.so && cp libip.so /opt/nocspeedup/ip.so; fi \ && find /opt/noc/ -type f -name "*.py" -print0 | xargs -0 python3 -m py_compile \ && pip3 uninstall -y Cython \ && apt remove --purge -y $BUILD_PACKAGES \ @@ -41,7 +43,6 @@ RUN \ && useradd -d /opt/noc -M -r -u 1200 -U noc -s /bin/sh \ && chown noc /opt/noc - VOLUME /opt/noc EXPOSE 1200 @@ -50,15 +51,22 @@ EXPOSE 1200 #HEALTHCHECK --interval=10s --timeout=1s \ # CMD curl -f http://0.0.0.0:1200/health/ || exit 1 +# +# Developer's container +# FROM code AS dev RUN \ apt update && apt-get install -y --no-install-recommends \ snmp \ vim \ + git \ && (./scripts/build/get-noc-requirements.py dev | pip3 install -r /dev/stdin )\ && rm -rf /var/lib/apt/lists/* +# +# Self-serving static ui files +# FROM nginx:alpine AS static RUN apk add --no-cache curl diff --git a/requirements.txt b/requirements.txt index 88f8c64b47..3e35a008bf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -75,6 +75,9 @@ pylibmc==1.5.1; extra == "cache-memcached" Babel==2.3.4; extra == "dev" ipython==7.18.1; extra == "dev" pojson==0.7; extra == "dev" +flake8==4.0.1; extra == "dev" +mypy==0.910; extra == "dev" +black==21.9b0; extra == "dev" # Login LDAP ldap3==2.8.1; extra == "login-ldap" # Login PAM -- GitLab