commit
43c6aad665
@ -2,10 +2,10 @@ version: "3.4"
|
||||
|
||||
|
||||
services:
|
||||
queues:
|
||||
configurator:
|
||||
image: mathwave/sprint-repo:configurator
|
||||
networks:
|
||||
- configurator
|
||||
- configurator-development
|
||||
environment:
|
||||
MONGO_HOST: "mongo.develop.sprinthub.ru"
|
||||
MONGO_PASSWORD: $MONGO_PASSWORD_DEV
|
||||
@ -18,5 +18,5 @@ services:
|
||||
order: start-first
|
||||
|
||||
networks:
|
||||
configurator:
|
||||
configurator-development:
|
||||
external: true
|
||||
|
@ -2,7 +2,7 @@ version: "3.4"
|
||||
|
||||
|
||||
services:
|
||||
queues:
|
||||
configurator:
|
||||
image: mathwave/sprint-repo:configurator
|
||||
networks:
|
||||
- configurator
|
||||
|
@ -28,7 +28,7 @@ jobs:
|
||||
run: docker push mathwave/sprint-repo:configurator
|
||||
deploy-dev:
|
||||
name: Deploy dev
|
||||
runs-on: [dev]
|
||||
runs-on: [prod]
|
||||
needs: push
|
||||
steps:
|
||||
- name: login
|
||||
@ -37,7 +37,9 @@ jobs:
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: dev
|
||||
- name: network
|
||||
run: docker network create -d overlay --attachable configurator-development || true
|
||||
- name: deploy
|
||||
env:
|
||||
MONGO_PASSWORD_DEV: ${{ secrets.MONGO_PASSWORD_DEV }}
|
||||
run: docker stack deploy --with-registry-auth -c ./.deploy/deploy-dev.yaml infra
|
||||
run: docker stack deploy --with-registry-auth -c ./.deploy/deploy-dev.yaml infra-development
|
||||
|
@ -37,6 +37,8 @@ jobs:
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: prod
|
||||
- name: network
|
||||
run: docker network create -d overlay --attachable configurator || true
|
||||
- name: deploy
|
||||
env:
|
||||
MONGO_PASSWORD_PROD: ${{ secrets.MONGO_PASSWORD_PROD }}
|
||||
|
@ -8,4 +8,4 @@ RUN pip install -r requirements.txt
|
||||
|
||||
COPY . .
|
||||
|
||||
ENTRYPOINT ["python", "main.py"]
|
||||
ENTRYPOINT ["python", "main.py"]
|
@ -20,6 +20,12 @@ class RequestDeleteBody(pydantic.BaseModel):
|
||||
id: str
|
||||
|
||||
|
||||
class Config(pydantic.BaseModel):
|
||||
id: str
|
||||
name: str
|
||||
value: dict
|
||||
|
||||
|
||||
router = fastapi.APIRouter()
|
||||
|
||||
|
||||
@ -40,3 +46,15 @@ async def delete(body: RequestDeleteBody):
|
||||
changed = await configs.delete(id=bson.ObjectId(body.id))
|
||||
if not changed:
|
||||
raise fastapi.HTTPException(404)
|
||||
|
||||
|
||||
@router.get('/api/v1/configs')
|
||||
async def get(stage: str, project: str) -> list[Config]:
|
||||
return [
|
||||
Config(
|
||||
id=str(config._id),
|
||||
name=config.name,
|
||||
value=config.value,
|
||||
)
|
||||
for config in await configs.get(project=project, stage=stage)
|
||||
]
|
||||
|
@ -11,9 +11,18 @@ class RequestPostBody(pydantic.BaseModel):
|
||||
|
||||
|
||||
class RequestPutBody(pydantic.BaseModel):
|
||||
id: str
|
||||
enabled: bool
|
||||
condition: str
|
||||
|
||||
|
||||
class RequestDeleteBody(pydantic.BaseModel):
|
||||
id: str
|
||||
|
||||
|
||||
class Experiment(pydantic.BaseModel):
|
||||
id: str
|
||||
name: str
|
||||
stage: str
|
||||
project: str
|
||||
enabled: bool
|
||||
condition: str
|
||||
|
||||
@ -28,13 +37,26 @@ async def post(body: RequestPostBody):
|
||||
|
||||
@router.put('/api/v1/experiments', status_code=fastapi.status.HTTP_202_ACCEPTED, responses={404: {'description': 'Not found'}})
|
||||
async def put(body: RequestPutBody):
|
||||
changed = await experiments.update(project=body.project, stage=body.stage, name=body.name, enabled=body.enabled, condition=body.condition)
|
||||
changed = await experiments.update(id=body.id, enabled=body.enabled, condition=body.condition)
|
||||
if not changed:
|
||||
raise fastapi.HTTPException(404)
|
||||
|
||||
|
||||
@router.delete('/api/v1/experiments', status_code=fastapi.status.HTTP_202_ACCEPTED, responses={404: {'description': 'Not found'}})
|
||||
async def delete(body: RequestPostBody):
|
||||
changed = await experiments.delete(project=body.project, stage=body.stage, name=body.name)
|
||||
async def delete(body: RequestDeleteBody):
|
||||
changed = await experiments.delete(id=body.id)
|
||||
if not changed:
|
||||
raise fastapi.HTTPException(404)
|
||||
|
||||
|
||||
@router.get('/api/v1/experiments')
|
||||
async def get(stage: str, project: str) -> list[Experiment]:
|
||||
return [
|
||||
Experiment(
|
||||
id=str(experiment._id),
|
||||
name=experiment.name,
|
||||
enabled=experiment.enabled,
|
||||
condition=experiment.condition,
|
||||
)
|
||||
for experiment in await experiments.get(project=project, stage=stage)
|
||||
]
|
||||
|
@ -18,12 +18,10 @@ def create_indexes():
|
||||
database.get_collection('configs').create_index([
|
||||
('stage', 1),
|
||||
('project', 1),
|
||||
('name', 1)
|
||||
])
|
||||
database.get_collection('experiments').create_index([
|
||||
('stage', 1),
|
||||
('project', 1),
|
||||
('name', 1)
|
||||
])
|
||||
database.get_collection('staff').create_index([
|
||||
('platform_id', 1),
|
||||
|
@ -21,13 +21,13 @@ async def create(config: Config) -> str:
|
||||
return result.inserted_id
|
||||
|
||||
|
||||
async def update_data(project: str, stage: str, name: str, value: dict) -> bool:
|
||||
result = await collection.update_one({'project': project, 'stage': stage, 'name': name}, {'$set': {'value': value}})
|
||||
async def update_data(id: bson.ObjectId, value: dict) -> bool:
|
||||
result = await collection.update_one({'_id': id}, {'$set': {'value': value}})
|
||||
return result.modified_count != 0
|
||||
|
||||
|
||||
async def delete(project: str, stage: str, name: str) -> bool:
|
||||
result = await collection.delete_one({'project': project, 'stage': stage, 'name': name})
|
||||
async def delete(id: bson.ObjectId) -> bool:
|
||||
result = await collection.delete_one({'_id': id})
|
||||
return result.deleted_count != 0
|
||||
|
||||
|
||||
|
@ -22,13 +22,13 @@ async def create(experiment: Experiment) -> str:
|
||||
return result.inserted_id
|
||||
|
||||
|
||||
async def update(project: str, stage: str, name: str, enabled: bool, condition: str) -> bool:
|
||||
result = await collection.update_one({'project': project, 'stage': stage, 'name': name}, {'$set': {'enabled': enabled, 'condition': condition}})
|
||||
async def update(id: bson.ObjectId, enabled: bool, condition: str) -> bool:
|
||||
result = await collection.update_one({'_id': id}, {'$set': {'enabled': enabled, 'condition': condition}})
|
||||
return result.modified_count != 0
|
||||
|
||||
|
||||
async def delete(project: str, stage: str, name: str) -> bool:
|
||||
result = await collection.delete_one({'project': project, 'stage': stage, 'name': name})
|
||||
async def delete(id: bson.ObjectId) -> bool:
|
||||
result = await collection.delete_one({'_id': id})
|
||||
return result.deleted_count != 0
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user