Skip to content

Commit

Permalink
Added dockerfile, devcontainer, and codespaces support
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Panchenko committed Jun 6, 2024
1 parent f6f79ca commit 83b70ff
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 0 deletions.
16 changes: 16 additions & 0 deletions {{cookiecutter.project_name}}/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "{{cookiecutter.project_name}} Project",
"dockerFile": "../Dockerfile",
"workspaceFolder": "/workspaces/{{cookiecutter.project_name}}",
"settings": {
"terminal.integrated.shell.linux": "/bin/bash",
"python.pythonPath": "/usr/local/bin/python",
},
"extensions": [
"ms-python.python",
"ms-toolsai.jupyter",
"ms-python.vscode-pylance"
],
"forwardPorts": [],
"remoteUser": "root",
}
9 changes: 9 additions & 0 deletions {{cookiecutter.project_name}}/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
data
logs
log
test/log
docs/jupyter_execute
docs/.jupyter_cache
docs/_build
coverage.xml
docker_build_and_run.sh
36 changes: 36 additions & 0 deletions {{cookiecutter.project_name}}/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Use the official Python image for the base image.
FROM python:{{cookiecutter.python_version}}-slim

# Set environment variables to make Python print directly to the terminal and avoid .pyc files.
ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1

# Install system dependencies required for pipx and Poetry.
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
build-essential \
git \
&& rm -rf /var/lib/apt/lists/*

# Install pipx.
RUN python3 -m pip install --no-cache-dir pipx \
&& pipx ensurepath

# Add poetry to the path
ENV PATH="${PATH}:/root/.local/bin"

# Install the latest version of Poetry using pipx.
RUN pipx install poetry

# Set the working directory. IMPORTANT: can't be changed as needs to be in sync to the dir where the project is cloned
# to in the codespace
WORKDIR /workspaces/{{cookiecutter.project_name}}

# Copy the pyproject.toml and poetry.lock files (if available) into the image.
COPY pyproject.toml poetry.lock* /workspaces/{{cookiecutter.project_name}}/

RUN poetry install --with dev

# Entrypoint should be a shell in the workdir with poetry shell activated
# Before that, the project should be installed with poetry install
ENTRYPOINT ["/bin/bash", "-c", "poetry install --with dev && poetry shell && $0 $@"]
42 changes: 42 additions & 0 deletions {{cookiecutter.project_name}}/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,48 @@

Welcome to the {{cookiecutter.project_name}} library!

## Getting Started

Clone the repository and run

```shell
git submodule update --init --recursive
```

to also pull the git submodules.

### Python setup

You can install the dependencies with

```shell
poetry install --with dev
```

### Docker setup

Build the docker image with

```shell
docker build -t {{cookiecutter.project_name}} .
```

and run it with the repository mounted as a volume:

```shell
docker run -it --rm -v "$(pwd)":/workspace {{cookiecutter.project_name}}
```

You can also just run `bash docker_build_and_run.sh`, which will do both things
for you.

Note: for the WSL subsystem on Windows you might need to adjust the path for the
volume.

### Codespaces

The fastest way to get started is to use a GitHub Codespace. Just click on the
button in the repository's main page.

## Contributing
Please open new issues for bugs, feature requests and extensions. See more details about the structure and
Expand Down
5 changes: 5 additions & 0 deletions {{cookiecutter.project_name}}/docker_build_and_run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/bash

docker build -t {{cookiecutter.project_name}} .

docker run -it --rm -v "$(pwd)":/workspace {{cookiecutter.project_name}}

0 comments on commit 83b70ff

Please sign in to comment.