Skip to content

Commit

Permalink
fix launcher (nginx, docker-compose.yml)
Browse files Browse the repository at this point in the history
Signed-off-by: Denis Karpelevich <[email protected]>
  • Loading branch information
dkarpele committed Nov 10, 2023
1 parent ce0de10 commit 08e8293
Show file tree
Hide file tree
Showing 39 changed files with 34 additions and 819 deletions.
12 changes: 6 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
PROJECT_NAME=Read-only API

HOST_CDN=127.0.0.1
PORT_CDN=81
HOST_CDN=fastapi-cdn-api
PORT_CDN=8000

HOST_AUTH=127.0.0.1
PORT_AUTH=80
HOST_AUTH=fastapi-auth-api
PORT_AUTH=8000

BUCKET_NAME=video
UPLOAD_PART_SIZE=15000000
IPAPI_KEY=
IPAPI_KEY= # See more https://ipapi.co/. Can be empty

APP_HOME=/app

REDIS_HOST=192.168.80.2
REDIS_HOST=redis
REDIS_PORT=6379
CACHE_EXPIRE_IN_SECONDS=21600
24 changes: 12 additions & 12 deletions .env.minio.json.example
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
{
"ORIGIN": {
"endpoint": "127.0.0.1:9000",
"endpoint": "minio1:9000",
"alias": "origin",
"access_key_id": "minioadmin",
"secret_access_key": "minioadmin",
"city": "Prague",
"latitude": "50.0874654",
"longitude": "14.4212535",
"latitude": 50.0874654,
"longitude": 14.4212535,
"is_active": "True"
},
"MINIO2": {
"endpoint": "192.168.16.4:9000",
"endpoint": "minio2:9000",
"alias": "m2",
"access_key_id": "minioadmin",
"secret_access_key": "minioadmin",
"city": "San Francisco",
"latitude": "37.3361663",
"longitude": "-121.890591",
"latitude": 37.3361663,
"longitude": -121.890591,
"is_active": "False"
},
"MINIO3": {
"endpoint": "192.168.16.3:9000",
"endpoint": "minio3:9000",
"alias": "m3",
"access_key_id": "minioadmin",
"secret_access_key": "minioadmin",
"city": "Guangzhou",
"latitude": "23.381517",
"longitude": "113.827461",
"latitude": 23.381517,
"longitude": 113.827461,
"is_active": "True"
},
"MINIO4": {
"endpoint": "192.168.16.5:9000",
"endpoint": "minio4:9000",
"alias": "m4",
"access_key_id": "minioadmin",
"secret_access_key": "minioadmin",
"city": "New York",
"latitude": "40.7127281",
"longitude": "-74.0060152",
"latitude": 40.7127281,
"longitude": -74.0060152,
"is_active": "True"
}
}
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
/.env
/.env.minio.json
/cdn_api/src/.env
/cdn_api/src/.env.minio.json
/cdn_api_sync/src/.env
/cdn_api_sync/src/.env.minio.json
/cdn_api_async_redis/src/.env.minio.json
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
Link to the project https://github.com/dkarpele/graduate_work

# Graduate work

### Installation

1. Clone [repo](https://github.com/dkarpele/graduate_work).
2. Create ```.env``` file according to ```.env.example```.
3. Create ```.env.minio.json``` file according to ```.env.minio.json.example```.
3. Copy ```.env.minio.json.example``` as ```cdn_api_async_redis/src/.env.minio.json```
4. Launch the project ```docker-compose up --build```.
5. Login to every Minio node and create a bucket (not automated yet)


#### [architecture](architecture)
Expand Down
3 changes: 1 addition & 2 deletions cdn_api_async_redis/src/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ ENV PYTHONUNBUFFERED 1
WORKDIR /app

COPY requirements.txt requirements.txt
COPY entrypoint.sh entrypoint.sh

RUN pip install --upgrade pip \
&& pip install -r /app/requirements.txt

COPY . ./src

CMD ["/bin/sh", "-c", "pwd; cd src ; ls ; \
CMD ["/bin/sh", "-c", "cd src ; \
gunicorn -k uvicorn.workers.UvicornWorker main:app --bind 0.0.0.0:8000"]
3 changes: 2 additions & 1 deletion cdn_api_async_redis/src/api/v1/films.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ async def object_url(
cache: CacheDep
) -> RedirectResponse:
client_host = request.client.host
client_host = "137.0.0.1"
# Stub to test CDN on localhost
# client_host = "137.0.0.1"
active_nodes = await get_active_nodes()
closest_node = await find_closest_node(client_host,
active_nodes)
Expand Down
1 change: 1 addition & 0 deletions cdn_api_async_redis/src/db/minio_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ async def get_url(self, bucket_name, object_name, *args, **kwargs) -> str:
bucket_name=bucket_name,
object_name=object_name,
expires=timedelta(hours=1))
logging.info(f'{url}')
return url
except S3Error as exc:
print("S3 error occurred.", exc)
Expand Down
14 changes: 0 additions & 14 deletions cdn_api_async_redis/src/entrypoint.sh

This file was deleted.

10 changes: 7 additions & 3 deletions cdn_api_async_redis/src/helpers/helper_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,18 @@ async def find_closest_node(user_ip: str,
"""
async with ClientSession() as session:
try:
url_ip_location = (f"https://ipapi.co/{user_ip}/json/"
f"?key={settings.ipapi_key}")
if settings.ipapi_key:
url_ip_location = f"https://ipapi.co/{user_ip}/json/"\
f"?key={settings.ipapi_key}"
else:
url_ip_location = f"https://ipapi.co/{user_ip}/json/"
async with session.get(url_ip_location) as response:
res = await response.json()
try:
user_coordinates = (float(res['latitude']),
float(res['longitude'])
)
logging.info(f"user coordinates: {user_coordinates}")
except KeyError:
logging.error(f"'{user_ip}' not found in the database.")
return False
Expand Down Expand Up @@ -161,7 +165,7 @@ async def is_scheduler_in_progress(cache: AbstractCache,
async def main():
print(await find_closest_node('137.0.0.1',
await get_active_nodes(
"../../../.env.minio.json")))
"../.env.minio.json")))


if __name__ == "__main__":
Expand Down
Empty file.
11 changes: 0 additions & 11 deletions cdn_api_async_redis/tests/functional/.env.example

This file was deleted.

2 changes: 0 additions & 2 deletions cdn_api_async_redis/tests/functional/.gitignore

This file was deleted.

Empty file.
33 changes: 0 additions & 33 deletions cdn_api_async_redis/tests/functional/conftest.py

This file was deleted.

65 changes: 0 additions & 65 deletions cdn_api_async_redis/tests/functional/docker-compose.yml

This file was deleted.

Empty file.
35 changes: 0 additions & 35 deletions cdn_api_async_redis/tests/functional/fixtures/es.py

This file was deleted.

32 changes: 0 additions & 32 deletions cdn_api_async_redis/tests/functional/fixtures/get_data.py

This file was deleted.

29 changes: 0 additions & 29 deletions cdn_api_async_redis/tests/functional/fixtures/redis.py

This file was deleted.

Loading

0 comments on commit 08e8293

Please sign in to comment.