Skip to content

Commit

Permalink
chore: rewrite makefile in taskfile (#3035)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
hay-kot committed Jan 27, 2024
1 parent 4d49e30 commit 0800a8d
Show file tree
Hide file tree
Showing 13 changed files with 243 additions and 263 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
12 changes: 9 additions & 3 deletions .github/workflows/partial-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -101,4 +107,4 @@ jobs:
LDAP_NAME_ATTRIBUTE: cn
LDAP_MAIL_ATTRIBUTE: mail
run: |
make backend-test
task py:test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,4 @@ lcov.info
dev/code-generation/openapi.json

.run/
.task/*
23 changes: 5 additions & 18 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand All @@ -29,7 +16,7 @@
},
{
"label": "Dev: Start Backend",
"command": "make backend",
"command": "task py",
"type": "shell",
"presentation": {
"reveal": "always",
Expand All @@ -49,7 +36,7 @@
},
{
"label": "Dev: Start Frontend",
"command": "make frontend",
"command": "task ui",
"type": "shell",
"presentation": {
"reveal": "always",
Expand All @@ -59,7 +46,7 @@
},
{
"label": "Dev: Start Docs Server",
"command": "make docs",
"command": "task docs",
"type": "shell",
"presentation": {
"reveal": "always",
Expand All @@ -69,7 +56,7 @@
},
{
"label": "Run python tests",
"command": "make test",
"command": "task py:test",
"type": "shell",
"presentation": {
"reveal": "always"
Expand Down
183 changes: 183 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions docker/docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Loading

0 comments on commit 0800a8d

Please sign in to comment.