Skip to content

Commit

Permalink
first flyctl deploy with initial docker
Browse files Browse the repository at this point in the history
  • Loading branch information
blefnk committed Mar 25, 2024
1 parent 68db541 commit 3714f12
Show file tree
Hide file tree
Showing 9 changed files with 374 additions and 284 deletions.
39 changes: 20 additions & 19 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
__pycache__/

# C extensions
*.so
*.so

# Distribution/packaging
*.egg
Expand Down Expand Up @@ -53,10 +53,10 @@ cover/
*.log.*
log.txt

# Django
local_settings.py
# Django
local_settings.py
db.sqlite3
db.sqlite3-journal
db.sqlite3-journal

# Flask
instance/
Expand All @@ -80,16 +80,16 @@ target/
# IPython
profile_default/
ipython_config.py
.ipython_config.py
.ipython_config.py

# pyenv
.python-version
.python-version

# Environments
.env
.venv
env/
venv/
venv/
ENV/
env.bak/
venv.bak/
Expand All @@ -101,7 +101,7 @@ venv.bak/
# Rope
.ropeproject

# PyCharm
# PyCharm
.idea/

# PyType
Expand All @@ -110,28 +110,29 @@ venv.bak/
# Cython
cython_debug/

# Node
# Node
node_modules
**/.pnp
**/.pnp.js
.pnp.js

# Yarn
# Yarn
yarn-debug.log*
yarn-error.log*
yarn-error.log*
npm-debug.log*

# Build outputs
build/
dist/
.next/
.egg
**/.next/
**/.next/
out/
**/.out/

# Misc
.DS_Store
**/.DS_Store
.installed.cfg
*.egg

Expand All @@ -144,7 +145,7 @@ backend/core/pandoc-*

# TypeScript
.tsbuildinfo
next-env.d.ts
next-env.d.ts

# Application secrets
.env*.local
Expand All @@ -153,7 +154,7 @@ streamlit-demo/.streamlit/secrets.toml
backend/.env
backend/core/application_default_credentials.json

# Editor files
# Editor files
*.sublime-project
*.sublime-workspace

