Skip to content

Commit

Permalink
ci: update github action
Browse files Browse the repository at this point in the history
  • Loading branch information
taskingaijc authored and SimsonW committed Mar 11, 2024
1 parent ec8e2b8 commit 66a2a6c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 56 deletions.
97 changes: 43 additions & 54 deletions .github/workflows/test-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,6 @@ jobs:

environment: test

services:
redis:
image: bitnami/redis:6.2.0
env:
REDIS_PASSWORD: password
ports:
- 6379:6379
postgres:
image: docker.io/ankane/pgvector:v0.5.1
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
inference:
image: taskingai/taskingai-inference:v0.2.0
env:
MODE: PROD
ports:
- 8001:8000
plugin:
image: taskingai/taskingai-plugin:v0.2.0
env:
MODE: PROD
ports:
- 8002:8000

steps:
- name: Checkout repo
uses: actions/checkout@v3
Expand Down Expand Up @@ -85,49 +52,71 @@ jobs:
working-directory: backend
run: pip install -r requirements.txt

- name: Create Docker network
run: docker network create taskingai-network

- name: Run Docker image - Postgres
run: |
docker run --network taskingai-network -d --rm \
-e POSTGRES_DB=taskingai \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=TaskingAI321 \
--name db ankane/pgvector:v0.5.1
- name: Run Docker image - Redis
run: |
docker run --network taskingai-network -d --rm \
--name cache redis:7-alpine
- name: Run Docker image - Inference
run: docker run --network taskingai-network -d --rm -e MODE=PROD --name inference taskingai/taskingai-inference:v0.2.0

- name: Run Docker image - Plugin
run: docker run --network taskingai-network -d --rm -e MODE=PROD --name plugin taskingai/taskingai-plugin:v0.2.0

- name: Build Docker image
working-directory: backend
env:
ECR_REGISTRY: ${{ env.ECR_REGISTRY }}
run: |
docker build -t taskingai/taskingai-server:$IMAGE_TAG .
echo "Build success: taskingai/taskingai-server:${IMAGE_TAG}"
- name: Run Docker image - API
- name: Run Docker image - WEB
working-directory: backend
env:
ECR_REGISTRY: ${{ env.ECR_REGISTRY }}
AES_ENCRYPTION_KEY: ${{ env.AES_ENCRYPTION_KEY }}
JWT_SECRET_KEY: ${{ env.JWT_SECRET_KEY }}
run: |
docker run --rm -d -p 8090:8000 \
-e PURPOSE=API \
-e POSTGRES_URL="postgresql+asyncpg://postgres:password@127.0.0.1:5432/test" \
-e REDIS_URL="redis://:password@127.0.0.1:6379/0" -e \
TASKINGAI_INFERENCE_URL=127.0.0.1:8001 -e \
TASKINGAI_PLUGIN_URL=127.0.0.1:8002 -e \
AES_ENCRYPTION_KEY=$AES_ENCRYPTION_KEY \
docker run --network taskingai-network --rm -d -p 8080:8000 \
-e PURPOSE=WEB \
-e POSTGRES_URL="postgres://postgres:TaskingAI321@db:5432/taskingai" \
-e REDIS_URL="redis://cache:6379/0" \
-e TASKINGAI_INFERENCE_URL=http://inference:8000 \
-e TASKINGAI_PLUGINS_URL=http://plugin:8000 \
-e AES_ENCRYPTION_KEY=$AES_ENCRYPTION_KEY \
-e JWT_SECRET_KEY=$JWT_SECRET_KEY \
taskingai/taskingai-server:$IMAGE_TAG
- name: Run Docker image - WEB
- name: Run Docker image - API
working-directory: backend
env:
ECR_REGISTRY: ${{ env.ECR_REGISTRY }}
AES_ENCRYPTION_KEY: ${{ env.AES_ENCRYPTION_KEY }}
JWT_SECRET_KEY: ${{ env.JWT_SECRET_KEY }}
run: |
docker run --rm -d -p 8080:8000 \
-e PURPOSE=WEB \
-e POSTGRES_URL="postgresql+asyncpg://postgres:password@127.0.0.1:5432/test" \
-e REDIS_URL="redis://:password@127.0.0.1:6379/0" \
-e TASKINGAI_INFERENCE_URL=127.0.0.1:8001 \
-e TASKINGAI_PLUGIN_URL=127.0.0.1:8002 \
docker run --network taskingai-network --rm -d -p 8090:8000 \
-e PURPOSE=API \
-e POSTGRES_URL="postgres://postgres:TaskingAI321@db:5432/taskingai" \
-e REDIS_URL="redis://cache:6379/0" \
-e TASKINGAI_INFERENCE_URL=http://inference:8000 \
-e TASKINGAI_PLUGINS_URL=http://plugin:8000 \
-e AES_ENCRYPTION_KEY=$AES_ENCRYPTION_KEY \
-e JWT_SECRET_KEY=$JWT_SECRET_KEY \
taskingai/taskingai-server:$IMAGE_TAG
- name: Wait for service to start
run: sleep 10

- name: Install Dependencies
working-directory: TaskingAI-Test
run: pip install -r requirements.txt

- name: Run WEB Tests
working-directory: TaskingAI-Test
run: bash ./community_app/run_test.sh
Expand Down
1 change: 1 addition & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ RUN pip3 install --no-cache-dir -r requirements.txt

# Copy the rest of the application
COPY ./app ./app
COPY ./tkhelper ./tkhelper

# Expose port 8000
EXPOSE 8000
Expand Down
6 changes: 4 additions & 2 deletions backend/app/fastapi_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ async def sync_data(first_sync=False):
async def lifespan(app: FastAPI):
from app.database import close_database, init_database
from app.services.auth.admin import create_default_admin_if_needed
from app.config import CONFIG

try:
logger.info("fastapi app startup...")
Expand All @@ -42,7 +43,8 @@ async def lifespan(app: FastAPI):
await sync_data(first_sync=True)

await init_database()
await create_default_admin_if_needed()
if CONFIG.WEB:
await create_default_admin_if_needed()

yield

Expand All @@ -52,7 +54,7 @@ async def lifespan(app: FastAPI):


def create_app():
from config import CONFIG
from app.config import CONFIG
from app.routes import routes

app = FastAPI(title="TaskingAI-Community", version=CONFIG.VERSION, lifespan=lifespan)
Expand Down

0 comments on commit 66a2a6c

Please sign in to comment.