Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a7d00529f6 | |||
| 4198ad488b | |||
| 4e84fc9501 | |||
| 0417eacbeb |
@@ -8,6 +8,8 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- master
|
- master
|
||||||
|
- dev
|
||||||
|
- qa
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -20,13 +22,11 @@ jobs:
|
|||||||
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
|
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
|
||||||
id: extract_branch
|
id: extract_branch
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- run: echo docker login ${{ vars.DOCK_REG}} -u ${{ vars.DOCK_REG_USER }}
|
- run: docker login kube-reg.fairfaxmedia.net -u docker -p ${{ secrets.DOCK_REG_AUTH }} # Login to private registry
|
||||||
name: login preview
|
|
||||||
- run: docker login ${{ vars.DOCK_REG}} -u ${{ vars.DOCK_REG_USER }} -p ${{ secrets.DOCK_REG_AUTH }} # Login to private registry
|
|
||||||
name: Login to private registry
|
name: Login to private registry
|
||||||
- run: docker build -t ${{ vars.DOCK_REG}}/papi/svc1:${{ steps.extract_branch.outputs.branch }} . # Build the Docker image
|
- run: docker build -t kube-reg.fairfaxmedia.net/papi/svc1:${{ steps.extract_branch.outputs.branch }} . # Build the Docker image
|
||||||
name: Build Docker image
|
name: Build Docker image
|
||||||
- run: docker push ${{ vars.DOCK_REG}}/papi/svc1:${{ steps.extract_branch.outputs.branch }} # Push the Docker image
|
- run: docker push kube-reg.fairfaxmedia.net/papi/svc1:${{ steps.extract_branch.outputs.branch }} # Push the Docker image
|
||||||
name: Push Docker image
|
name: Push Docker image
|
||||||
deploy:
|
deploy:
|
||||||
runs-on: ubuntu-latest-full
|
runs-on: ubuntu-latest-full
|
||||||
@@ -39,9 +39,7 @@ jobs:
|
|||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- env:
|
- env:
|
||||||
KUBEB64: '${{ secrets.KUBEB64 }}'
|
KUBEB64: '${{ secrets.KUBEB64 }}'
|
||||||
name: deploy
|
run: mkdir -p $HOME/.kube &&echo "$KUBEB64" | base64 -d > $HOME/.kube/config &&
|
||||||
run: mkdir -p $HOME/.kube &&echo "$KUBEB64" | base64 -d > $HOME/.kube/config && chmod 700 $HOME/.kube/config &&
|
/usr/local/bin/helm upgrade --install papi-git-${{ steps.extract_branch.outputs.branch }} papi-helm/ -f ./papi-helm/v.${{ steps.extract_branch.outputs.branch }}.yaml --set image.tag=${{ steps.extract_branch.outputs.branch }} --set name=papi-${{ steps.extract_branch.outputs.branch }} # Deploy the Helm chart
|
||||||
/usr/local/bin/helm upgrade --install papi-${{ steps.extract_branch.outputs.branch }} papi-helm/ --set image.repository=${{ vars.DOCK_REG }}/papi/svc1:${{ steps.extract_branch.outputs.branch }} -f ./papi-helm/v.prod.yaml --set image.tag=${{ steps.extract_branch.outputs.branch }} --set name=papi-prod # Deploy the Helm chart
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"llama-vscode.endpoint": "http://192.168.1.142:11434"
|
|
||||||
}
|
|
||||||
11
Makefile
11
Makefile
@@ -2,7 +2,7 @@ ENV=dev
|
|||||||
VER=0.0.11
|
VER=0.0.11
|
||||||
TAG=${ENV}-${VER}
|
TAG=${ENV}-${VER}
|
||||||
TAG_ARM=${ENV}-arm-${VER}
|
TAG_ARM=${ENV}-arm-${VER}
|
||||||
REGISTRY=192.168.1.134:5000
|
REGISTRY=kube-reg.fairfaxmedia.net
|
||||||
#REGISTRY=direct.fairfaxmedia.net:1529
|
#REGISTRY=direct.fairfaxmedia.net:1529
|
||||||
|
|
||||||
SVC=papi/svc1
|
SVC=papi/svc1
|
||||||
@@ -17,8 +17,8 @@ clean:
|
|||||||
rm -rf test.db
|
rm -rf test.db
|
||||||
rm -rf htmlcov
|
rm -rf htmlcov
|
||||||
|
|
||||||
install.log: requirements.txt
|
install:
|
||||||
pip3 install -r requirements.txt > install.log
|
pip3 install -r requirements.txt
|
||||||
report.xml: *.py
|
report.xml: *.py
|
||||||
pytest --cov=papi --cov=posts --cov=users test_papi.py test_posts.py test_users.py --junitxml=report.xml --cov-report=html --cov-report=xml --cov-report=term --cov-fail-under 90
|
pytest --cov=papi --cov=posts --cov=users test_papi.py test_posts.py test_users.py --junitxml=report.xml --cov-report=html --cov-report=xml --cov-report=term --cov-fail-under 90
|
||||||
|
|
||||||
@@ -45,8 +45,7 @@ integration:
|
|||||||
|
|
||||||
|
|
||||||
arm-tok:
|
arm-tok:
|
||||||
kubectl --context arm-k3s create token serviceaccounts-cluster-admin -duration=1000000000s
|
kubectl --context arm-k3s create token serviceaccounts-cluster-admin
|
||||||
|
|
||||||
echo login at https://k3a.fairfaxmedia.net
|
echo login at https://k3a.fairfaxmedia.net
|
||||||
|
|
||||||
|
|
||||||
@@ -54,7 +53,7 @@ k8s-tok:
|
|||||||
kubectl --context microk8s create token serviceaccounts-cluster-admin
|
kubectl --context microk8s create token serviceaccounts-cluster-admin
|
||||||
echo login at https://kube.fairfaxmedia.net
|
echo login at https://kube.fairfaxmedia.net
|
||||||
|
|
||||||
run: install.log
|
run: install
|
||||||
uvicorn papi:app --reload --port 8912 --host 0.0.0.0
|
uvicorn papi:app --reload --port 8912 --host 0.0.0.0
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
This is the Posts API project, a simple API for managing blog posts.
|
This is the Posts API project, a simple API for managing blog posts.
|
||||||
|
|
||||||
|
|
||||||
## Table of Contents
|
## Table of Contents
|
||||||
- [Installation](#installation)
|
- [Installation](#installation)
|
||||||
- [Usage](#usage)
|
- [Usage](#usage)
|
||||||
@@ -10,7 +9,6 @@ This is the Posts API project, a simple API for managing blog posts.
|
|||||||
- [Contributing](#contributing)
|
- [Contributing](#contributing)
|
||||||
- [License](#license)
|
- [License](#license)
|
||||||
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
1. Clone the repository:
|
1. Clone the repository:
|
||||||
@@ -26,8 +24,6 @@ This is the Posts API project, a simple API for managing blog posts.
|
|||||||
pip install -r requirements.txt
|
pip install -r requirements.txt
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
To start the server, run:
|
To start the server, run:
|
||||||
@@ -114,7 +110,6 @@ make deploy
|
|||||||
### postman-like hopscotch collection:
|
### postman-like hopscotch collection:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
hopscotch_collection.json can be imported into the following tool
|
hopscotch_collection.json can be imported into the following tool
|
||||||
[hopscotch-ui](https://hopscotch.kube.fairfaxmedia.net/)
|
[hopscotch-ui](https://hopscotch.kube.fairfaxmedia.net/)
|
||||||
|
|
||||||
|
|||||||
3
db.py
3
db.py
@@ -12,8 +12,7 @@ engine = create_engine(DATABASE_URL)
|
|||||||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||||
Base = declarative_base()
|
Base = declarative_base()
|
||||||
version = os.environ.get("VERSION", "0.0.0")
|
version = os.environ.get("VERSION", "0.0.0")
|
||||||
def create_db():
|
|
||||||
Base.metadata.create_all(bind=engine)
|
|
||||||
|
|
||||||
|
|
||||||
def get_db():
|
def get_db():
|
||||||
|
|||||||
18
install.log
18
install.log
@@ -1,18 +0,0 @@
|
|||||||
Requirement already satisfied: fastapi in /home/steve/py312/lib/python3.12/site-packages (from -r requirements.txt (line 1)) (0.115.8)
|
|
||||||
Requirement already satisfied: sqlalchemy in /home/steve/py312/lib/python3.12/site-packages (from -r requirements.txt (line 2)) (2.0.29)
|
|
||||||
Requirement already satisfied: uvicorn in /home/steve/py312/lib/python3.12/site-packages (from -r requirements.txt (line 3)) (0.30.6)
|
|
||||||
Requirement already satisfied: pyresttest in /home/steve/py312/lib/python3.12/site-packages (from -r requirements.txt (line 4)) (1.7.1)
|
|
||||||
Requirement already satisfied: starlette<0.46.0,>=0.40.0 in /home/steve/py312/lib/python3.12/site-packages (from fastapi->-r requirements.txt (line 1)) (0.45.3)
|
|
||||||
Requirement already satisfied: pydantic!=1.8,!=1.8.1,!=2.0.0,!=2.0.1,!=2.1.0,<3.0.0,>=1.7.4 in /home/steve/py312/lib/python3.12/site-packages (from fastapi->-r requirements.txt (line 1)) (2.10.6)
|
|
||||||
Requirement already satisfied: typing-extensions>=4.8.0 in /home/steve/py312/lib/python3.12/site-packages (from fastapi->-r requirements.txt (line 1)) (4.12.2)
|
|
||||||
Requirement already satisfied: greenlet!=0.4.17 in /home/steve/py312/lib/python3.12/site-packages (from sqlalchemy->-r requirements.txt (line 2)) (3.0.3)
|
|
||||||
Requirement already satisfied: click>=7.0 in /home/steve/py312/lib/python3.12/site-packages (from uvicorn->-r requirements.txt (line 3)) (8.1.7)
|
|
||||||
Requirement already satisfied: h11>=0.8 in /home/steve/py312/lib/python3.12/site-packages (from uvicorn->-r requirements.txt (line 3)) (0.14.0)
|
|
||||||
Requirement already satisfied: pyyaml in /home/steve/py312/lib/python3.12/site-packages (from pyresttest->-r requirements.txt (line 4)) (6.0.1)
|
|
||||||
Requirement already satisfied: pycurl in /home/steve/py312/lib/python3.12/site-packages (from pyresttest->-r requirements.txt (line 4)) (7.45.3)
|
|
||||||
Requirement already satisfied: future in /home/steve/py312/lib/python3.12/site-packages (from pyresttest->-r requirements.txt (line 4)) (1.0.0)
|
|
||||||
Requirement already satisfied: annotated-types>=0.6.0 in /home/steve/py312/lib/python3.12/site-packages (from pydantic!=1.8,!=1.8.1,!=2.0.0,!=2.0.1,!=2.1.0,<3.0.0,>=1.7.4->fastapi->-r requirements.txt (line 1)) (0.7.0)
|
|
||||||
Requirement already satisfied: pydantic-core==2.27.2 in /home/steve/py312/lib/python3.12/site-packages (from pydantic!=1.8,!=1.8.1,!=2.0.0,!=2.0.1,!=2.1.0,<3.0.0,>=1.7.4->fastapi->-r requirements.txt (line 1)) (2.27.2)
|
|
||||||
Requirement already satisfied: anyio<5,>=3.6.2 in /home/steve/py312/lib/python3.12/site-packages (from starlette<0.46.0,>=0.40.0->fastapi->-r requirements.txt (line 1)) (4.6.2.post1)
|
|
||||||
Requirement already satisfied: idna>=2.8 in /home/steve/py312/lib/python3.12/site-packages (from anyio<5,>=3.6.2->starlette<0.46.0,>=0.40.0->fastapi->-r requirements.txt (line 1)) (3.6)
|
|
||||||
Requirement already satisfied: sniffio>=1.1 in /home/steve/py312/lib/python3.12/site-packages (from anyio<5,>=3.6.2->starlette<0.46.0,>=0.40.0->fastapi->-r requirements.txt (line 1)) (1.3.1)
|
|
||||||
@@ -7,7 +7,7 @@ replicaCount: 1
|
|||||||
|
|
||||||
# This sets the container image more information can be found here: https://kubernetes.io/docs/concepts/containers/images/
|
# This sets the container image more information can be found here: https://kubernetes.io/docs/concepts/containers/images/
|
||||||
image:
|
image:
|
||||||
repository: git.fairfaxmedia.net/papi/svc1
|
repository: kube-reg.fairfaxmedia.net/papi/svc1
|
||||||
# This sets the pull policy for images.
|
# This sets the pull policy for images.
|
||||||
pullPolicy: IfNotPresent
|
pullPolicy: IfNotPresent
|
||||||
# Overrides the image tag whose default is the chart appVersion.
|
# Overrides the image tag whose default is the chart appVersion.
|
||||||
@@ -61,7 +61,7 @@ ingress:
|
|||||||
enabled: true
|
enabled: true
|
||||||
className: ""
|
className: ""
|
||||||
annotations: {}
|
annotations: {}
|
||||||
kubernetes.io/ingress.class: nginx
|
# kubernetes.io/ingress.class: nginx
|
||||||
# kubernetes.io/tls-acme: "true"
|
# kubernetes.io/tls-acme: "true"
|
||||||
tls: []
|
tls: []
|
||||||
# - secretName: chart-example-tls
|
# - secretName: chart-example-tls
|
||||||
@@ -92,9 +92,9 @@ readinessProbe:
|
|||||||
|
|
||||||
# This section is for setting up autoscaling more information can be found here: https://kubernetes.io/docs/concepts/workloads/autoscaling/
|
# This section is for setting up autoscaling more information can be found here: https://kubernetes.io/docs/concepts/workloads/autoscaling/
|
||||||
autoscaling:
|
autoscaling:
|
||||||
enabled: true
|
enabled: false
|
||||||
minReplicas: 0
|
minReplicas: 1
|
||||||
maxReplicas: 5
|
maxReplicas: 100
|
||||||
targetCPUUtilizationPercentage: 80
|
targetCPUUtilizationPercentage: 80
|
||||||
# targetMemoryUtilizationPercentage: 80
|
# targetMemoryUtilizationPercentage: 80
|
||||||
|
|
||||||
|
|||||||
2
posts.py
2
posts.py
@@ -9,7 +9,7 @@ class Post(db.Base):
|
|||||||
id = Column(Integer, primary_key=True, index=True)
|
id = Column(Integer, primary_key=True, index=True)
|
||||||
title = Column(String)
|
title = Column(String)
|
||||||
content = Column(String)
|
content = Column(String)
|
||||||
author_id = Column(Integer, ForeignKey("users.id"),index=True)
|
author_id = Column(Integer, ForeignKey("users.id"))
|
||||||
|
|
||||||
|
|
||||||
router = APIRouter(prefix="/posts")
|
router = APIRouter(prefix="/posts")
|
||||||
|
|||||||
Reference in New Issue
Block a user