chore: rewrite makefile in taskfile (#3035)

* add docker-compose with development dependencies

* delete old runtime.txt file

* specify specific group for postgres deps

* replace makefile with taskfile with new features

* drop template.env file in favor of defaults within taskfile

* use with github actions

* update docs for taskfile changes

* update task.json for vscode

* add taskfile to devcontainer.json

* pre-install taskfile so startup command works

* remove run command and fix desc for ui

* change node-> python->py for consistency
This commit is contained in:
Hayden 2024-01-27 12:14:42 -06:00 committed by GitHub
parent 4d49e307e3
commit 0800a8d00a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 244 additions and 264 deletions

View File

@ -14,6 +14,7 @@ RUN echo "export PROMPT_COMMAND='history -a'" >> /home/vscode/.bashrc \
&& echo "export HISTFILE=~/commandhistory/.bash_history" >> /home/vscode/.bashrc \
&& chown vscode:vscode -R /home/vscode/
RUN npm install -g @go-task/cli
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
@ -37,4 +38,3 @@ RUN apt-get update \
libwebp-dev \
libsasl2-dev libldap2-dev libssl-dev \
gnupg gnupg2 gnupg1
# && pip install -U --no-cache-dir pip

View File

@ -46,7 +46,7 @@
],
// Use 'onCreateCommand' to run commands at the end of container creation.
// Use 'postCreateCommand' to run commands after the container is created.
"onCreateCommand": "sudo chown -R vscode:vscode /workspaces/mealie/frontend/node_modules && make setup",
"onCreateCommand": "sudo chown -R vscode:vscode /workspaces/mealie/frontend/node_modules && task setup",
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode",
// "features": {

View File

@ -35,6 +35,12 @@ jobs:
# Steps
steps:
- name: Install Task
uses: arduino/setup-task@v1
with:
version: 3.x
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Check out repository
uses: actions/checkout@v4
@ -78,11 +84,11 @@ jobs:
- name: Lint (Ruff)
run: |
make backend-lint
task py:lint
- name: Mypy Typecheck
run: |
make backend-typecheck
task py:mypy
- name: Pytest
env:
@ -101,4 +107,4 @@ jobs:
LDAP_NAME_ATTRIBUTE: cn
LDAP_MAIL_ATTRIBUTE: mail
run: |
make backend-test
task py:test

1
.gitignore vendored
View File