Expand All @@ -163,13 +164,13 @@ backend/core/application_default_credentials.json
package-lock.json
backend/celerybeat-schedule
backend/celerybeat-schedule.db
frontend/public/robots.txt
frontend/public/sitemap*
frontend/public/robots.txt
frontend/public/sitemap*
volumes/db/data/
volumes/storage/stub/stub/example/*
pyfiles/*
backend/bin/*
backend/lib/*
backend/lib/*
backend/pyvenv.cfg
backend/share/*
backend/slim.report.json
Expand All @@ -186,13 +187,13 @@ backend/core/local_models/*

# Misc files
*.pem
*.pyd
*.pyd
*.pyo
__pypackages__/
celerybeat-schedule
celerybeat.pid
.dmypy.json
dmypy.json
dmypy.json
.pdm.toml
pdm.lock
poetry.lock
Expand Down
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,
"files.associations": {
"requirements.txt": "properties",
"*.ignore": "plaintext",
"*.toml": "properties",
"*.txt": "plaintext"
},
"editor.tabSize": 2,
Expand All @@ -16,6 +18,7 @@
"code",
"details",
"h3",
"hr",
"img",
"li",
"ol",
Expand Down
46 changes: 28 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,16 @@ source ~/Desktop/B/A/python/venv/main/bin/activate

**4. Install dependencies:**

The project already has many pre-selected good packages, so you can easily get started, or remove unused packages whenever you want.
The project already has many pre-selected good packages, so you can easily get started, or remove¹ unused packages whenever you want.

So, to install the packages listed in `requirements.txt` just run:

```bash
cd backend && pip install -r requirements.txt
```

<details>
<summary>💡 How to remove unused packages?</summary>
<summary>¹💡 How to remove unused packages?</summary>

<p>Here are the most common and effective ways to remove unused packages from the <code>requirements.txt</code> file:</p>
<h3>1. Manual Review and Editing:</h3>
Expand Down Expand Up @@ -113,22 +119,21 @@ The project already has many pre-selected good packages, so you can easily get s
<li><strong>Review Changes:</strong> Check the updated <code>requirements.txt</code> to make sure the automated tool didn't remove anything essential.</li>
<li><strong>Test Thoroughly:</strong> Run your project's tests or experiment with it manually to ensure everything still works as expected.</li>
</ol>
<hr/>

</details>

```bash
cd backend && pip install -r requirements.txt
```
### Development

**5. Start the development server:**
**Start the development server:**

```bash
uvicorn main:app --reload
# http://localhost:8000
# http://localhost:8000/items/5?q=example
# http://localhost:10000
# http://localhost:10000/items/5?q=example
```

### Important notice
**A tip!**

Remember to work on the activate virtual environment after each new terminal with:

Expand All @@ -142,18 +147,23 @@ So you will see something like that:
- Windows `(main) PS C:\B\S\reliverse\relivator-docker-backend\backend >`
- macOS/Linux `(main) user@machine:~/Desktop/B/S/reliverse/relivator-docker-backend/backend$`

### Docker (Optional)
### Deployment and dockerizing

_Instructions for building and running the project using Docker are forthcoming._

_Instructions for building and running the project using Docker and Docker Compose are forthcoming. Prerequisites:_
**Getting Things Ready:**

- [Docker](https://docs.docker.com/get-docker)
- [Docker Compose](https://docs.docker.com/compose/install)
1. Install [Docker Desktop](https://docs.docker.com/get-docker) and [flyctl](https://fly.io/docs/hands-on/install-flyctl).
2. Create an account with `fly auth signup` or login with `fly auth login`.
3. Run `fly launch` from inside your project source directory to create, configure, and (for most apps) deploy a new application.
4. If prompted, run `fly deploy` to deploy your new app (**or to redeploy after changes!**).

## Contributing

Thank you for considering contributions to Reliverse, means to Relivator Universe!
Thanks for considering contributions to Reliverse, means to Relivator Universe, means to the one of main universe of Bleverse (Blefonix Multiverse)! 😍

1. Follow the installation steps above.
2. Make your changes.
3. Update `requirements.txt` if needed: `pip freeze > requirements.txt`
4. Submit a pull request.
1. Follow the installation steps above, including deployment steps.
2. Update `requirements.txt` if needed: `pip freeze > requirements.txt`.
3. Make your changes. Ensure you have successful build with `flyctl deploy`.
4. Commit the changes to your repo fork. Submit a PR to [relivator-docker-backend](https://github.com/blefnk/relivator-docker-backend).
5. [optional] Visit and sign up on [bleverse.com](https://bleverse.com) to collect your reward as a thank you. (You can win even Blefcoins or even Blefonix Stone!)
1 change: 1 addition & 0 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fly.toml
16 changes: 16 additions & 0 deletions backend/dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM python:3.8

RUN useradd -ms /bin/bash user
USER user

WORKDIR /home/user

COPY requirements.txt .

RUN pip install -r requirements.txt && rm requirements.txt

COPY . .

EXPOSE 10000

ENTRYPOINT [ "python", "main.py"]
55 changes: 55 additions & 0 deletions backend/fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# fly.toml app configuration file generated for relivator on 2024-03-25T17:48:15+01:00
# See https://fly.io/docs/reference/configuration for information about how to use it.

app = "relivator"
primary_region = "waw"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []

[experimental]
allowed_public_ports = []
auto_rollback = true

[[services]]
http_checks = []
internal_port = 10000
processes = ["app"]
protocol = "tcp"
script_checks = []

[services.concurrency]
hard_limit = 25
soft_limit = 20
type = "connections"

[[services.ports]]
force_https = true
handlers = ["http"]
port = 80

[[services.ports]]
handlers = ["tls", "http"]
port = 443

[[services.tcp_checks]]
grace_period = "1s"
interval = "15s"
restart_limit = 0
timeout = "2s"

# [build]
# builder = "paketobuildpacks/builder:base"

# [env]
# PORT = "10000"

# [http_service]
# auto_stop_machines = true
# auto_start_machines = true
# min_machines_running = 0

# [[vm]]
# memory = "1gb"
# cpu_kind = "shared"
# cpus = 1
50 changes: 26 additions & 24 deletions backend/main.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,30 @@
import os

if __name__ == "__main__":
# import needed here when running main.py to debug backend
# you will need to run pip install python-dotenv
from dotenv import load_dotenv # type: ignore

load_dotenv()
from typing import Union
from fastapi import FastAPI, HTTPException
from fastapi.responses import JSONResponse
from fastapi.responses import HTMLResponse, FileResponse
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from pydantic import BaseModel
from logger import get_logger

logger = get_logger(__name__)

if os.getenv("DEV_MODE") == "true":
import debugpy

logger.debug("👨‍💻 Running in dev mode")
debugpy.listen(("0.0.0.0", 5678))

app = FastAPI()
# from logger import get_logger
# logger = get_logger(__name__)

class Item(BaseModel):
name: str
price: float
is_offer: Union[bool, None] = None

app.mount("/static", StaticFiles(directory="static"), name="static")
app = FastAPI()

app.mount("/static", StaticFiles(directory="static"), name="static")
templates = Jinja2Templates(directory="templates")

@app.get("/")
async def root():
return {"message": "Hello Reliverse!"}
async def root() -> str:
return "Hello, Reliverse!"

@app.get('/favicon.ico')
@app.get("/favicon.ico")
async def favicon():
file_name = "favicon.ico"
file_path = os.path.join(app.root_path, "static", file_name)
Expand All @@ -48,11 +34,27 @@ async def favicon():
def read_item(item_id: int, q: Union[str, None] = None):
return {"item_id": item_id, "q": q}


@app.put("/items/{item_id}")
def update_item(item_id: int, item: Item):
return {"item_price": item.price, "item_id": item_id}

@app.get('/abc')
@app.get("/abc")
def abc_test():
return{'hello':'abc'}
return{"hello":"abc"}

def debug_setup():
if os.getenv("DEV_MODE") == "true":
import debugpy
# logger.debug("👨‍💻 Running in dev mode")
debugpy.listen(("0.0.0.0", 5678))

def run_app():
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=10000)

if __name__ == "__main__":
# import needed here when running main.py to debug backend
from dotenv import load_dotenv # type: ignore
load_dotenv()
debug_setup()
run_app()
3 changes: 3 additions & 0 deletions backend/procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# TODO: Modify this Procfile to fit your needs

web: gunicorn app:app
Loading

0 comments on commit 3714f12

Please sign in to comment.