Skip to content

Commit 11306ca

Browse files
authored
MPT-17674: propagate-changes-from-template (#39)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> Closes [MPT-17674](https://softwareone.atlassian.net/browse/MPT-17674) - .editorconfig: enforce tab indentation for Makefile and *.mk files - .pre-commit-config.yaml: normalize package names to lowercase and reorder flake8-related entries - Replace legacy Makefile with a modular Makefile system: - New top-level Makefile dynamically includes make/*.mk fragments, auto-generates .PHONY targets, adds a require helper macro, and sets default goal to help - Added make/common.mk: Docker Compose-based development workflow and targets (build, test, check, check-all, format, run, bash, shell) and uv dependency management (uv-add, uv-add-dev, uv-upgrade) - Added make/external_tools.mk: review target (CodeRabbit) - Added make/repo.mk: placeholder for repo-specific targets - Removed old legacy makefile (full deletion) and migrated functionality into the new modular layout - Dockerfile refactor: - Replace VIRTUAL_ENV usage with UV_PROJECT_ENVIRONMENT and preserve PATH - Adjust build stage (COPY . . and uv sync --no-dev), add dev stage (uv sync --dev), and add prod stage that removes tests, creates appuser, sets UV_CACHE_DIR and switches to non-root user - README.md: reorganized into a setup-first guide with explicit Makefile structure, setup workflow, developer utilities, and configuration section (env vars) - docs/PROJECT_DESCRIPTION.md: add pre-commit snippets showing how to check migrations - pyproject.toml: minor Ruff config cleanup (remove docstring-code-format setting) <!-- end of auto-generated comment: release notes by coderabbit.ai --> [MPT-17674]: https://softwareone.atlassian.net/browse/MPT-17674?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
2 parents 5dea70b + b640887 commit 11306ca

File tree

13 files changed

+166
-83
lines changed

13 files changed

+166
-83
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ indent_size = 2
1212

1313
[*.py]
1414
indent_size = 4
15+
16+
[{Makefile,*.mk}]
17+
indent_style = tab

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ cython_debug/
167167
.ruff_cache
168168
.idea
169169

170-
# Specific project gitignore
170+
# Makefile
171+
make/local.mk
172+
173+
# mpt-tool
171174
migrations/
172175
.migrations-state.json
173-
settings.py

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ repos:
2828
- id: flake8
2929
additional_dependencies:
3030
[
31-
Flake8-pyproject==1.2.*,
32-
Flake8-AAA==0.17.*,
31+
flake8-aaa==0.17.*,
32+
flake8-pyproject==1.2.*,
3333
wemake-python-styleguide==1.5.*,
3434
]
3535

Dockerfile

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,33 @@ FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim AS base
22

33
WORKDIR /mpt_tool
44

5-
COPY . ./
6-
75
RUN uv venv /opt/venv
86

9-
ENV VIRTUAL_ENV=/opt/venv
7+
ENV UV_PROJECT_ENVIRONMENT=/opt/venv
108
ENV PATH=/opt/venv/bin:$PATH
119

1210
FROM base AS build
1311

14-
RUN uv sync --frozen --no-cache --all-groups --active
12+
COPY . .
13+
14+
RUN uv sync --frozen --no-cache --no-dev
1515

1616
FROM build AS dev
1717

18+
RUN uv sync --frozen --no-cache --dev
19+
20+
CMD ["bash"]
21+
22+
FROM build AS prod
23+
24+
RUN rm -rf tests/
25+
26+
RUN groupadd -r appuser && useradd -r -g appuser -m -d /home/appuser appuser && \
27+
mkdir -p /home/appuser/.cache/uv && \
28+
chown -R appuser:appuser /mpt_tool /opt/venv /home/appuser
29+
30+
ENV UV_CACHE_DIR=/home/appuser/.cache/uv
31+
32+
USER appuser
33+
1834
CMD ["bash"]

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
MK_FILES := $(sort $(wildcard make/*.mk))
2+
-include $(MK_FILES)
3+
4+
.DEFAULT_GOAL := help
5+
.PHONY: $(shell awk -F: '/^[a-zA-Z0-9_-]+:([^=]|$$)/ {print $$1}' $(MAKEFILE_LIST))
6+
7+
require = $(if $(value $(1)),,$(error Missing required variable: $(1). Example: make $(MAKECMDGOALS) $(1)=<value>))
8+
9+
help: ## Show available commands
10+
@echo "Available commands:"
11+
@awk 'BEGIN {FS = ":.*##"} /^[a-zA-Z0-9_-]+:.*##/ {printf " make %-22s %s\n", $$1, $$2}' $(MAKEFILE_LIST)

README.md

Lines changed: 67 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,58 +19,80 @@ to manage both schema and data migrations across multiple backends, ensuring con
1919
- Docker and Docker Compose plugin (`docker compose` CLI)
2020
- `make`
2121
- [CodeRabbit CLI](https://www.coderabbit.ai/cli) (optional. Used for running review check locally)
22-
- Copy .env.sample to .env
22+
2323

2424
### Make targets overview
2525

26-
Common development workflows are wrapped in the `makefile`:
26+
Common development workflows are wrapped in the `Makefile`. Run `make help` to see the list of available commands.
27+
28+
### How the Makefile works
29+
30+
The project uses a modular Makefile structure that organizes commands into logical groups:
31+
32+
- **Main Makefile** (`Makefile`): Entry point that automatically includes all `.mk` files from the `make/` directory
33+
- **Modular includes** (`make/*.mk`): Commands are organized by category:
34+
- `common.mk` - Core development commands (build, test, format, etc.)
35+
- `repo.mk` - Repository management and dependency commands
36+
- `migrations.mk` - Database migration commands (Only available in extension repositories)
37+
- `external_tools.mk` - Integration with external tools
38+
39+
40+
You can extend the Makefile with your own custom commands creating a `local.mk` file inside make folder. This file is
41+
automatically ignored by git, so your personal commands won't affect other developers or appear in version control.
42+
2743

28-
- `make help` – list available commands
29-
- `make bash` – start the app container and open a bash shell
30-
- `make build` – build the application image for development
31-
- `make check` – run code quality checks (ruff, flake8, lockfile check)
32-
- `make check-all` – run checks and tests
33-
- `make format` – apply formatting and import fixes
34-
- `make down` – stop and remove containers
35-
- `make review` – check the code in the cli by running CodeRabbit
36-
- `make run` – run the CLI tool
37-
- `make test` – run the test suite with pytest
44+
### Setup
3845

39-
## Running CLI commands
46+
Follow these steps to set up the development environment:
47+
48+
#### 1. Clone the repository
4049

41-
Run the CLI tool:
4250
```bash
43-
make run
51+
git clone <repository-url>
52+
```
53+
```bash
54+
cd mpt-tool
55+
```
56+
57+
#### 2. Create environment configuration
58+
59+
Copy the sample environment file and update it with your values:
60+
61+
```bash
62+
cp .env.sample .env
4463
```
4564

46-
## Running tests
65+
Edit the `.env` file with your actual configuration values. See the [Configuration](#configuration) section for details on available variables.
4766

48-
Tests run inside Docker using the dev configuration.
67+
#### 3. Build the Docker images
4968

50-
Run the full test suite:
69+
Build the development environment:
5170

5271
```bash
53-
make test
72+
make build
5473
```
5574

56-
Pass additional arguments to pytest using the `args` variable:
75+
This will create the Docker images with all required dependencies and the virtualenv.
76+
77+
#### 4. Verify the setup
78+
79+
Run the test suite to ensure everything is configured correctly:
5780

5881
```bash
59-
make test args="-k test_cli -vv"
60-
make test args="tests/test_cli.py"
82+
make test
6183
```
6284

63-
## Pre-commit
85+
You're now ready to start developing! See [Running the cli](#running-the-cli) for next steps.
86+
6487

65-
Checking migrations with pre-commit:
88+
## Running the cli
6689

67-
Add this to your .pre-commit-config.yaml
90+
Before running, ensure your `.env` file is populated.
6891

69-
```yaml
70-
- repo: https://github.com/softwareone-platform/mpt-tool
71-
rev: '' # Use the sha / tag you want to point at
72-
hooks:
73-
- id: check-migrations
92+
Start the cli:
93+
94+
```bash
95+
make run
7496
```
7597

7698
## Developer utilities
@@ -84,3 +106,18 @@ make check-all # run checks and tests
84106
make format # auto-format code and imports
85107
make review # check the code in the cli by running CodeRabbit
86108
```
109+
110+
## Configuration
111+
112+
The following environment variables are typically set in `.env`. Docker Compose reads them when using the Make targets described above.
113+
114+
### Application
115+
116+
| Environment Variable | Default | Example | Description |
117+
|----------------------------------------|-------------------------|-------------------------------------------|-------------------------------------------------------------------------------------------|
118+
| `MPT_API_BASE_URL` | `http://localhost:8000` | `https://portal.softwareone.com/mpt` | SoftwareONE Marketplace API URL |
119+
| `MPT_API_TOKEN` | - | eyJhbGciOiJSUzI1N... | SoftwareONE Marketplace API Token |
120+
| `MPT_TOOL_STORAGE_TYPE` | `local` | `airtable` | Storage type for MPT tools (local or airtable) |
121+
| `MPT_TOOL_STORAGE_AIRTABLE_API_KEY` | - | patXXXXXXXXXXXXXX | Airtable API key for MPT tool storage (required when storage type is airtable) |
122+
| `MPT_TOOL_STORAGE_AIRTABLE_BASE_ID` | - | appXXXXXXXXXXXXXX | Airtable base ID for MPT tool storage (required when storage type is airtable) |
123+
| `MPT_TOOL_STORAGE_AIRTABLE_TABLE_NAME` | - | MigrationTracking | Airtable table name for MPT tool storage (required when storage type is airtable) |

docs/PROJECT_DESCRIPTION.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,18 @@ Run `mpt-service-cli --help` to see all available commands and params:
340340
- Create a new migration with the updated logic
341341
- Never modify an already-applied migration in production
342342
343+
## Pre-commit
344+
345+
Checking migrations with pre-commit:
346+
347+
Add this to your .pre-commit-config.yaml
348+
349+
```yaml
350+
- repo: https://github.com/softwareone-platform/mpt-tool
351+
rev: '' # Use the sha / tag you want to point at
352+
hooks:
353+
- id: check-migrations
354+
```
343355
344356
## Development
345357

make/common.mk

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
DC = docker compose -f compose.yaml
2+
RUN = $(DC) run --rm app
3+
RUN_IT = $(DC) run --rm -it app
4+
5+
bash: ## Open a bash shell
6+
$(RUN_IT) bash
7+
8+
build: ## Build images
9+
$(DC) build
10+
11+
check: ## Check code quality with ruff
12+
$(RUN) bash -c "ruff format --check . && ruff check . && flake8 . && uv lock --check"
13+
14+
check-all: check test ## Run checks and tests
15+
16+
down: ## Stop and remove containers
17+
$(DC) down
18+
19+
format: ## Format code
20+
$(RUN) bash -c "ruff check --select I --fix . && ruff format ."
21+
22+
run: ## Run service
23+
$(DC) up
24+
25+
shell: ## Open Django shell
26+
$(RUN_IT) bash -c "swoext shell"
27+
28+
test: ## Run test
29+
$(RUN) pytest $(if $(args),$(args),.)
30+
31+
uv-add: ## Add a production dependency (pkg=<package_name>)
32+
$(call require,pkg)
33+
$(RUN) bash -c "uv add $(pkg)"
34+
$(MAKE) build
35+
36+
uv-add-dev: ## Add a dev dependency (pkg=<package_name>)
37+
$(call require,pkg)
38+
$(RUN) bash -c "uv add --dev $(pkg)"
39+
$(MAKE) build
40+
41+
uv-upgrade: ## Upgrade all packages or a specific package (use pkg="package_name" to target one)
42+
$(RUN) bash -c "uv lock $(if $(pkg),--upgrade-package $(pkg),--upgrade) && uv sync"
43+
$(MAKE) build

make/external_tools.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
review: ## Run CodeRabbit code review in interactive mode. Pass args=<options> to override or include more options
2+
coderabbit review $(args)

make/repo.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
## Add repo-specific targets here. Do not modify the shared *.mk files.

0 commit comments

Comments
 (0)