@ -162,3 +162,4 @@ lcov.info
dev/code-generation/openapi.json
.run/
.task/*

23
.vscode/tasks.json vendored
View File

@ -1,22 +1,9 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "DEV: Build and Start Docker Compose",
"command": "make docker-dev",
"type": "shell",
"args": [],
"problemMatcher": [
"$tsc"
],
"presentation": {
"reveal": "always"
},
"group": "test"
},
{
"label": "Production: Build and Start Docker Compose",
"command": "make docker-prod",
"command": "task docker:prod",
"type": "shell",
"args": [],
"problemMatcher": [
@ -29,7 +16,7 @@
},
{
"label": "Dev: Start Backend",
"command": "make backend",
"command": "task py",
"type": "shell",
"presentation": {
"reveal": "always",
@ -49,7 +36,7 @@
},
{
"label": "Dev: Start Frontend",
"command": "make frontend",
"command": "task ui",
"type": "shell",
"presentation": {
"reveal": "always",
@ -59,7 +46,7 @@
},
{
"label": "Dev: Start Docs Server",
"command": "make docs",
"command": "task docs",
"type": "shell",
"presentation": {
"reveal": "always",
@ -69,7 +56,7 @@
},
{
"label": "Run python tests",
"command": "make test",
"command": "task py:test",
"type": "shell",
"presentation": {
"reveal": "always"

183
Taskfile.yml Normal file
View File

@ -0,0 +1,183 @@
# https://taskfile.dev
version: "3"
vars:
GREETING: Hello, World!
env:
DEFAULT_GROUP: Home
PRODUCTION: false
API_PORT: 9000
API_DOCS: True
TOKEN_TIME: 256 # hours
# mailplit SMTP config
# start dev:services to use mailpit
SMTP_HOST: localhost
SMTP_PORT: 1025
SMTP_FROM_NAME: MealieDev
SMTP_AUTH_STRATEGY: NONE
LANG: en-US
# loads .env file if it exists
dotenv:
- .env
- .dev.env
tasks:
docs:gen:
desc: runs the API documentation generator
cmds:
- poetry run python dev/code-generation/gen_docs_api.py
docs:
desc: runs the documentation server
dir: docs
deps:
- docs:gen
cmds:
- poetry run python -m mkdocs serve
setup:ui:
desc: setup frontend dependencies
dir: frontend
cmds:
- yarn install
setup:py:
desc: setup python dependencies
cmds:
- poetry install --with main,dev,postgres
- poetry run pre-commit install
setup:model:
desc: setup nlp model
vars:
MODEL_URL: https://github.com/mealie-recipes/nlp-model/releases/download/v1.0.0/model.crfmodel
OUTPUT: ./mealie/services/parser_services/crfpp/model.crfmodel
sources:
# using pyproject.toml as the dependency since this should only ever need to run once
# during setup. There is perhaps a better way to do this.
- ./pyproject.toml
generates:
- ./mealie/services/parser_services/crfpp/model.crfmodel
cmds:
- curl -L0 {{ .MODEL_URL }} --output {{ .OUTPUT }}
setup:
desc: setup all dependencies
deps:
- setup:ui
- setup:py
- setup:model
dev:generate:
desc: run code generators
cmds:
- poetry run python dev/code-generation/main.py
dev:services:
desc: starts postgres and mailpit containers
dir: docker
cmds:
- docker compose -f docker-compose.dev.yml up
dev:clean:
desc: cleans up dev environment !! removes all data files !!
vars:
DEV_DATA: ""
cmds:
- rm -r ./dev/data/recipes/
- rm -r ./dev/data/users/
- rm -f ./dev/data/mealie*.db
- rm -f ./dev/data/mealie.log
- rm -f ./dev/data/.secret
py:mypy:
desc: runs python type checking
cmds:
- poetry run mypy mealie
py:test:
desc: runs python tests (support args after '--')
cmds:
- poetry run pytest {{ .CLI_ARGS }}
py:format:
desc: runs python code formatter
cmds:
- poetry run black mealie
py:lint:
desc: runs python linter
cmds:
- poetry run ruff mealie
py:check:
desc: runs all linters, type checkers, and formatters
deps:
- py:format
- py:lint
- py:mypy
- py:test
py:coverage:
desc: runs python coverage and generates html report
cmds:
- poetry run pytest
- poetry run coverage report -m
- poetry run coveragepy-lcov
- poetry run coverage html
- open htmlcov/index.html
py:
desc: runs the backend server
cmds:
- poetry run python mealie/db/init_db.py
- poetry run python mealie/app.py
py:postgres:
desc: runs the backend server configured for containerized postgres
env:
DB_ENGINE: postgres
POSTGRES_USER: mealie
POSTGRES_PASSWORD: mealie
POSTGRES_SERVER: localhost
POSTGRES_PORT: 5432
POSTGRES_DB: mealie
cmds:
- poetry run python mealie/db/init_db.py
- poetry run python mealie/app.py
ui:build:
desc: builds the frontend in frontend/dist
dir: frontend
cmds:
- yarn build
ui:lint:
desc: runs the frontend linter
dir: frontend
cmds:
- yarn lint
ui:test:
desc: runs the frontend tests
dir: frontend
cmds:
- yarn test
ui:check:
desc: runs all frontend checks
deps:
- ui:lint
- ui:test
ui:
desc: runs the frontend server
dir: frontend
cmds:
- yarn run dev
docker:prod:
desc: builds and runs the production docker image locally
dir: docker
cmds:
- docker compose -f docker-compose.yml -p mealie up -d --build

View File

@ -0,0 +1,21 @@
version: "3.4"
services:
mailpit:
image: axllent/mailpit:latest
container_name: mealie_dev_mailpit
restart: no
environment:
- "MP_SMTP_AUTH_ACCEPT_ANY=true"
- "MP_SMTP_AUTH_ALLOW_INSECURE=true"
ports:
- "8025:8025"
- "1025:1025"
postgres:
container_name: mealie_dev_postgres
image: postgres:15
restart: no
ports:
- "5432:5432"
environment:
POSTGRES_PASSWORD: mealie
POSTGRES_USER: mealie

View File

@ -13,7 +13,7 @@ Pull requests are the best way to propose changes to the codebase (we use [Githu
3. If you're interested on working on major changes please get in touch on discord and coordinate with other developers. No sense in doubling up on work if someones already on it.
4. Once you've got an idea of what changes you want to make, create a draft PR as soon as you can to let us know what you're working on and how we can help!
5. If you've changed APIs, update the documentation.
6. Run tests, including `make backend-all`. Note that the tests do not clean up after themselves and leave things in the database. So be sure to also run `make clean-data` and/or `make backend-clean` inbetween major testing rounds to be sure that you aren't testing on old data.
6. Run tests, including `task py:check`.
6. Issue that pull request! First make a draft PR, make sure that the automated github tests all pass, then mark as ready for review.
7. Be sure to add release notes to the pull request.

View File

@ -14,12 +14,12 @@ Prerequisites
- Visual Studio Code
### Linux and MacOS
First ensure that docker is running. Then when you clone the repo and open with VS Code you should see a popup asking you to reopen the project inside a development container. Click yes and it will build the development container and run the setup required to run both the backend API and the frontend webserver. This also pre-configures pre-commit hooks to ensure that the code is up to date before committing.
### Windows
Make sure the VSCode Dev Containers extension is installed, then select "Dev Containers: Clone Repository in Container Volume..." in the command pallete (F1). Select your forked repo and choose the `mealie-next` branch, which contains the latest changes. This mounts your repository directly in WSL2, which [greatly improves the performance of the container](https://code.visualstudio.com/docs/devcontainers/containers#_quick-start-open-a-git-repository-or-github-pr-in-an-isolated-container-volume), and enables hot-reloading for the frontend. Running the container on a mounted volume may not work correctly on Windows due to WSL permission mapping issues.
[Checkout the makefile reference](#make-file-reference) for all of the available commands.
Make sure the VSCode Dev Containers extension is installed, then select "Dev Containers: Clone Repository in Container Volume..." in the command palette (F1). Select your forked repo and choose the `mealie-next` branch, which contains the latest changes. This mounts your repository directly in WSL2, which [greatly improves the performance of the container](https://code.visualstudio.com/docs/devcontainers/containers#_quick-start-open-a-git-repository-or-github-pr-in-an-isolated-container-volume), and enables hot-reloading for the frontend. Running the container on a mounted volume may not work correctly on Windows due to WSL permission mapping issues.
!!! tip
For slow terminal checkout the solution in this [GitHub Issue](https://github.com/microsoft/vscode/issues/133215)
@ -29,16 +29,18 @@ Make sure the VSCode Dev Containers extension is installed, then select "Dev Con
```
## Without Dev Containers
### Prerequisites
- [Python 3.10](https://www.python.org/downloads/)
- [Poetry](https://python-poetry.org/docs/#installation)
- [Node v16.x](https://nodejs.org/en/)
- [yarn](https://classic.yarnpkg.com/lang/en/docs/install/#mac-stable)
- [task](https://taskfile.dev/#/installation)
### Installing Dependencies
Once the prerequisites are installed you can cd into the project base directory and run `make setup` to install the python and node dependencies.
Once the prerequisites are installed you can cd into the project base directory and run `task setup` to install the python and node dependencies, and download the NLP model.
=== "Linux / macOS"
@ -46,29 +48,16 @@ Once the prerequisites are installed you can cd into the project base directory
# Naviate To The Root Directory
cd /path/to/project
# Utilize the Makefile to Install Dependencies
make setup
# Utilize the Taskfile to Install Dependencies
task setup
```
=== "Windows"
``` powershell
# Install Python Dependencies
Set-Directory -Path "C:\path\to\project"
poetry install
# Install Node Dependencies
Set-Directory frontend
yarn install
```
### Setting ENV Variables
Before you start the server you MUST copy the `template.env` and `frontend/template.env` files to their respective locations with the name `.env` and `frontend/.env` respectively. The application will-not run without these files.
## Postgres
- Whether using a container or manual install, you need to set up your own postgres dev server. The database, username, password, etc should match the `POSTGRES_*` options located in the `.env` file.
- Install psycog2 with `poetry install -E pgsql` (in the main `mealie` directory, *not* `frontend`)
The taskfile has two commands that need to be run to run the development environment against a postgres database.
- `task dev:services` - This will start the postgres database, and a smtp server for email testing.
- `task py:postgres` - This will run that backend API configured for the local postgres database.
## Starting The Server
@ -78,57 +67,24 @@ Now you're ready to start the servers. You'll need two shells open, One for the
```bash
# Terminal #1
make backend
task py
# Terminal #2
make frontend
task ui
```
=== "Windows"
``` powershell
# Terminal # 1
poetry run python mealie/db/init_db.py # Initialize the database
poetry run python mealie/app.py # start application
# Terminal # 2
Set-Directory frontend
yarn run dev
```
## Make File Reference
Run `make help` for reference. If you're on a system that doesn't support makefiles in most cases you can use the commands directly in your terminal by copy/pasting them from the Makefile.
```
docs 📄 Start Mkdocs Development Server
code-gen 🤖 Run Code-Gen Scripts
setup 🏗 Setup Development Instance
setup-model 🤖 Get the latest NLP CRF++ Model
clean-data ⚠️ Removes All Developer Data for a fresh server start
clean-pyc 🧹 Remove Python file artifacts
clean-test 🧹 Remove test and coverage artifacts
backend-clean 🧹 Remove all build, test, coverage and Python artifacts
backend-test 🧪 Run tests quickly with the default Python
backend-format 🧺 Format, Check and Flake8
backend-all 🧪 Runs all the backend checks and tests
backend-coverage ☂️ Check code coverage quickly with the default Python
backend 🎬 Start Mealie Backend Development Server
frontend 🎬 Start Mealie Frontend Development Server
frontend-build 🏗 Build Frontend in frontend/dist
frontend-generate 🏗 Generate Code for Frontend
frontend-lint 🧺 Run yarn lint
docker-dev 🐳 Build and Start Docker Development Stack (currently not functional, see #756, #1072)
docker-prod 🐳 Build and Start Docker Production Stack
```
## Internationalization
### Frontend
We use vue-i18n package for internationalization. Translations are stored in json format located in [frontend/lang/messages](https://github.com/mealie-recipes/mealie/tree/mealie-next/frontend/lang/messages).
### Backend
Translations are stored in json format located in [mealie/lang/messages](https://github.com/mealie-recipes/mealie/tree/mealie-next/mealie/lang/messages).
### Quick frontend localization with VS Code
[i18n Ally for VScode](https://marketplace.visualstudio.com/items?itemName=lokalise.i18n-ally) is helpful for generating new strings to translate using Code Actions. It also has a nice feature, which shows translations in-place when editing code.
A few settings must be tweaked to make the most of its features. Some settings are stored on project level, but most of them have to be set manually in your workspace or user settings.\

122
makefile
View File

@ -1,122 +0,0 @@
define BROWSER_PYSCRIPT
import os, webbrowser, sys
from urllib.request import pathname2url
webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1])))
endef
export BROWSER_PYSCRIPT
define PRINT_HELP_PYSCRIPT
import re, sys
for line in sys.stdin:
match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line)
if match:
target, help = match.groups()
print("%-20s %s" % (target, help))
endef
export PRINT_HELP_PYSCRIPT
BROWSER := python -c "$$BROWSER_PYSCRIPT"
help:
@python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)
.PHONY: docs
docs: ## 📄 Start Mkdocs Development Server
poetry run python dev/code-generation/gen_docs_api.py && \
cd docs && poetry run python -m mkdocs serve
# -----------------------------------------------------------------------------
# Backend makefile
.PHONY: setup
setup: ## 🏗 Setup Development Instance
poetry install --with main,dev && \
cd frontend && \
yarn install && \
cd ..
poetry run pre-commit install
cp -n template.env .env || true
@echo "🏗 Development Setup Complete "
@echo "❗️ Tips"
@echo " 1. run 'make backend' to start the API server"
@echo " 2. run 'make frontend' to start the Node Server"
@echo " 3. Testing the Natural Language Processor? Try 'make setup-model' to get the most recent model"
setup-model: ## 🤖 Get the latest NLP CRF++ Model
@echo Fetching NLP Model - CRF++ is still Required
curl -L0 https://github.com/mealie-recipes/nlp-model/releases/download/v1.0.0/model.crfmodel --output ./mealie/services/parser_services/crfpp/model.crfmodel
clean-data: ## ⚠️ Removes All Developer Data for a fresh server start
rm -r ./dev/data/recipes/
rm -r ./dev/data/users/
rm -f ./dev/data/mealie*.db
rm -f ./dev/data/mealie.log
rm -f ./dev/data/.secret
clean-pyc: ## 🧹 Remove Python file artifacts
find ./mealie -name '*.pyc' -exec rm -f {} +
find ./mealie -name '*.pyo' -exec rm -f {} +
find ./mealie -name '*~' -exec rm -f {} +
find ./mealie -name '__pycache__' -exec rm -fr {} +
clean-test: ## 🧹 Remove test and coverage artifacts
rm -fr .tox/
rm -f .coverage
rm -fr htmlcov/
rm -fr .pytest_cache
backend-clean: clean-pyc clean-test ## 🧹 Remove all build, test, coverage and Python artifacts
rm -fr .mypy_cache
backend-typecheck:
poetry run mypy mealie
backend-test: ## 🧪 Run tests quickly with the default Python
poetry run pytest
backend-format: ## 🧺 Format the codebase
poetry run black .
backend-lint: ## 🧹 Lint the codebase (Ruff)
poetry run ruff mealie
backend-all: backend-format backend-lint backend-typecheck backend-test ## 🧪 Runs all the backend checks and tests
backend-coverage: ## ☂️ Check code coverage quickly with the default Python
poetry run pytest
poetry run coverage report -m
poetry run coveragepy-lcov
poetry run coverage html
$(BROWSER) htmlcov/index.html
backend: ## 🎬 Start Mealie Backend Development Server
poetry run python mealie/db/init_db.py && \
poetry run python mealie/app.py
# -----------------------------------------------------------------------------
# Frontend makefile
.PHONY: frontend
frontend: ## 🎬 Start Mealie Frontend Development Server
cd frontend && yarn run dev
frontend-build: ## 🏗 Build Frontend in frontend/dist
cd frontend && yarn run build
frontend-lint: ## 🧺 Run yarn lint
cd frontend && yarn lint
# -----------------------------------------------------------------------------
# Docker makefile
prod: ## 🐳 Build and Start Docker Production Stack
cd docker && docker compose -f docker compose.yml -p mealie up --build
generate:
poetry run python dev/code-generation/main.py

View File

@ -45,6 +45,9 @@ text-unidecode = "^1.3"
rapidfuzz = "^3.2.0"
html2text = "^2020.1.16"
[tool.poetry.group.postgres.dependencies]
psycopg2-binary = { version = "^2.9.1" }
[tool.poetry.group.dev.dependencies]
black = "^23.7.0"
coverage = "^7.0"

View File

@ -1 +0,0 @@
3.8

View File

@ -1,54 +0,0 @@
# The Default Group Assigned to All Users
DEFAULT_GROUP=Home
# The Default Credentials for the Super User
DEFAULT_EMAIL=changeme@example.com
DEFAULT_PASSWORD=MyPassword
# Determines Production Mode, This will set the directory path to use for data storage
PRODUCTION=False
# API Port for Python Server
API_PORT=9000
# Exposes /docs and /redoc on the server
API_DOCS=True
# Sets the Database type to use. Note that in order for Postgres URI to be created, you must set DB_ENGINE=postgres
DB_ENGINE=sqlite # Optional: 'sqlite', 'postgres'
POSTGRES_USER=mealie
POSTGRES_PASSWORD=mealie
POSTGRES_SERVER=postgres
POSTGRES_PORT=5432
POSTGRES_DB=mealie
TOKEN_TIME=24
LANG=en-US
# NOT USED
# SMTP_HOST=""
# SMTP_PORT=""
# SMTP_FROM_NAME=""
# SMTP_AUTH_STRATEGY="" # Options: 'TLS', 'SSL', 'NONE'
# SMTP_FROM_EMAIL=""
# SMTP_USER=""
# SMTP_PASSWORD=""
# Configuration for authentication via an external LDAP server
LDAP_AUTH_ENABLED=False
# LDAP_SERVER_URL=""
# LDAP_TLS_INSECURE=False
# LDAP_TLS_CACERTFILE=
# LDAP_ENABLE_STARTTLS=False
# LDAP_BASE_DN=""
# LDAP_QUERY_BIND=""
# LDAP_QUERY_PASSWORD=""
# Optionally, filter by a particular user group
# (&(|({id_attribute}={input})({mail_attribute}={input}))(objectClass=person)(memberOf=cn=mealie_user,ou=groups,dc=example,dc=com))
# LDAP_USER_FILTER="(&(|({id_attribute}={input})({mail_attribute}={input}))(objectClass=person))"
# LDAP_ADMIN_FILTER=""
# LDAP_ID_ATTRIBUTE=uid
# LDAP_NAME_ATTRIBUTE=name
# LDAP_MAIL_ATTRIBUTE=mail