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

build: devcontainer TDE-598 #285

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM osgeo/gdal:ubuntu-small-3.6.1

RUN apt update && apt install -y python3-pip python3-distutils git
RUN curl -sSL https://install.python-poetry.org | python3 -

# Allowing access to osgeo/gdal python library within the venv environment created with Poetry
ENV PYTHONPATH="/lib/python3/dist-packages:/workspaces/topo-imagery:$PYTHONPATH"

ENV PATH=/root/.local/bin:$PATH
25 changes: 25 additions & 0 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# topo-imagery devcontainer

The purpose of this devcontainer is to avoid any trouble to the developers managing a Python environment with GDAL and other dependencies.

> **_NOTE:_** It has been setup to be used with VSCode under a linux environment. Some functionalities might not work with a different configuration.

## `Dockerfile`

This Docker container describes the OS configuration for the development environment. It is intended to be based on the same Docker image than our production container.

## `devcontainer.json`

It allows us to use common settings for the development environment.

### `post_create.sh`

This script is run after the container is created.

### `post_start.sh`

This script is run everytime the container is started.

## Usage

Once opened the local cloned repository in VSCode, click on the bottom left corner green button `><` `Open a Remote Window` and select the `Reopen in Container` option. Wait for the container to be build. Open a new terminal from VSCode. It should source the Python `venv`.
49 changes: 49 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 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
{
"name": "topo-imagery-dev",
"context": "..",
"dockerFile": "Dockerfile",
"customizations": {
"vscode": {
"settings": {
"terminal.integrated.profiles.linux": {
"bash": {
"path": "/bin/bash"
}
},
"editor.codeActionsOnSave": {
"source.organizeImports": true
},
"python.defaultInterpreterPath": "${containerWorkspaceFolder}/.venv/bin/python3.10",
"python.formatting.blackPath": "${containerWorkspaceFolder}/.venv/bin/black",
"python.linting.mypyPath": "${containerWorkspaceFolder}/.venv/bin/mypy",
"python.linting.pylintPath": "${containerWorkspaceFolder}/.venv/bin/pylint",
"python.formatting.provider": "black",
"python.testing.pytestEnabled": true,
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"editor.formatOnSave": true,
"autoDocstring.docstringFormat": "google-notypes"
},
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"esbenp.prettier-vscode",
"njpwerner.autodocstring"
]
}
},
"postCreateCommand": "bash ./.devcontainer/post_create.sh",
"postStartCommand": "bash ./.devcontainer/post_start.sh ${containerWorkspaceFolder}",
"mounts": [
"source=${localEnv:HOME}${localEnv:USERPROFILE}/.aws,target=/root/.aws,type=bind",
"source=${localEnv:HOME}${localEnv:USERPROFILE}/.bashrc,target=/root/.bashrc,type=bind,consistency=cached"
//"source=${localEnv:HOME}${localEnv:USERPROFILE}/tmp,target=/tmp,type=bind"
],
// https://containers.dev/features
// NOTE: installing Git in that way took more time than within the Dockerfile
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
}
}
8 changes: 8 additions & 0 deletions .devcontainer/post_create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

# Change Poetry settings to better deal with working in a container
poetry config cache-dir $(pwd)/.cache
poetry config virtualenvs.in-project true

# Install all dependencies with poetry
poetry install --no-interaction
4 changes: 4 additions & 0 deletions .devcontainer/post_start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

git config --global --add safe.directory $1
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix in devcontainer pre-release mentioned in microsoft/vscode-remote-release#7628 (comment) did not work for me

poetry run pre-commit install
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.cache
/.coverage
/html/
/htmlcov/
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@ Python version is set to `3.8.10` as it is the current version used by `osgeo/gd
```bash
docker run -v ${HOME}/.aws/credentials:/root/.aws/credentials:ro -e AWS_PROFILE 'image-id' python create_polygons.py --uri 's3://path-to-the-tiff/image.tif' --destination 'destination-bucket'
```

#### Development

This repo has a `devcontainer` which can be used within VSCode as a development environment with all of the required dependencies included. See the [.devcontainer/README.md](/.devcontainer/README.md) for more information.