-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implements rosemary test command
- Loading branch information
1 parent
4850bc9
commit 3ccdec4
Showing
7 changed files
with
94 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,35 @@ | ||
# Use an official Python runtime as a parent image | ||
# Use an official Python runtime as a parent image, Alpine version for a lighter footprint | ||
FROM python:3.11-alpine | ||
|
||
# Install the MySQL client to be able to use it in the standby script. | ||
RUN apk add --no-cache mysql-client | ||
# Install MySQL client and temporary build dependencies | ||
RUN apk add --no-cache mysql-client \ | ||
&& apk add --no-cache --virtual .build-deps gcc musl-dev python3-dev libffi-dev openssl-dev | ||
|
||
# Set the working directory in the container to /app | ||
WORKDIR /app | ||
|
||
# Copy the contents of the local app/ directory to the /app directory in the container | ||
COPY app/ ./app | ||
|
||
# Copy requirements.txt at the /app working directory | ||
# Copy requirements.txt into the working directory /app | ||
COPY requirements.txt . | ||
|
||
# Copy the wait-for-db.sh script and set execution permissions | ||
COPY --chmod=+x scripts/wait-for-db.sh ./scripts/ | ||
|
||
# Install any needed packages specified in requirements.txt | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
# Update pip | ||
RUN pip install --no-cache-dir --upgrade pip | ||
# Install any needed packages specified in requirements.txt and upgrade pip | ||
RUN pip install --no-cache-dir -r requirements.txt \ | ||
&& pip install --no-cache-dir --upgrade pip \ | ||
&& apk del .build-deps | ||
|
||
# Copy the migration scripts to the /app directory in the container | ||
COPY migrations/ ./migrations | ||
|
||
# Expose port 5000 | ||
EXPOSE 5000 | ||
|
||
# Set environment variables for production | ||
ENV FLASK_ENV=production | ||
|
||
# Run the database migrations and then start the application with Gunicorn | ||
CMD sh ./scripts/wait-for-db.sh && flask db upgrade && gunicorn --bind 0.0.0.0:5000 app:app --log-level debug --timeout 3600 | ||
CMD sh ./scripts/wait-for-db.sh && flask db upgrade && gunicorn --bind 0.0.0.0:5000 app:app --log-level info --timeout 3600 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,32 @@ | ||
# rosemary/cli.py | ||
|
||
import click | ||
from rosemary.commands.update import update | ||
from rosemary.commands.info import info | ||
from rosemary.commands.make_module import make_module | ||
from rosemary.commands.env import env | ||
from rosemary.commands.test import test | ||
|
||
|
||
class RosemaryCLI(click.Group): | ||
def get_command(self, ctx, cmd_name): | ||
rv = super().get_command(ctx, cmd_name) | ||
if rv is not None: | ||
return rv | ||
click.echo(f"No such command '{cmd_name}'.") | ||
click.echo("Try 'rosemary --help' for a list of available commands.") | ||
return None | ||
|
||
|
||
@click.group() | ||
@click.group(cls=RosemaryCLI) | ||
def cli(): | ||
"""A CLI tool to help with project management.""" | ||
pass | ||
|
||
|
||
cli.add_command(update) | ||
cli.add_command(info) | ||
cli.add_command(make_module) | ||
cli.add_command(env) | ||
cli.add_command(test) | ||
|
||
if __name__ == '__main__': | ||
cli() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import click | ||
import subprocess | ||
import os | ||
|
||
|
||
@click.command('test', help="Runs pytest on the blueprints directory or a specific module.") | ||
@click.argument('module_name', required=False) | ||
def test(module_name): | ||
base_path = 'app/blueprints' | ||
test_path = base_path | ||
|
||
if module_name: | ||
test_path = os.path.join(base_path, module_name) | ||
if not os.path.exists(test_path): | ||
click.echo(f"Module '{module_name}' does not exist.") | ||
return | ||
click.echo(f"Running tests for the '{module_name}' module...") | ||
else: | ||
click.echo("Running tests for all modules...") | ||
|
||
try: | ||
subprocess.run(['pytest', '-v', test_path], check=True) | ||
except subprocess.CalledProcessError as e: | ||
click.echo(f"Error running tests: {e}") |