Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2

updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
day: "sunday"
groups:
all-github-actions:
patterns:
- "*"

- package-ecosystem: "pip" # See documentation for possible values
directory: "docs/" # Location of package manifests
directory: "./" # Location of package manifests
schedule:
interval: "weekly"
day: "sunday"
groups:
all-pip:
patterns:
- "*"
48 changes: 37 additions & 11 deletions .github/workflows/pip.yml → .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,54 @@
# Secret Variables required in GitHub secrets: TWINE_USERNAME, TWINE_PASSWORD / TWINE_USERNAME_TEST, TWINE_PASSWORD_TEST

name: build-pip-publish
name: build-python-package

on:
push:
branches: [ main ]
paths-ignore: [ "*.md" ]
branches: ["main"]
tags: ["v*"]
paths-ignore: ["*.md"]
pull_request:
branches: [ main ]
paths-ignore: [ "*.md" ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
branches: ["main"]
paths-ignore: ["*.md"]
workflow_dispatch: # Allows you to run this workflow manually from the Actions tab

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
build-pypi-package:
# The type of runner that the job will run on
job-ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: "3.13"
- run: pip install ruff && ruff check ./src

job-semgrep:
runs-on: ubuntu-latest
container:
image: semgrep/semgrep:latest
continue-on-error: true
if: (github.actor != 'dependabot[bot]')
steps:
- uses: actions/checkout@v6
- run: |
semgrep ci --verbose \
--config p/ci \
--config p/security-audit \
--config p/python \
--config p/javascript \
--config p/react \
--config p/owasp-top-ten

build-pypi-package:
runs-on: ubuntu-latest
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
# sudo python setup.py install clean --all
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: pip-install-test
run: |
Expand Down
7 changes: 6 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@
"ms-python.python",
"ms-python.vscode-pylance"
],
"unwantedRecommendations": []
"unwantedRecommendations": [
"ms-python.flake8",
"ms-python.pylint",
"ms-python.black-formatter",
"ms-python.autopep8"
]
}
18 changes: 13 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
{
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": "always"
},
"files.exclude": {
"**/.git": true,
"**/node_modules": true,
"**/__pycache__": true,
"**/*.pyc": true
},
"[python]": {
"editor.defaultFormatter": "ms-python.autopep8",
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit",
"source.fixAll.ruff": "explicit"
}
"source.organizeImports.ruff": "always",
"source.fixAll.ruff": "always"
},
"editor.formatOnSave": true
},
"[sql]": {
"editor.defaultFormatter": "dbcode.dbcode", // mtxr.sqltools, dbcode.dbcode, ReneSaarsoo.sql-formatter-vsc
"editor.formatOnSave": true
},
"ruff.enable": true,
"ruff.lint.enable": true,
"ruff.nativeServer": "on",
"ruff.lineLength": 128,
"ruff.configuration": {
"format": {
"quote-style": "double"
}
}
},
"markdown.validate.enabled": true
}
19 changes: 9 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
# Aloha!
# Aloha

## What is it?

`aloha` is a versatile Python utility package for building microservices.

