Skip to content

Commit

Permalink
Add devcontainer (#485)
Browse files Browse the repository at this point in the history
  • Loading branch information
frcroth authored Feb 11, 2024
1 parent e3508fe commit fcd7ac2
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM mcr.microsoft.com/devcontainers/python:3.11

# Add more tools needed in the devcontainer here
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends \
nano \
pipx \
gettext \
&& true

ENV POETRY_VERSION=1.3.2

# README steps
RUN pip install "poetry==$POETRY_VERSION"
RUN poetry self add "poetry-dynamic-versioning[plugin]"

ENV SHELL=/bin/bash
24 changes: 24 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 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": "myHPI-dev-container",
"build": {
"dockerfile": "Dockerfile",
"context": ".."
},

// 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": [8000],

// Uncomment the next line to run commands after the container is created.
"postCreateCommand": "bash .devcontainer/setup.sh"

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "devcontainer"
}
16 changes: 16 additions & 0 deletions .devcontainer/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
python -m venv env
source env/bin/activate
poetry install
if python tools/install_bootstrap.py --is-installed; then
echo "Bootstrap is already installed."
else
python tools/install_bootstrap.py
fi

if [ ! -f .env ]; then
cp .env.example .env
fi

python manage.py migrate
python manage.py compilemessages
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ This tool is used to manage the student representative website at https://myhpi.

## Development setup

For a quick start, use the [dev container](https://containers.dev/), e.g. by installing the [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) in Visual Studio Code or using the [built-in feature in JetBrains IDEs](jetbrains.com/help/idea/connect-to-devcontainer.html). This automatically installs all dependencies in a container. After starting the container, setup your local data by following the Manual Setup from step 9 (creating a superuser).

### Manual setup

To set up a development version on your local machine, you need to execute the following steps:

1. Check out repository and cd to it
Expand Down
14 changes: 14 additions & 0 deletions tools/install_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ def remove_current_bootstrap():
os.remove(bootstrap_min_js_map_path)


def is_bootstrap_installed():
return (
os.path.exists(os.path.join("myhpi", "static", "scss", "bootstrap"))
and os.path.exists(os.path.join("myhpi", "static", "js", "bootstrap.bundle.min.js"))
and os.path.exists(os.path.join("myhpi", "static", "js", "bootstrap.bundle.min.js.map"))
)


def init_argparse() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
usage="%(prog)s [-u]", description="Install bootstrap for myHPI."
Expand All @@ -100,6 +108,9 @@ def init_argparse() -> argparse.ArgumentParser:
parser.add_argument(
"-r", "--remove", action="store_true", help="Remove current bootstrap installation."
)
parser.add_argument(
"--is-installed", action="store_true", help="Check if bootstrap is installed."
)
return parser


Expand All @@ -115,6 +126,9 @@ def install_bootstrap():
Ensure that it is run in the top directory of the repository."
)
exit(1)
if args.is_installed:
is_installed = is_bootstrap_installed()
exit(0 if is_installed else 1)
if args.update or args.remove:
remove_current_bootstrap()
if args.remove:
Expand Down

0 comments on commit fcd7ac2

Please sign in to comment.