diff --git a/.github/workflows/test-backend.yml b/.github/workflows/test-backend.yml index 0509d3ab..3a1ae7f0 100644 --- a/.github/workflows/test-backend.yml +++ b/.github/workflows/test-backend.yml @@ -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 @@ -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 diff --git a/backend/Dockerfile b/backend/Dockerfile index 7fe1f83b..7977c8bf 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -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 diff --git a/backend/app/fastapi_app.py b/backend/app/fastapi_app.py index 7e67ac49..13892535 100644 --- a/backend/app/fastapi_app.py +++ b/backend/app/fastapi_app.py @@ -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...") @@ -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 @@ -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)