Skip to content

Commit 0c9dc95

Browse files
committed
Initial commit
0 parents  commit 0c9dc95

File tree

14 files changed

+402
-0
lines changed

14 files changed

+402
-0
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: bug
6+
assignees: ''
7+
---
8+
9+
**Which OS are you using?**
10+
- OS: [e.g. Linux or Windows]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
name: Feature request
3+
about: Any feature you want
4+
title: ''
5+
labels: enhancement
6+
assignees: ''
7+
---
8+
9+
**Describe feature you want**
10+

.github/pull_request_template.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Related issues / PRs. Summarize issues.
2+
- #
3+
4+
## Summarize Changes
5+
1.

.github/workflows/ci.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: CI
2+
3+
on:
4+
workflow_dispatch:
5+
6+
push:
7+
branches:
8+
- master
9+
pull_request:
10+
branches:
11+
- master
12+
13+
jobs:
14+
test:
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
# Update python version matrix compatible with your project
19+
python: ["3.10", "3.11", "3.12"]
20+
21+
env:
22+
# Use API Key from GA's environment variables for testing. You can remove this line if you don't need it.
23+
SERVICE_API_KEY: ${{ secrets.SERVICE_API_KEY }}
24+
25+
steps:
26+
# This will remove unnecessary files to free up space. This has done because some package needs more space to install. e.g.) torch
27+
- name: Clean up space for action
28+
run: rm -rf /opt/hostedtoolcache
29+
30+
- uses: actions/checkout@v4
31+
- name: Setup Python
32+
uses: actions/setup-python@v5
33+
with:
34+
python-version: ${{ matrix.python }}
35+
36+
# Install project dependencies with pytest and run tests
37+
- name: Install dependencies
38+
run: pip install -r requirements.txt pytest
39+
40+
41+
# `-rs` flag is used to debug for the test failure
42+
- name: Run test
43+
run: python -m pytest -rs tests
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# This workflow is an automated CD to the DockerHub.
2+
# The auto-trigger is disabled by default, you can edit the trigger in the `on` section if you want.
3+
4+
name: Publish to Docker Hub
5+
6+
on:
7+
workflow_dispatch:
8+
9+
push:
10+
branches:
11+
# - master
12+
13+
jobs:
14+
dockerhub-publish:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Clean up space for action
19+
run: rm -rf /opt/hostedtoolcache
20+
21+
- name: Log in to Docker Hub
22+
uses: docker/login-action@v2
23+
with:
24+
# Register your DockerHub username and password in the repository's GA secrets.
25+
username: ${{ secrets.DOCKER_USERNAME }}
26+
password: ${{ secrets.DOCKER_PASSWORD }}
27+
28+
- name: Checkout repository
29+
uses: actions/checkout@v3
30+
31+
- name: Set up Docker Buildx
32+
uses: docker/setup-buildx-action@v3
33+
34+
- name: Set up QEMU
35+
uses: docker/setup-qemu-action@v3
36+
37+
- name: Build and push Docker image
38+
uses: docker/build-push-action@v5
39+
with:
40+
context: .
41+
file: ./Dockerfile
42+
push: true
43+
# Update with your image name
44+
tags: ${{ secrets.DOCKER_USERNAME }}/image-name:latest
45+
46+
- name: Log out of Docker Hub
47+
run: docker logout
48+

.github/workflows/publish-pypi.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# This workflow is an automated CD to the DockerHub. The trigger is disabled by default, you can edit the trigger in the `on` section if you want.
2+
3+
4+
name: Publish to PyPI
5+
6+
on:
7+
# Uncomment the following line to trigger the workflow when you make "release" in the repository
8+
# release:
9+
# types: [created]
10+
11+
12+
jobs:
13+
pypi-publish:
14+
name: Upload release to PyPI
15+
runs-on: ubuntu-latest
16+
environment:
17+
name: pypi
18+
# Update URL with your package name
19+
url: https://pypi.org/p/package-name
20+
permissions:
21+
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
22+
23+
steps:
24+
- uses: actions/checkout@v4
25+
- name: Set up Python 3.12
26+
uses: actions/setup-python@v5
27+
with:
28+
python-version: 3.12
29+
30+
- name: Install pypa/build
31+
run: >-
32+
python -m
33+
pip install
34+
build
35+
--user
36+
37+
- name: Build a binary wheel and a source tarball
38+
run: >-
39+
python -m
40+
build
41+
--sdist
42+
--wheel
43+
--outdir dist/
44+
.
45+
46+
- name: Publish package distributions to PyPI
47+
if: startsWith(github.ref, 'refs/tags')
48+
uses: pypa/gh-action-pypi-publish@release/v1

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
**/.idea/
2+
**/__pycache__/
3+
**/.pytest_cache/
4+
**/venv/
5+
**/.env

