Skip to content

Commit b77190a

Browse files
authored
Merge pull request #30 from MedAziz11/release/1.2.1
Release/1.2.1
2 parents bd4114f + facfceb commit b77190a

25 files changed

+510
-135
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Auto Release
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
7+
jobs:
8+
release:
9+
name: Release
10+
runs-on: ubuntu-latest
11+
if: github.event.pull_request.merged && (github.event.pull_request.base.ref == 'main' || github.event.pull_request.base.ref == 'develop')
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v2
15+
16+
- name: Tag
17+
uses: K-Phoen/semver-release-action@master
18+
with:
19+
release_branch: ${{ github.event.pull_request.base.ref }}
20+
env:
21+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/main.yml

Lines changed: 97 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,106 @@
1-
name: Docker Image CI
1+
name: Stellar Docker Image CI
22

33
on:
44
push:
5-
branches: [ "main" ]
5+
branches:
6+
- main
7+
- develop
8+
tags:
9+
- "v*.*.*"
10+
611
pull_request:
7-
branches: [ "main" ]
12+
branches:
13+
- main
14+
- develop
15+
16+
env:
17+
DOCKERHUB_REPO: ${{ vars.DOCKERHUB_REPO || 'medaziz11' }}
18+
DOCKERHUB_IMAGE: ${{ vars.DOCKERHUB_IMAGE || 'uptimekuma_restapi' }}
19+
CACHE_PATH: /tmp/.buildx-cache
820

921
jobs:
22+
build-test-push:
23+
runs-on: ubuntu-latest
24+
steps:
25+
# Check out the repository code
26+
- name: Checkout code
27+
uses: actions/checkout@v3
1028

11-
build-and-push:
29+
# Set up Docker Buildx for building images with BuildKit
30+
- name: Set up Docker Buildx
31+
uses: docker/setup-buildx-action@v1
1232