[![License](https://img.shields.io/github/license/QPod/aloha)](https://github.com/QPod/aloha/blob/main/LICENSE)
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/QPod/aloha-python/pip.yml?branch=main)](https://github.com/QPod/aloha-python/actions)
[![Code Activity](https://img.shields.io/github/commit-activity/m/QPod/aloha)](https://github.com/QPod/aloha/pulse)
[![Recent Code Update](https://img.shields.io/github/last-commit/QPod/docker-images.svg)](https://github.com/QPod/aloha/stargazers)

[![License](https://img.shields.io/github/license/QPod/aloha-python)](https://github.com/QPod/aloha-python/blob/main/LICENSE)
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/QPod/aloha-python/build.yml?branch=main)](https://github.com/QPod/aloha-python/actions)
[![Join the Gitter Chat](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/QPod/)
[![PyPI version](https://img.shields.io/pypi/v/aloha)](https://pypi.python.org/pypi/aloha/)
[![PyPI Downloads](https://img.shields.io/pypi/dm/aloha)](https://pepy.tech/badge/aloha/)

---
[![Code Activity](https://img.shields.io/github/commit-activity/m/QPod/aloha-python)](https://github.com/QPod/aloha-python/pulse)
[![Recent Code Update](https://img.shields.io/github/last-commit/QPod/docker-images.svg)](https://github.com/QPod/aloha-python/stargazers)

Please generously STAR★ our project or donate to us!
[![GitHub Starts](https://img.shields.io/github/stars/QPod/aloha.svg?label=Stars&style=social)](https://github.com/QPod/aloha/stargazers)
[![GitHub Starts](https://img.shields.io/github/stars/QPod/aloha-python.svg?label=Stars&style=social)](https://github.com/QPod/aloha-python/stargazers)
[![Donate-PayPal](https://img.shields.io/badge/Donate-PayPal-blue.svg)](https://paypal.me/haobibo)
[![Donate-AliPay](https://img.shields.io/badge/Donate-Alipay-blue.svg)](https://raw.githubusercontent.com/wiki/haobibo/resources/img/Donate-AliPay.png)
[![Donate-WeChat](https://img.shields.io/badge/Donate-WeChat-green.svg)](https://raw.githubusercontent.com/wiki/haobibo/resources/img/Donate-WeChat.png)
Expand All @@ -32,7 +30,8 @@ Refer to[📚 Document & 中文文档](https://aloha-python.readthedocs.io/) for
pip install aloha[all]
```

And then:
And then:

```python
from aloha.logger import LOG
from aloha.settings import SETTINGS as S
Expand Down
179 changes: 179 additions & 0 deletions app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
# App Demo

Using `aloha` to develop your project - a boilerplate/template project.

## Overview

This project provides a containerized development environment using Docker and Docker Compose. It sets up a complete development workspace with all necessary dependencies pre-installed, allowing you to focus on writing code rather than configuring your environment.

### Key Components

- **Docker**: Containerization platform that packages applications with all their dependencies
- **Docker Compose**: Tool for defining and running multi-container Docker applications
- **Development Container**: A pre-configured environment with Python, Node.js, and database clients

## How to quickly setup and start DEV environment

### Prerequisites

Before getting started, ensure you have the following installed:

- Docker Engine
- Docker Compose
- Git (for cloning the repository)

You can verify Docker installation by running:

```bash
docker --version
docker-compose --version
```

### Step 1: Launch the Development Environment

Run this command in your terminal:

```bash
./tool/cicd/run-dev.sh up
```

**What happens when you run this command:**

1. **Port Availability Check**: The script first verifies that the required ports are not already in use on your system. The ports are dynamically assigned based on your user ID (UID) to avoid conflicts with other developers.

2. **Docker Image Build**: If the Docker image doesn't exist yet, Docker Compose will build it using:
- `tool/cicd/docker-compose.app-demo.DEV.yml`: Defines the container configuration
- `tool/dev-demo.Dockerfile`: Specifies how to build the Docker image

The build process includes:
- Installing Node.js package manager (pnpm)
- Setting up Python with JupyterLab
- Installing project dependencies from `app/requirements.txt`
- Adding PostgreSQL database client tools

3. **Container Start**: Docker Compose starts the container with the following features:
- **Volume Mounts**: Your local code directories are mounted into the container, enabling live development (changes on your host are immediately visible in the container):
- `doc/` → `/root/doc`
- `notebook/` → `/root/notebook`
- `src/` → `/root/src`
- `app/` → `/root/app`
- **Port Forwarding**: Exposes ports for your application and web interface
- **Persistent Process**: The container runs `tail -f /dev/null` to stay active

### Step 2: Enter the Development Container

Once the environment is running, execute:

```bash
./tool/cicd/run-dev.sh enter
```

**What this command does:**

- Uses `docker exec -it` to create an interactive terminal session
- Attaches you to the running container with a bash shell
- You'll be logged in as the root user inside the container
- Your working directory will be `/root`

**What you can do inside the container:**

- Run Python scripts and applications
- Use JupyterLab for interactive development
- Install additional packages with pip or npm
- Access the PostgreSQL database using the client tools
- Edit files (changes will be reflected on your host machine)

### Step 3: Manage the Environment

The `run-dev.sh` script provides several commands to manage your development environment:

| Command | Description |
| -------------------------------- | ------------------------------------------- |
| `./tool/cicd/run-dev.sh up` | Start or create the development environment |
| `./tool/cicd/run-dev.sh restart` | Restart the running container |
| `./tool/cicd/run-dev.sh logs` | View and follow container logs |
| `./tool/cicd/run-dev.sh enter` | Access the container's bash shell |
| `./tool/cicd/run-dev.sh down` | Stop and remove the container |

### Understanding the Port Assignment

The script dynamically assigns ports to avoid conflicts:

- **Base App Port**: 30000 (as specified in the `run-dev.sh`)+ your UID
- **Base Web Port**: 33000 (as specified in the `run-dev.sh`)+ your UID

Your specific ports will be displayed when you run any `run-dev.sh` command:

```
----------------------------------------
User: yourusername (UID: 1000)
Project Name: dev-app-demo-yourusername
Container: dev-app-demo-yourusername
App Port Expose: 31000
Web Port Expose: 34000
Action: up
Compose: /path/to/docker-compose.app-demo.DEV.yml
----------------------------------------
```

### Tearing Down the Environment

When you're done working, you can stop and remove the container:

```bash
./tool/cicd/run-dev.sh down
```

**Note:** This command only removes the container, not the Docker image. If you want to reclaim disk space by removing the image as well, run:

```bash
docker rmi $(docker images | grep dev-app-demo | awk '{print $3}')
```

## Project Structure

```
aloha-python/
├── app/ # Application code
│ ├── main.py # Main application entry point
│ ├── requirements.txt # Python dependencies
│ └── app_common/ # Common application utilities
├── src/ # Source code for the aloha library
├── doc/ # Documentation files
├── notebook/ # Jupyter notebooks
└── tool/ # Development tools
├── cicd/ # CI/CD scripts and configs
│ ├── run-dev.sh # Main development environment script
│ └── docker-compose.app-demo.DEV.yml
├── dev-demo.Dockerfile
└── app-demo.Dockerfile
```

## Troubleshooting

### "Port is already in use" error

If you see this error, another process is using the assigned ports. You can:

1. Identify and stop the conflicting process
2. Work with a system administrator to free up the ports

### Container won't start

- Check Docker logs: `./tool/cicd/run-dev.sh logs`
- Ensure Docker service is running: `systemctl status docker` (Linux) or check Docker Desktop (Windows/macOS)

### Changes not reflecting

- Verify your files are in the mounted directories
- Check that you're editing files on your host machine (not just inside the container)
- Restart any running services inside the container if needed

## Next Steps

Once inside the container, you can:

1. Explore the `app/` directory to understand the application structure
2. Check out the Jupyter notebooks in the `notebook/` directory
3. Review the documentation in the `doc/` directory
4. Start developing your application!
File renamed without changes.
File renamed without changes.
18 changes: 10 additions & 8 deletions demo/app_common/debug.py → app/app_common/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,25 @@ def main():
"app_common.api.api_multipart",
]

if 'service' not in SETTINGS.config:
SETTINGS.config['service'] = {}
if "service" not in SETTINGS.config:
SETTINGS.config["service"] = {}

# load the service modules from SETTINGS.config['service']['modules']
SETTINGS.config['service'].update({
'modules': modules_to_load,
'debug': True,
})
SETTINGS.config["service"].update(
{
"modules": modules_to_load,
"debug": True,
}
)

# Use self defined 404 handler
SETTINGS.config['default_handler_class'] = DefaultHandler404
SETTINGS.config["default_handler_class"] = DefaultHandler404

app = Application()

# The event loop starts after start.
app.start()


if __name__ == '__main__':
if __name__ == "__main__":
main()
File renamed without changes.
Loading