Skip to content

Commit

Permalink
update with out using .env file
Browse files Browse the repository at this point in the history
  • Loading branch information
KeithLin724 committed Dec 22, 2023
1 parent 4cceab3 commit 2dfeb94
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 16 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ In `api_cuda` folder is a text_to_image server, for provide text to image servic


### Mention
You need to make a`./api/.env` and `./api_cuda/.env`
#### Format of `./api/.env`
You need to make `./api_cuda/.env` file
<!-- #### Format of `./api/.env`
```sh
SERVER_IP={your_server_ip}
SERVER_PORT=5000
```
``` -->

#### Format of `./api_cuda/.env`
```sh
Expand Down
10 changes: 6 additions & 4 deletions api/base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@
import logging
from func import helper

from dotenv import load_dotenv
# from dotenv import load_dotenv

load_dotenv()
# load_dotenv()

REDIS_CONNECT = Redis(host=os.getenv("SERVER_IP"), port=6379)
# REDIS_CONNECT = Redis(host=os.getenv("SERVER_IP"), port=6379)
REDIS_CONNECT = Redis(host="redis", port=6379)
TASK_IMAGE_QUEUE = Queue(
"generate-image-queue",
connection=REDIS_CONNECT,
default_timeout=3600,
)

# SERVER_IP = helper.get_local_ip()
SERVER_IP = os.getenv("SERVER_IP")
# SERVER_IP = os.getenv("SERVER_IP")
SERVER_IP = "localhost"
SERVER_PORT = 5000
SERVER_URL = f"http://{SERVER_IP}:{SERVER_PORT}"

Expand Down
15 changes: 10 additions & 5 deletions api/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,21 @@ services:
- redis_volume_data:/data
ports:
- 6379:6379
networks:
- my-network

redis_insight:
image: redislabs/redisinsight:latest
container_name: redis_insight
restart: always
ports:
- 8001:8001
networks:
- my-network
volumes:
- redis_insight_volume_data:/db


server:
runtime: nvidia # 使用 NVIDIA Container Toolkit
build:
Expand All @@ -45,8 +50,8 @@ services:
environment:
- NVIDIA_VISIBLE_DEVIVES=all

- SERVER_IP=${SERVER_IP}
- SERVER_PORT=${SERVER_PORT}
# - SERVER_IP=${SERVER_IP}
# - SERVER_PORT=${SERVER_PORT}

work_listener:
build:
Expand All @@ -59,9 +64,9 @@ services:
networks:
- my-network

environment:
- SERVER_IP=${SERVER_IP}
- SERVER_PORT=${SERVER_PORT}
# environment:
# - SERVER_IP=${SERVER_IP}
# - SERVER_PORT=${SERVER_PORT}


volumes:
Expand Down
8 changes: 5 additions & 3 deletions api/rq_worker.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from rq import Worker, Queue, Connection
from redis import Redis
import os
from dotenv import load_dotenv

# from dotenv import load_dotenv
import api_task_func


load_dotenv()
# load_dotenv()

SERVER_IP = os.getenv("SERVER_IP")
# SERVER_IP = os.getenv("SERVER_IP")
SERVER_IP = "redis" # use in docker compose
print(SERVER_IP)
# 连接到Redis队列
redis_conn = Redis(host=SERVER_IP, port=6379)
Expand Down
2 changes: 1 addition & 1 deletion api/server_data.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"ip": "140.113.238.27", "port": 5000}
{"ip": "localhost", "port": 5000}

0 comments on commit 2dfeb94

Please sign in to comment.