From ac0a9d02bd6a5a7c076670c56aa5fbaf75640428 Mon Sep 17 00:00:00 2001 From: Zander Chase <130414180+vowelparrot@users.noreply.github.com> Date: Thu, 4 May 2023 11:37:00 -0700 Subject: [PATCH] Visual Studio Code/Github Codespaces Dev Containers (#4035) (#4122) Having dev containers makes its easier, faster and secure to setup the dev environment for the repository. The pull request consists of: - .devcontainer folder with: - **devcontainer.json :** (minimal necessary vscode extensions and settings) - **docker-compose.yaml :** (could be modified to run necessary services as per need. Ex vectordbs, databases) - **Dockerfile:**(non root with dev tools) - Changes to README - added the Open in Github Codespaces Badge - added the Open in dev container Badge Co-authored-by: Jinto Jose <129657162+jj701@users.noreply.github.com> --- .devcontainer/Dockerfile | 42 +++++++++++++++++++++++++++++++ .devcontainer/devcontainer.json | 33 ++++++++++++++++++++++++ .devcontainer/docker-compose.yaml | 31 +++++++++++++++++++++++ README.md | 3 ++- 4 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/docker-compose.yaml diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000000..4c5d56bd2c --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,42 @@ +# This is a Dockerfile for Developer Container + +# Use the Python base image +ARG VARIANT="3.11-bullseye" +FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT} AS langchain-dev-base + +USER vscode + +# Define the version of Poetry to install (default is 1.4.2) +# Define the directory of python virtual environment +ARG PYTHON_VIRTUALENV_HOME=/home/vscode/langchain-py-env \ + POETRY_VERSION=1.4.2 + +ENV POETRY_VIRTUALENVS_IN_PROJECT=false \ + POETRY_NO_INTERACTION=true + +# Create a Python virtual environment for Poetry and install it +RUN python3 -m venv ${PYTHON_VIRTUALENV_HOME} && \ + $PYTHON_VIRTUALENV_HOME/bin/pip install --upgrade pip && \ + $PYTHON_VIRTUALENV_HOME/bin/pip install poetry==${POETRY_VERSION} + +ENV PATH="$PYTHON_VIRTUALENV_HOME/bin:$PATH" \ + VIRTUAL_ENV=$PYTHON_VIRTUALENV_HOME + +# Setup for bash +RUN poetry completions bash >> /home/vscode/.bash_completion && \ + echo "export PATH=$PYTHON_VIRTUALENV_HOME/bin:$PATH" >> ~/.bashrc + +# Set the working directory for the app +WORKDIR /workspaces/langchain + +# Use a multi-stage build to install dependencies +FROM langchain-dev-base AS langchain-dev-dependencies + +ARG PYTHON_VIRTUALENV_HOME + +# Copy only the dependency files for installation +COPY pyproject.toml poetry.lock poetry.toml ./ + +# Install the Poetry dependencies (this layer will be cached as long as the dependencies don't change) +RUN poetry install --no-interaction --no-ansi --with dev,test,docs + diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000000..b3e3efb513 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,33 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-dockerfile +{ + "dockerComposeFile": "./docker-compose.yaml", + "service": "langchain", + "workspaceFolder": "/workspaces/langchain", + "name": "langchain", + "customizations": { + "vscode": { + "extensions": [ + "ms-python.python" + ], + "settings": { + "python.defaultInterpreterPath": "/home/vscode/langchain-py-env/bin/python3.11" + } + } + + }, + + // Features to add to the dev container. More info: https://containers.dev/features. + "features": {}, + + // 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. + // "postCreateCommand": "cat /etc/os-release", + + // Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "devcontainer" + "remoteUser": "vscode", + "overrideCommand": true +} diff --git a/.devcontainer/docker-compose.yaml b/.devcontainer/docker-compose.yaml new file mode 100644 index 0000000000..824b7e7843 --- /dev/null +++ b/.devcontainer/docker-compose.yaml @@ -0,0 +1,31 @@ +version: '3' +services: + langchain: + build: + dockerfile: .devcontainer/Dockerfile + context: ../ + volumes: + - ../:/workspaces/langchain + networks: + - langchain-network + # environment: + # MONGO_ROOT_USERNAME: root + # MONGO_ROOT_PASSWORD: example123 + # depends_on: + # - mongo + # mongo: + # image: mongo + # restart: unless-stopped + # environment: + # MONGO_INITDB_ROOT_USERNAME: root + # MONGO_INITDB_ROOT_PASSWORD: example123 + # ports: + # - "27017:27017" + # networks: + # - langchain-network + +networks: + langchain-network: + driver: bridge + + diff --git a/README.md b/README.md index f7251f5d9a..bf14363970 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,8 @@ ⚡ Building applications with LLMs through composability ⚡ -[![lint](https://github.com/hwchase17/langchain/actions/workflows/lint.yml/badge.svg)](https://github.com/hwchase17/langchain/actions/workflows/lint.yml) [![test](https://github.com/hwchase17/langchain/actions/workflows/test.yml/badge.svg)](https://github.com/hwchase17/langchain/actions/workflows/test.yml) [![linkcheck](https://github.com/hwchase17/langchain/actions/workflows/linkcheck.yml/badge.svg)](https://github.com/hwchase17/langchain/actions/workflows/linkcheck.yml) [![Downloads](https://static.pepy.tech/badge/langchain/month)](https://pepy.tech/project/langchain) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Twitter](https://img.shields.io/twitter/url/https/twitter.com/langchainai.svg?style=social&label=Follow%20%40LangChainAI)](https://twitter.com/langchainai) [![](https://dcbadge.vercel.app/api/server/6adMQxSpJS?compact=true&style=flat)](https://discord.gg/6adMQxSpJS) +[![lint](https://github.com/hwchase17/langchain/actions/workflows/lint.yml/badge.svg)](https://github.com/hwchase17/langchain/actions/workflows/lint.yml) [![test](https://github.com/hwchase17/langchain/actions/workflows/test.yml/badge.svg)](https://github.com/hwchase17/langchain/actions/workflows/test.yml) [![linkcheck](https://github.com/hwchase17/langchain/actions/workflows/linkcheck.yml/badge.svg)](https://github.com/hwchase17/langchain/actions/workflows/linkcheck.yml) [![Downloads](https://static.pepy.tech/badge/langchain/month)](https://pepy.tech/project/langchain) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Twitter](https://img.shields.io/twitter/url/https/twitter.com/langchainai.svg?style=social&label=Follow%20%40LangChainAI)](https://twitter.com/langchainai) [![](https://dcbadge.vercel.app/api/server/6adMQxSpJS?compact=true&style=flat)](https://discord.gg/6adMQxSpJS) [![Open in Dev Containers](https://img.shields.io/static/v1?label=Dev%20Containers&message=Open&color=blue&logo=visualstudiocode)](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/hwchase17/langchain) [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/hwchase17/langchain) + Looking for the JS/TS version? Check out [LangChain.js](https://github.com/hwchase17/langchainjs).