13-
runs-on: ubuntu-latest
33+
# Cache Docker layers for faster builds
34+
- name: Cache Docker layers
35+
uses: actions/cache@v2
36+
with:
37+
path: ${{ env.CACHE_PATH }}
38+
key: ${{ runner.os }}-buildx-${{ github.ref }}-${{ hashFiles('**/Dockerfile') }}
39+
restore-keys: |
40+
${{ runner.os }}-buildx-${{ github.ref }}-
41+
${{ runner.os }}-buildx-
42+
43+
# Log in to Docker Hub using the provided secrets
44+
- name: Login to Docker Hub
45+
if: github.event_name != 'pull_request'
46+
uses: docker/login-action@v1
47+
with:
48+
username: ${{ secrets.DOCKER_USERNAME }}
49+
password: ${{ secrets.DOCKER_PASSWORD }}
50+
51+
- name: Set image tags
52+
id: image_tags
53+
run: |
54+
REPO=${{ env.DOCKERHUB_REPO }}
55+
IMAGE=${{ env.DOCKERHUB_IMAGE }}
56+
BRANCH=$(echo ${GITHUB_REF#refs/heads/} | sed 's/\//-/g')
57+
58+
if [ "${{ github.event_name }}" == "pull_request" ]; then
59+
PR_NUMBER=${{ github.event.number }}
60+
TAGS="${REPO}/${IMAGE}:pr-${PR_NUMBER}"
61+
elif [[ $GITHUB_REF == "refs/heads/main" ]]; then
62+
TAGS="${REPO}/${IMAGE}:latest"
63+
elif [[ $GITHUB_REF == "refs/heads/develop" ]]; then
64+
TAGS="${REPO}/${IMAGE}:dev"
65+
elif [[ $GITHUB_REF == refs/tags/* ]]; then
66+
VERSION=$(echo ${GITHUB_REF#refs/tags/v} | sed 's/\//-/g')
67+
TAGS="${REPO}/${IMAGE}:v${VERSION},${REPO}/${IMAGE}:latest"
68+
else
69+
echo "Error: Unexpected branch or tag"
70+
exit 1
71+
fi
72+
73+
echo "::set-output name=tags::${TAGS}"
74+
75+
# Build, test, and push the Docker image
76+
- name: Build, Test, and Push Docker image
77+
uses: docker/build-push-action@v2
78+
with:
79+
context: .
80+
platforms: linux/amd64,linux/arm64
81+
push: ${{ github.event_name != 'pull_request' }}
82+
tags: ${{ steps.image_tags.outputs.tags }}
83+
cache-from: type=local,src=${{ env.CACHE_PATH }}
84+
cache-to: type=local,dest=${{ env.CACHE_PATH }}
85+
86+
# FUTURE TESTS?
87+
# # Test the built Docker image
88+
# - name: Run container structure tests
89+
# run: |
90+
# docker run -v $(pwd)/test:/test -v /var/run/docker.sock:/var/run/docker.sock \
91+
# gcr.io/gcp-runtimes/container-structure-test:v1.12.0 \
92+
# test --image ${{ env.DOCKERHUB_REPO }}/${{ env.DOCKERHUB_IMAGE }}:${{ matrix.branch }}-${{ matrix.platform }} \
93+
# --config /test/structure-test-config.yaml
94+
95+
# # Scan the built Docker image for security vulnerabilities
96+
# - name: Scan Docker image for vulnerabilities
97+
# run: |
98+
# IMAGE_TAG=${{ matrix.branch }}-${{ env.PLATFORM_TAG }}
99+
# docker pull ${{ env.DOCKERHUB_REPO }}/${{ env.DOCKERHUB_IMAGE }}:${IMAGE_TAG}
100+
# docker run --rm -v /var/run/docker.sock:/var/run/docker.sock \
101+
# aquasec/trivy:latest \
102+
# --exit-code 1 \
103+
# --severity CRITICAL,HIGH \
104+
# --ignore-unfixed \
105+
# ${{ env.DOCKERHUB_REPO }}
14106

15-
steps:
16-
- uses: actions/checkout@v3
17-
18-
- name: Build and Push the Docker image
19-
uses: mr-smithers-excellent/docker-build-push@v6
20-
with:
21-
image: medaziz11/uptimekuma_restapi
22-
tags: 1.2
23-
registry: docker.io
24-
username: ${{ secrets.DOCKER_USERNAME }}
25-
password: ${{ secrets.DOCKER_PASSWORD }}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Manual Release
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
semver:
6+
description: 'Which version you want to increment? Use MAJOR, MINOR or PATCH'
7+
required: true
8+
default: 'PATCH'
9+
label:
10+
description: 'Add Labels. i.e final, alpha, rc'
11+
required: false
12+
default: ''
13+
jobs:
14+
release:
15+
name: Release
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v2
20+
- name: Build
21+
run: echo "BUILD COMPLETE 👍"
22+
- name: Test
23+
run: echo "TESTS PASSED 🎉"
24+
- uses: rui-costa/action-automatic-semver-releases@{latest}
25+
with:
26+
TOKEN: '${{ secrets.GITHUB_TOKEN }}'
27+
SEMVER: '${{ github.event.inputs.semver }}'
28+
LABEL: '${{ github.event.inputs.label }}'

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
.env
2-
db/*
2+
db/*
3+
__pycache__
4+
.pytest_cache
5+
.mypy_cache

.pre-commit-config.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.1.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-yaml
8+
- id: check-added-large-files
9+
10+
- repo: https://github.com/psf/black
11+
rev: 23.3.0
12+
hooks:
13+
- id: black
14+
15+
- repo: https://github.com/pycqa/bandit
16+
rev: 1.7.0
17+
hooks:
18+
- id: bandit
19+
exclude: /tests/.*

Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,13 @@ ENV PYTHONUNBUFFERED 1
4949
ENV PATH="/app/venv/bin:$PATH"
5050

5151
## Cleanup without impacting the codebase
52-
RUN chmod +x /app/entrypoint.sh
52+
RUN chmod +x /app/entrypoint.sh
5353

5454
USER appuser
5555

56-
# Run the app
56+
#Run the app
5757
ENTRYPOINT ["/app/entrypoint.sh"]
5858

59+
# ENTRYPOINT [ "tail", "-f", "/dev/null" ]
60+
5961

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,10 @@ down:
66

77
test:
88
bash tests/monitor.sh
9+
bash tests/maintenance.sh
910
bash tests/statuspage.sh
11+
12+
setup:
13+
python3 -m venv venv && \
14+
. venv/bin/activate && \
15+
pip install -r requirements.txt

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ You will connect with those credentials:
3737
- Easy to use REST API with most of the Uptime-Kuma features
3838
- Swagger Docs
3939
- Dockerized [UptimeKuma_RestAPI Image](https://hub.docker.com/repository/docker/medaziz11/uptimekuma_restapi)
40-
- Multi-architecture support (amd64, arm64, arm/v7, arm/v6)
40+
- Multi-architecture support (amd64, arm64)
4141

4242
### Example :
4343

app/app_setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ async def shutdown_event():
1919

2020
async def setup_database():
2121
if not os.path.exists("../db"):
22-
os.makedirs("../db")
22+
os.makedirs("../db", 777)
2323

2424
await Tortoise.init(
25-
db_url="sqlite://../db/test.sqlite3",
25+
db_url="sqlite://../db/db.sqlite3",
2626
modules={"models": ["models.user"]}
2727
)
2828

app/config.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
11
from pydantic import AnyHttpUrl, BaseSettings
2+
from fastapi.logger import logger as fast_api_logger
23
from typing import List
34
import secrets
45
import logging
56
import os
67

7-
logger = logging.getLogger("uvicorn.error")
8+
logger = logging.getLogger("gunicorn.error")
9+
fast_api_logger.handlers = logger.handlers
10+
811

912
class Settings(BaseSettings):
10-
PROJECT_NAME: str="Uptime-Kuma-API"
13+
PROJECT_NAME: str = "Uptime-Kuma-API"
1114
BACKEND_CORS_ORIGINS: List[AnyHttpUrl] = []
12-
13-
ACCESS_TOKEN_EXPIRE: int = os.environ.get('ACCESS_TOKEN_EXPIRATION',60 * 24 * 8) #8 days
14-
SECRET_KEY: str = secrets.token_urlsafe(32)
1515

16-
KUMA_SERVER: str = os.environ.get('KUMA_SERVER')
17-
KUMA_USERNAME: str = os.environ.get('KUMA_USERNAME')
18-
KUMA_PASSWORD: str = os.environ.get('KUMA_PASSWORD')
16+
ACCESS_TOKEN_EXPIRE: int = os.environ.get(
17+
"ACCESS_TOKEN_EXPIRATION", 60 * 24 * 8
18+
) # 8 days
19+
SECRET_KEY: str = os.environ.get("SECRET_KEY", secrets.token_urlsafe(32))
1920

20-
ADMIN_PASSWORD: str = os.environ.get('ADMIN_PASSWORD')
21+
KUMA_SERVER: str = os.environ.get("KUMA_SERVER")
22+
KUMA_USERNAME: str = os.environ.get("KUMA_USERNAME")
23+
KUMA_PASSWORD: str = os.environ.get("KUMA_PASSWORD")
2124

25+
ADMIN_PASSWORD: str = os.environ.get("ADMIN_PASSWORD")
2226

2327
class Config:
2428
case_sensitive = True
2529
env_file = ".env"
2630

27-
settings = Settings()
31+
32+
settings = Settings()

0 commit comments

Comments
 (0)