Skip to content

Commit

Permalink
build: update docker file
Browse files Browse the repository at this point in the history
  • Loading branch information
jameszyao committed Jan 19, 2024
1 parent 27157c9 commit 855f3af
Show file tree
Hide file tree
Showing 13 changed files with 832 additions and 1,356 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Inside the cloned repository, go to the docker directory and launch the services

```bash
cd docker
docker-compose up -d
docker-compose -p taskingai up -d
```

Once the service is up, access the TaskingAI console through your browser with the URL http://localhost:8080.
Expand Down
2 changes: 2 additions & 0 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env
.env.example
5 changes: 3 additions & 2 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ RUN pip3 install --no-cache-dir -r requirements.txt
# Copy the rest of the application
COPY . ./

# Expose port 8000
EXPOSE 8000

# Command to run the application using gunicorn
CMD gunicorn --bind 0.0.0.0:8000 \
--preload \
Expand All @@ -27,5 +30,3 @@ CMD gunicorn --bind 0.0.0.0:8000 \
--worker-connections 200 \
-k uvicorn.workers.UvicornWorker \
app.fastapi_app:app

EXPOSE 8000
3 changes: 2 additions & 1 deletion backend/app/fastapi_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ async def startup_event():
logger.info("FastAPI app startup...")
await redis_pool.init_pool()
await postgres_db_pool.init_pool()
await create_default_admin_if_needed()
if CONFIG.WEB:
await create_default_admin_if_needed()
check_http_error(await inference_health_check())

@app.on_event("shutdown")
Expand Down
18 changes: 12 additions & 6 deletions backend/common/models/auth/admin_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 +53,36 @@ def to_dict(self, purpose: SerializePurpose):

@classmethod
async def get_redis_by_id(cls, admin_id: str):
return await redis_object_get_object(Admin, admin_id)
return await redis_object_get_object(
Admin,
key="id:" + admin_id,
)

@classmethod
async def get_redis_by_username(cls, username: str):
return await redis_object_get_object(Admin, username)
return await redis_object_get_object(
Admin,
key="username:" + username,
)

async def set_redis(self):
await redis_object_set_object(
Admin,
key=self.admin_id,
key="id:" + self.admin_id,
value=self.to_dict(purpose=SerializePurpose.REDIS),
)
await redis_object_set_object(
Admin,
key=self.username,
key="username:" + self.username,
value=self.to_dict(purpose=SerializePurpose.REDIS),
)

async def pop_redis(self):
await redis_object_pop(
Admin,
key=self.admin_id,
key="id:" + self.admin_id,
)
await redis_object_pop(
Admin,
key=self.username,
key="username:" + self.username,
)
2 changes: 1 addition & 1 deletion backend/common/services/auth/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async def refresh_admin_token(admin_id: str) -> Admin:


async def create_default_admin_if_needed() -> Admin:
admin = await db_admin.get_admin_by_username("admin")
admin = await db_admin.get_admin_by_username(CONFIG.DEFAULT_ADMIN_USERNAME)
if not admin:
admin = await db_admin.register_admin(CONFIG.DEFAULT_ADMIN_USERNAME, CONFIG.DEFAULT_ADMIN_PASSWORD)
return admin
2 changes: 1 addition & 1 deletion backend/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"AES_ENCRYPTION_KEY": "1234567890123456789012345678901234567890123456789012345678901234",
"JWT_SECRET_KEY": "1234567890123456789012345678901234567890123456789012345678901234",
"DEFAULT_ADMIN_USERNAME": "admin",
"DEFAULT_ADMIN_PASSWORD": "password",
"DEFAULT_ADMIN_PASSWORD": "TaskingAI321",
}


Expand Down
63 changes: 36 additions & 27 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,67 +1,65 @@
version: "0.0.1"
version: "0.1.0"

services:
inference:
frontend:
image: taskingai-console:0.1.0
depends_on:
- backend-web
- backend-api
- backend-inference

backend-inference:
image: taskingai-inference:1.1.0
expose:
- "8002"
environment:
AES_ENCRYPTION_KEY: b90e4648ad699c3bdf62c0860e09eb9efc098ee75f215bf750847ae19d41e4b0
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8002/v1/health_check"]
test:
["CMD", "curl", "-f", "http://backend-inference:8000/v1/health_check"]
interval: 5s
timeout: 5s
retries: 10

