diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 95efa14a..8cbdca97 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,13 +1,13 @@ -FROM eligibility_server:latest - -# install python tooling -COPY .devcontainer/requirements.txt .devcontainer/requirements.txt -RUN pip install --no-cache-dir -r .devcontainer/requirements.txt - -# install docs tooling -COPY docs/requirements.txt docs/requirements.txt -RUN pip install --no-cache-dir -r docs/requirements.txt - -# install test tooling -COPY tests/requirements.txt tests/requirements.txt -RUN pip install -r tests/requirements.txt +FROM eligibility_server:latest + +# install python tooling +COPY .devcontainer/requirements.txt .devcontainer/requirements.txt +RUN pip install --no-cache-dir -r .devcontainer/requirements.txt + +# install docs tooling +COPY docs/requirements.txt docs/requirements.txt +RUN pip install --no-cache-dir -r docs/requirements.txt + +# install test tooling +COPY tests/requirements.txt tests/requirements.txt +RUN pip install -r tests/requirements.txt diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 1d4f55aa..d1572d95 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,28 +1,30 @@ // For format details, see https://aka.ms/vscode-remote/devcontainer.json { "name": "cal-itp/eligibility-server", - "dockerComposeFile": ["compose.yml"], + "dockerComposeFile": ["../compose.yml"], "service": "dev", "runServices": ["dev", "docs"], "workspaceFolder": "/home/calitp/app", - "postAttachCommand": ["/bin/bash", ".devcontainer/pre-commit.sh"], + "postStartCommand": ["/bin/bash", "bin/init.sh"], + "postAttachCommand": ["/bin/bash", ".devcontainer/postAttach.sh"], // Set *default* container specific settings.json values on container create. "settings": { - "terminal.integrated.defaultProfile.linux": "bash", - "terminal.integrated.profiles.linux": { - "bash": { - "path": "/bin/bash" - } + "terminal.integrated.defaultProfile.linux": "bash", + "terminal.integrated.profiles.linux": { + "bash": { + "path": "/bin/bash" } + } }, // Add the IDs of extensions you want installed when the container is created. "extensions": [ - "batisteo.vscode-django", - "ms-python.python", - "ms-python.vscode-pylance", - "eamodio.gitlens", - "mhutchie.git-graph" + "bpruitt-goddard.mermaid-markdown-syntax-highlighting", + "eamodio.gitlens", + "esbenp.prettier-vscode", + "mhutchie.git-graph", + "ms-python.python", + "ms-python.vscode-pylance" ] } diff --git a/.devcontainer/pre-commit.sh b/.devcontainer/postAttach.sh old mode 100644 new mode 100755 similarity index 56% rename from .devcontainer/pre-commit.sh rename to .devcontainer/postAttach.sh index b576c2df..15ee70ca --- a/.devcontainer/pre-commit.sh +++ b/.devcontainer/postAttach.sh @@ -1,8 +1,5 @@ #!/usr/bin/env bash -set -eu +set -eux # initialize hook environments pre-commit install --install-hooks --overwrite - -# manage commit-msg hooks -pre-commit install --hook-type commit-msg diff --git a/.devcontainer/requirements.txt b/.devcontainer/requirements.txt index de63c055..0164b67a 100644 --- a/.devcontainer/requirements.txt +++ b/.devcontainer/requirements.txt @@ -1,2 +1,3 @@ +black flake8 pre-commit diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..0866a5b7 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +.git/ +.github/ +.vscode/ +.flake8 +.*ignore diff --git a/.devcontainer/.env.sample b/.env.sample similarity index 100% rename from .devcontainer/.env.sample rename to .env.sample diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 945b6bea..5efd57f5 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -2,7 +2,7 @@ name: Run pytests on: pull_request: - branches: [ "*" ] + branches: ["*"] jobs: tests: @@ -23,7 +23,7 @@ jobs: - name: Load environment variables uses: cardinalby/export-env-action@v1 with: - envFile: .devcontainer/.env.sample + envFile: .env.sample - name: Test with pytest run: | diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e912b0bd..e98ea507 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,3 +1,7 @@ +default_install_hook_types: + - pre-commit + - commit-msg + repos: - repo: https://github.com/compilerla/conventional-pre-commit rev: v2.0.0 diff --git a/.vscode/settings.json b/.vscode/settings.json index 82128960..86c82d8e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,11 +1,20 @@ { + "editor.defaultFormatter": "esbenp.prettier-vscode", + "editor.formatOnSave": true, + "files.encoding": "utf8", + "files.eol": "\n", + "files.insertFinalNewline": true, + "files.trimFinalNewlines": true, + "files.trimTrailingWhitespace": true, + "[python]": { + "editor.defaultFormatter": "ms-python.python" + }, + "python.defaultInterpreterPath": "/usr/local/bin/python", + "python.formatting.provider": "black", + "python.languageServer": "Pylance", "python.linting.flake8Enabled": true, "python.linting.enabled": true, - "python.languageServer": "Pylance", - "python.testing.pytestArgs": [ - "tests" - ], + "python.testing.pytestArgs": ["tests"], "python.testing.unittestEnabled": false, - "python.testing.pytestEnabled": true, - "python.defaultInterpreterPath": "/usr/local/bin/python", + "python.testing.pytestEnabled": true } diff --git a/bin/init.sh b/bin/init.sh new file mode 100755 index 00000000..55be042d --- /dev/null +++ b/bin/init.sh @@ -0,0 +1,6 @@ +#! usr/bin/env bash +set -eux + +# run database migrations + +python setup.py diff --git a/bin/start.sh b/bin/start.sh old mode 100644 new mode 100755 index f7169d2e..9be866d0 --- a/bin/start.sh +++ b/bin/start.sh @@ -1,6 +1,10 @@ #! usr/bin/env bash set -eux -python setup.py +# initialize Flask + +bin/init.sh + +# start the web server flask run -h 0.0.0.0 diff --git a/.devcontainer/compose.yml b/compose.yml similarity index 76% rename from .devcontainer/compose.yml rename to compose.yml index 134198da..73cee41b 100644 --- a/.devcontainer/compose.yml +++ b/compose.yml @@ -1,17 +1,19 @@ +name: eligibility-server version: "3.8" services: server: - build: .. + build: . env_file: .env image: eligibility_server:latest ports: - "5000" volumes: - - ../:/home/calitp/app/ + - .:/home/calitp/app/ + dev: build: - context: .. + context: . dockerfile: .devcontainer/Dockerfile entrypoint: sleep infinity env_file: .env @@ -19,7 +21,8 @@ services: ports: - "5000" volumes: - - ../:/home/calitp/app/ + - .:/home/calitp/app/ + docs: image: eligibility_server:dev entrypoint: mkdocs @@ -27,4 +30,4 @@ services: ports: - "8000" volumes: - - ../:/home/calitp/app:cached + - .:/home/calitp/app diff --git a/docs/README.md b/docs/README.md index a66a2e16..5fb43b2d 100644 --- a/docs/README.md +++ b/docs/README.md @@ -23,7 +23,6 @@ Running the application locally is possible with [Docker and Docker Compose](htt ### Build the Docker container for local development ```bash -cd .devcontainer cp .env.sample .env docker compose build server ``` diff --git a/docs/getting-started.md b/docs/getting-started.md index 381196fa..9621e37e 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -18,7 +18,6 @@ cd eligibility-server Use the sample as the template. ```bash -cd .devcontainer cp .env.sample .env ``` @@ -50,7 +49,6 @@ Asterisk * indicates required ### Build image using Docker Compose ```bash -cd .devcontainer docker compose build --no-cache server ``` @@ -86,7 +84,8 @@ Once you clone the repository locally, open it within VS Code, which will prompt 2. Start the `eligibility-server` Flask app and database with `F5` 3. Now you can run tests from the container. -Starting the Dev Container will run `bin/start.sh`, which runs `setup.py` and starts the Flask app. The `setup.py` script creates a table, imports and saves users from a JSON or CSV file specified in the .env file from the `IMPORT_FILE_PATH` key. CSV files will require +Starting the Dev Container will run `bin/init.sh`, which runs `setup.py` and starts the Flask app. The `setup.py` script creates the database and imports and saves users +based on the configured settings. ## Run tests