Skip to content

Commit ccd916b

Browse files
bamurtaughbamurtaughsamruddhikhandale
authored
Update dev container (langchain-ai#6189)
Fixes langchain-ai#6172 As described in langchain-ai#6172, I'd love to help update the dev container in this project. **Summary of changes:** - Dev container now builds (the current container in this repo won't build for me) - Dockerfile updates - Update image to our [currently-maintained Python image](https://github.com/devcontainers/images/tree/main/src/python/.devcontainer) (`mcr.microsoft.com/devcontainers/python`) rather than the deprecated image from vscode-dev-containers - Move Dockerfile to root of repo - in order for `COPY` to work properly, it needs the files (in this case, `pyproject.toml` and `poetry.toml`) in the same directory - devcontainer.json updates - Removed `customizations` and `remoteUser` since they should be covered by the updated image in the Dockerfile - Update comments - Update docker-compose.yaml to properly point to updated Dockerfile - Add a .gitattributes to avoid line ending conversions, which can result in hundreds of pending changes ([info](https://code.visualstudio.com/docs/devcontainers/tips-and-tricks#_resolving-git-line-ending-issues-in-containers-resulting-in-many-modified-files)) - Add a README in the .devcontainer folder and info on the dev container in the contributing.md **Outstanding questions:** - Is it expected for `poetry install` to take some time? It takes about 30 minutes for this dev container to finish building in a Codespace, but a user should only have to experience this once. Through some online investigation, this doesn't seem unusual - Versions of poetry newer than 1.3.2 failed every time - based on some of the guidance in contributing.md and other online resources, it seemed changing poetry versions might be a good solution. 1.3.2 is from Jan 2023 --------- Co-authored-by: bamurtaugh <brmurtau@microsoft.com> Co-authored-by: Samruddhi Khandale <samruddhikhandale@github.com>
1 parent 03b5891 commit ccd916b

File tree

6 files changed

+75
-30
lines changed

6 files changed

+75
-30
lines changed

.devcontainer/README.md

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Dev container
2+
3+
This project includes a [dev container](https://containers.dev/), which lets you use a container as a full-featured dev environment.
4+
5+
You can use the dev container configuration in this folder to build and run the app without needing to install any of its tools locally! You can use it in [GitHub Codespaces](https://github.com/features/codespaces) or the [VS Code Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers).
6+
7+
## GitHub Codespaces
8+
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/hwchase17/langchain)
9+
10+
You may use the button above, or follow these steps to open this repo in a Codespace:
11+
1. Click the **Code** drop-down menu at the top of https://github.com/hwchase17/langchain.
12+
1. Click on the **Codespaces** tab.
13+
1. Click **Create codespace on master** .
14+
15+
For more info, check out the [GitHub documentation](https://docs.github.com/en/free-pro-team@latest/github/developing-online-with-codespaces/creating-a-codespace#creating-a-codespace).
16+
17+
## VS Code Dev Containers
18+
[![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)
19+
20+
If you already have VS Code and Docker installed, you can use the button above to get started. This will cause VS Code to automatically install the Dev Containers extension if needed, clone the source code into a container volume, and spin up a dev container for use.
21+
22+
You can also follow these steps to open this repo in a container using the VS Code Dev Containers extension:
23+
24+
1. If this is your first time using a development container, please ensure your system meets the pre-reqs (i.e. have Docker installed) in the [getting started steps](https://aka.ms/vscode-remote/containers/getting-started).
25+
26+
2. Open a locally cloned copy of the code:
27+
28+
- Clone this repository to your local filesystem.
29+
- Press <kbd>F1</kbd> and select the **Dev Containers: Open Folder in Container...** command.
30+
- Select the cloned copy of this folder, wait for the container to start, and try things out!
31+
32+
You can learn more in the [Dev Containers documentation](https://code.visualstudio.com/docs/devcontainers/containers).
33+
34+
## Tips and tricks
35+
36+
* If you are working with the same repository folder in a container and Windows, you'll want consistent line endings (otherwise you may see hundreds of changes in the SCM view). The `.gitattributes` file in the root of this repo will disable line ending conversion and should prevent this. See [tips and tricks](https://code.visualstudio.com/docs/devcontainers/tips-and-tricks#_resolving-git-line-ending-issues-in-containers-resulting-in-many-modified-files) for more info.
37+
* If you'd like to review the contents of the image used in this dev container, you can check it out in the [devcontainers/images](https://github.com/devcontainers/images/tree/main/src/python) repo.

.devcontainer/devcontainer.json

+24-21
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,36 @@
11
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2-
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-dockerfile
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-docker-compose
33
{
4+
// Name for the dev container
5+
"name": "langchain",
6+
7+
// Point to a Docker Compose file
48
"dockerComposeFile": "./docker-compose.yaml",
9+
10+
// Required when using Docker Compose. The name of the service to connect to once running
511
"service": "langchain",
6-
"workspaceFolder": "/workspaces/langchain",
7-
"name": "langchain",
8-
"customizations": {
9-
"vscode": {
10-
"extensions": [
11-
"ms-python.python"
12-
],
13-
"settings": {
14-
"python.defaultInterpreterPath": "/home/vscode/langchain-py-env/bin/python3.11"
15-
}
16-
}
17-
18-
},
19-
20-
// Features to add to the dev container. More info: https://containers.dev/features.
21-
"features": {},
12+
13+
// The optional 'workspaceFolder' property is the path VS Code should open by default when
14+
// connected. This is typically a file mount in .devcontainer/docker-compose.yml
15+
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
16+
17+
// Prevent the container from shutting down
18+
"overrideCommand": true
19+
20+
// Features to add to the dev container. More info: https://containers.dev/features
21+
// "features": {
22+
// "ghcr.io/devcontainers-contrib/features/poetry:2": {}
23+
// }
2224

2325
// Use 'forwardPorts' to make a list of ports inside the container available locally.
2426
// "forwardPorts": [],
2527

2628
// Uncomment the next line to run commands after the container is created.
2729
// "postCreateCommand": "cat /etc/os-release",
2830

29-
// Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root.
30-
// "remoteUser": "devcontainer"
31-
"remoteUser": "vscode",
32-
"overrideCommand": true
31+
// Configure tool-specific properties.
32+
// "customizations": {},
33+
34+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
35+
// "remoteUser": "root"
3336
}

.devcontainer/docker-compose.yaml

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ version: '3'
22
services:
33
langchain:
44
build:
5-
dockerfile: .devcontainer/Dockerfile
6-
context: ../
5+
dockerfile: dev.Dockerfile
6+
context: ..
77
volumes:
8-
- ../:/workspaces/langchain
8+
# Update this to wherever you want VS Code to mount the folder of your project
9+
- ..:/workspaces:cached
910
networks:
1011
- langchain-network
1112
# environment:

.gitattributes

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* text=auto eol=lf
2+
*.{cmd,[cC][mM][dD]} text eol=crlf
3+
*.{bat,[bB][aA][tT]} text eol=crlf

.github/CONTRIBUTING.md

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ we do not want these to get in the way of getting good code into the codebase.
5959

6060
## 🚀 Quick Start
6161

62+
> **Note:** You can run this repository locally (which is described below) or in a [development container](https://containers.dev/) (which is described in the [.devcontainer folder](https://github.com/hwchase17/langchain/tree/master/.devcontainer)).
63+
6264
This project uses [Poetry](https://python-poetry.org/) as a dependency manager. Check out Poetry's [documentation on how to install it](https://python-poetry.org/docs/#installation) on your system before proceeding.
6365

6466
❗Note: If you use `Conda` or `Pyenv` as your environment / package manager, avoid dependency conflicts by doing the following first:

.devcontainer/Dockerfile dev.Dockerfile

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
# This is a Dockerfile for Developer Container
1+
# This is a Dockerfile for the Development Container
22

33
# Use the Python base image
44
ARG VARIANT="3.11-bullseye"
5-
FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT} AS langchain-dev-base
5+
FROM mcr.microsoft.com/devcontainers/python:0-${VARIANT} AS langchain-dev-base
66

77
USER vscode
88

99
# Define the version of Poetry to install (default is 1.4.2)
1010
# Define the directory of python virtual environment
1111
ARG PYTHON_VIRTUALENV_HOME=/home/vscode/langchain-py-env \
12-
POETRY_VERSION=1.4.2
12+
POETRY_VERSION=1.3.2
1313

1414
ENV POETRY_VIRTUALENVS_IN_PROJECT=false \
1515
POETRY_NO_INTERACTION=true
@@ -35,8 +35,7 @@ FROM langchain-dev-base AS langchain-dev-dependencies
3535
ARG PYTHON_VIRTUALENV_HOME
3636

3737
# Copy only the dependency files for installation
38-
COPY pyproject.toml poetry.lock poetry.toml ./
38+
COPY pyproject.toml poetry.toml ./
3939

4040
# Install the Poetry dependencies (this layer will be cached as long as the dependencies don't change)
41-
RUN poetry install --no-interaction --no-ansi --with dev,test,docs
42-
41+
RUN poetry install --no-interaction --no-ansi --with dev,test,docs

0 commit comments

Comments
 (0)