backend-api:
image: taskingai-backend:0.0.1
ports:
- "8000:8000"
image: taskingai-server:0.1.0
environment:
POSTGRES_URL: postgres://postgres:TaskingAI321@db:5432/taskingai
REDIS_URL: redis://:TaskingAI321@cache:6379/0
TASKINGAI_INFERENCE_URL: http://localhost:8002
TASKINGAI_INFERENCE_URL: http://backend-inference:8000
AES_ENCRYPTION_KEY: b90e4648ad699c3bdf62c0860e09eb9efc098ee75f215bf750847ae19d41e4b0
DEFAULT_ADMIN_USERNAME: admin
DEFAULT_ADMIN_PASSWORD: TaskingAI321
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/v1/health_check"]
test: ["CMD", "curl", "-f", "http://backend-api:8000/v1/health_check"]
interval: 5s
timeout: 5s
retries: 10
depends_on:
- db
- cache
- backend-inference

backend-web:
image: taskingai-backend:0.0.1
ports:
- "8001:8001"
image: taskingai-server:0.1.0
environment:
POSTGRES_URL: postgres://postgres:TaskingAI321@db:5432/taskingai
REDIS_URL: redis://:TaskingAI321@cache:6379/0
TASKINGAI_INFERENCE_URL: http://localhost:8002
TASKINGAI_INFERENCE_URL: http://backend-inference:8000
AES_ENCRYPTION_KEY: b90e4648ad699c3bdf62c0860e09eb9efc098ee75f215bf750847ae19d41e4b0
PURPOSE: WEB
DEFAULT_ADMIN_USERNAME: admin
DEFAULT_ADMIN_PASSWORD: TaskingAI321
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8001/api/v1/health_check"]
test: ["CMD", "curl", "-f", "http://backend-web:8000/api/v1/health_check"]
interval: 5s
timeout: 5s
retries: 10
depends_on:
- db
- cache

# frontend:
# image: your-frontend-image
# ports:
# - "80:80"
# depends_on:
# - backend1
# - backend2
- backend-inference

db:
image: ankane/pgvector:v0.5.1
# ports:
# - "5432"
environment:
POSTGRES_DB: taskingai
POSTGRES_USER: postgres
Expand All @@ -78,8 +76,6 @@ services:
cache:
image: redis:7-alpine
command: ["redis-server", "--requirepass", "TaskingAI321"]
# ports:
# - "6379"
volumes:
- redis_data:/data
healthcheck:
Expand All @@ -89,6 +85,19 @@ services:
retries: 10
restart: always

nginx:
image: nginx:1.24
ports:
- "8080:80"
# edit this to change the port, for example to "8080:80" to use port 8080
volumes:
- ./nginx/conf:/etc/nginx/conf.d
depends_on:
- frontend
- backend-web
- backend-api
- backend-inference

volumes:
postgres_data:
redis_data:
15 changes: 15 additions & 0 deletions docker/nginx/conf/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
server {
listen 80;

location /api/v1/ {
proxy_pass http://backend-web:8000;
}

location /v1/ {
proxy_pass http://backend-api:8000;
}

location / {
proxy_pass http://frontend:80;
}
}
30 changes: 21 additions & 9 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
FROM node:16-alpine as builder
# Start with a Node.js 18.18 image as the build environment
FROM node:18.18 as build-stage

# Set the working directory in the Docker container
WORKDIR /app
ADD package.json .
ADD package-lock.json .

RUN npm i
# Copy package.json and package-lock.json (if available) to the working directory
COPY package*.json ./

ADD . .
# Install dependencies defined in package.json
RUN npm install

# Copy the rest of your app's source code from your host to your image filesystem
COPY . .

# Build the application for production
RUN npm run build

FROM nginx:1.24
# Start with a lightweight version of Nginx on Alpine Linux
FROM nginx:alpine

# Copy the build artifacts from the previous stage to the Nginx server directory
COPY --from=build-stage /app/dist /usr/share/nginx/html

EXPOSE 8080
# Expose port 80 to the Docker host, so it can be mapped to the Docker container
EXPOSE 80

COPY ./default.conf /opt/bitnami/nginx/conf/bitnami/default.conf
COPY --from=builder /app/dist /usr/share/nginx/html
# Start Nginx when the container is launched and keep it running
CMD ["nginx", "-g", "daemon off;"]
30 changes: 0 additions & 30 deletions frontend/default.conf

This file was deleted.

Loading

0 comments on commit 855f3af

Please sign in to comment.