README.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Python Project Template
2+
This is basic python project template with basic CI/CD GA workflow & GH issue & PR template. Anyone can use this template to start a new python project.
3+
4+
## Directory Structure
5+
You can remove the `(optional)` directories if you don't need them. (e.g. `docker/`, `setup.py`, etc.)
6+
```
7+
python-project-template/
8+
├── .github/ # GA workflows & PR, Issue templates
9+
├── docker/ # (optional) Dockerfile & docker-compose files related to the project.
10+
├── tests/ # Test codes with pytest
11+
├── .gitignore # gitignore file
12+
├── README.md # README file
13+
└── requirements.txt # Project dependencies
14+
```
15+
16+
## Github Actions
17+
1. [`ci.yml`](https://github.com/jhj0517/python-project-template/tree/master/.github/workflows/ci.yml)
18+
Basic CI workflow with pytest. It runs tests in the [`tests`](https://github.com/jhj0517/python-project-template/tree/master/tests) directory, with master branch commit & PR triggers by default.
19+
2. [`publish-dockerhub.yml`](https://github.com/jhj0517/python-project-template/tree/master/.github/workflows/publish-dockerhub.yml)
20+
Basic CD workflow for DockerHub. This workflow is optional, only needed when you want to publish the docker image to the dockerhub. You can remove this workflow if you don't need it.<br>
21+
It will build the docker image with [`docker/Dockerfile`](https://github.com/jhj0517/python-project-template/tree/master/docker/Dockerfile) and [`docker/docker-compose.yaml`](https://github.com/jhj0517/python-project-template/tree/master/docker/docker-compose.yaml) for the project and publish it to the dockerhub with the tag `latest`.<br>
22+
The auto-trigger for this workflow is disabled by default. You can edit the workflow to enable it.<br>
23+
Before using the workflow, you need to set the `DOCKERHUB_USERNAME` & `DOCKERHUB_TOKEN` in the repository secrets.
24+
25+
[image](URL)
26+
27+
And make sure to edit the `image-name` in the workflow.
28+
29+
[code-url](URL)
30+
31+
3. [`publish-pypi.yml`](https://github.com/jhj0517/python-project-template/tree/master/.github/workflows/publish-dockerhub.yml)
32+
Basic CD workflow for pypi package. This is the workflow that only used in case when your project is a python package that will be published in the pypi. You can remove this workflow if you don't need it.<br>
33+
It will build it and publish it to pypi whenever you make a new "release" in the repository.<br>
34+
The auto-trigger for this workflow is disabled by default. You can edit the workflow to enable it.<br>
35+
Before using the workflow, edit package name to yours in the workflow.
36+
37+
[code-url](URL)
38+
39+
## Issue & PR Template
40+
There are some basic templates for the issue & PR. You can edit them or add more to fit your project's needs.
41+
42+
- Issue Templates:
43+
1. [`bug_report.md`](https://github.com/jhj0517/python-project-template/tree/master/.github/ISSUE_TEMPLATE/bug_report.md) : Basic bug report template
44+
2. [`feature_request.md`](https://github.com/jhj0517/python-project-template/tree/master/.github/ISSUE_TEMPLATE/feature_request.md) : Feature request template
45+
46+
- PR Template: [`pull_request_template.md`](https://github.com/jhj0517/python-project-template/tree/master/.github/pull_request_template.md)
47+
48+
49+
## Docker
50+
51+
The [`docker/`](https://github.com/jhj0517/python-project-template/tree/master/docker) directory and [`publish-dockerhub.yml`](https://github.com/jhj0517/python-project-template/tree/master/.github/workflows/publish-dockerhub.yml) are associated with building the docker image and publishing to dockerhub. You can remove them if you don't need them.<br>
52+
Before building image, make sure to edit the variable in the [`docker/Dockerfile`](https://github.com/jhj0517/python-project-template/tree/master/docker/Dockerfile):
53+
54+
[code-url](URL)
55+
56+
And in [`docker/docker-compose.yaml`](https://github.com/jhj0517/python-project-template/tree/master/docker/docker-compose.yaml) as well:
57+
58+
[code-url](URL)
59+
60+
The image is built and published automatically by the action, but you can also manually build and run the image with the following commands.
61+
62+
1. git clone this repository
63+
```bash
64+
git clone https://github.com/your-name/your-project-name.git
65+
```
66+
2. Build the image
67+
```bash
68+
docker compose -f docker/docker-compose.yaml build
69+
```
70+
3. Run the container
71+
```bash
72+
docker compose -f docker/docker-compose.yaml up
73+
```
74+
75+
## PyPI
76+
The [`setup.py`](https://github.com/jhj0517/python-project-template/tree/master/setup.py), [`pyproject.toml`](https://github.com/jhj0517/python-project-template/tree/master/setup.py) and [`publish-pypi.yml`](https://github.com/jhj0517/python-project-template/tree/master/.github/workflows/publish-dockerhub.yml) are associated with building the package and publishing to PyPI. You can remove them if you don't need them.<br>
77+
Make sure to edit dependencies & variables in the [`pyproject.toml`](https://github.com/jhj0517/python-project-template/tree/master/setup.py) as your project's needs.
78+
79+
80+
## How to start
81+
Click "Use this template" and "Create a new repository". Then git clone it and you can start your own project.
82+
83+
[image-url](URL)
84+
85+
86+

docker/Dockerfile

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# It has two separate stages, with Builder Stage & Runtime Stage, because it's helpful to reduce the image size.
2+
3+
# Edit `PROJECT_NAME` with your project name.
4+
ARG PROJECT_NAME=your-project-name
5+
6+
7+
# 1. Builder Stage
8+
FROM debian:bookworm-slim AS builder
9+
10+
ARG PROJECT_NAME
11+
12+
RUN apt-get update && \
13+
apt-get install -y curl python3 python3-pip python3-venv && \
14+
rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/* && \
15+
mkdir -p /${PROJECT_NAME}
16+
17+
WORKDIR /${PROJECT_NAME}
18+
19+
COPY requirements.txt .
20+
21+
RUN python3 -m venv venv && \
22+
. venv/bin/activate && \
23+
pip install --no-cache-dir -r requirements.txt
24+
25+
26+
# 2. Runtime Stage
27+
FROM debian:bookworm-slim AS runtime
28+
29+
ARG PROJECT_NAME
30+
31+
RUN apt-get update && \
32+
apt-get install -y curl python3 && \
33+
rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*
34+
35+
WORKDIR /${PROJECT_NAME}
36+
37+
COPY . .
38+
COPY --from=builder /${PROJECT_NAME}/venv /${PROJECT_NAME}/venv
39+
40+
# Uncomment this and add VOLUME if needed.
41+
# VOLUME [ "/$PROJECT_NAME/volume-directory" ]
42+
43+
# Edit ENTRYPOINT what the container should run when it starts.
44+
ENTRYPOINT [ "python", "app.py" ]

docker/docker-compose.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
services:
2+
app:
3+
build:
4+
dockerfile: docker/Dockerfile
5+
context: ..
6+
# Edit image name to match your project
7+
image: your-name/project-name:latest
8+
9+
volumes:
10+
# Update paths to mount models and output paths to your custom paths like this, e.g:
11+
# - path/your-local/volume-dir:/project-name/volume-dir
12+
- /project-name/volume-dir
13+
14+
ports:
15+
- "7860:7860"
16+
17+
# This will enable terminal debugging in the container
18+
stdin_open: true
19+
tty: true
20+
21+
# Update entrypoint what to do when the container starts
22+
entrypoint: ["python", "app.py"]
23+
24+
25+
# This is only needed if the project requires GPU. If you're not using Nvidia GPU, Update device to match yours.
26+
# See more info at : https://docs.docker.com/compose/compose-file/deploy/#driver
27+
# You can remove this if you think it's not necessary.
28+
deploy:
29+
resources:
30+
reservations:
31+
devices:
32+
- driver: nvidia
33+
count: all
34+
capabilities: [ gpu ]

0 commit comments

Comments
 (0)