Skip to content

Commit

Permalink
build!: Refactor dependencies and CI
Browse files Browse the repository at this point in the history
  • Loading branch information
itsamirhn committed May 24, 2024
1 parent 185d610 commit ef7aba5
Show file tree
Hide file tree
Showing 12 changed files with 1,459 additions and 36 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.venv
.git
64 changes: 64 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Build and Deploy

permissions:
contents: read
packages: write

on:
push:
tags:
- "v*.*.*"

jobs:
build:
name: Build and Push Docker images
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
ghcr.io/itsamirhn/bonbast-api:latest
ghcr.io/itsamirhn/bonbast-api:${{ github.ref_name }}
deploy:
name: Deploy API
runs-on: ubuntu-latest
needs:
- build
environment: production
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Deploy to server
uses: easingthemes/ssh-deploy@main
with:
SSH_PRIVATE_KEY: ${{ secrets.SSH_KEY }}
REMOTE_HOST: ${{ secrets.SSH_HOST }}
REMOTE_USER: ${{ secrets.SSH_USERNAME }}
SOURCE: docker-compose.yaml
SCRIPT_AFTER: |
TAG=${{ github.ref_name }} docker compose up -d
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,5 @@ dmypy.json
# Cython debug symbols
cython_debug/

.deta
.secrets
.pdm-python
14 changes: 14 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
exclude: migrations
repos:
- repo: https://github.com/pdm-project/pdm
rev: 2.15.3
hooks:
- id: pdm-lock-check
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-yaml
- id: mixed-line-ending
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-merge-conflict
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM python:3.12-slim

WORKDIR /code

COPY pyproject.toml .
COPY pdm.lock .

RUN pip3 install "pdm<3"

RUN pdm install --global --project . --production --fail-fast --no-lock

COPY . .

EXPOSE 3000

CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "3000"]
1 change: 0 additions & 1 deletion Procfile

This file was deleted.

6 changes: 6 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
services:
api:
image: ghcr.io/itsamirhn/bonbast-api:${TAG:-latest}
restart: unless-stopped
ports:
- "3000:3000"
1 change: 0 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,3 @@ async def read_archive_range(
date = price.pop("date")
price_range[date] = price
return price_range

1,329 changes: 1,329 additions & 0 deletions pdm.lock

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[project]
name = "Bonbast-API"
version = "0.1.0"
authors = [
{name = "AmirMohammad Hosseini Nasab", email = "awmirhn@gmail.com"},
]
dependencies = [
"bonbast~=1.0.2",
"fastapi~=0.111.0",
"fastapi-cache2~=0.2.1",
"httpx~=0.27.0",
"uvicorn~=0.29.0",
"beautifulsoup4~=4.12.3",
]
requires-python = ">=3.11"
readme = "README.md"
license = {text = "MIT"}


[tool.pdm]
distribution = false

[tool.pdm.dev-dependencies]
dev = [
"pre-commit>=3.7.1",
]
32 changes: 0 additions & 32 deletions requirements.txt

This file was deleted.

1 change: 0 additions & 1 deletion runtime.txt

This file was deleted.

0 comments on commit ef7aba5

Please sign in to comment.