Skip to content

Commit 5d441b1

Browse files
committed
prepared playbook for prod
1 parent cc03376 commit 5d441b1

File tree

9 files changed

+69
-44
lines changed

9 files changed

+69
-44
lines changed

.github/workflows/deploy-dev.yaml renamed to .github/workflows/deploy-to-node.yaml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Deploy to dev machine
1+
name: Deploy to node
22

33
on:
44
workflow_call:
@@ -19,6 +19,14 @@ on:
1919
required: false
2020
type: string
2121
default: 3000
22+
postgres-password:
23+
required: false
24+
type: string
25+
default: postgres
26+
web-api-key:
27+
required: false
28+
type: string
29+
default: "1234"
2230

2331
jobs:
2432
deploy:
@@ -39,7 +47,7 @@ jobs:
3947
uses: dawidd6/action-ansible-playbook@v2
4048
with:
4149
# Required, playbook filepath
42-
playbook: deploy-dev.yaml
50+
playbook: deploy-to-node.yaml
4351
# Optional, directory where playbooks live
4452
directory: ansible
4553
# Optional, SSH private key
@@ -49,4 +57,9 @@ jobs:
4957
[dev]
5058
dev01 ansible_host=${{secrets.DEV_NODE_IP}} ansible_connection=ssh ansible_user=web-team
5159
options: |
52-
--extra-vars "stack_name=${{inputs.stack-name}} image_tag=${{inputs.image-tag}} backend_port=${{inputs.backend-port}} website_port=${{inputs.website-port}}"
60+
--extra-vars "stack_name=${{inputs.stack-name}} \
61+
image_tag=${{inputs.image-tag}} \
62+
backend_port=${{inputs.backend-port}} \
63+
website_port=${{inputs.website-port}} \
64+
postgres_password=${{inputs.postgres-password}} \
65+
web_api_key=${{inputs.web-api-key}}"

.github/workflows/release.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ jobs:
3535
context: .
3636
dockerfile: docker/Dockerfile.discord-bot
3737
build-args: ""
38-
deploy-dev:
38+
deploy-to-node:
3939
needs: [build-backend, build-web, build-bot]
40-
uses: ./.github/workflows/deploy-dev.yaml
40+
uses: ./.github/workflows/deploy-to-node.yaml
4141
secrets: inherit
4242
with:
4343
stack-name: ${{ github.event_name == 'release' && 'staging' || 'dev' }}
@@ -46,3 +46,9 @@ jobs:
4646
'latest' }}
4747
backend-port: ${{ github.event_name == 'release' && '8180' || '8080' }}
4848
website-port: ${{ github.event_name == 'release' && '3100' || '3000' }}
49+
postgres-password:
50+
${{ github.event_name == 'release' && secrets.STAGING_POSTGRES_PASSWORD
51+
|| 'postgres' }}
52+
web-api-key:
53+
${{ github.event_name == 'release' && secrets.STAGING_WEB_API_KEY ||
54+
'1234' }}

ansible/deploy-dev.yaml renamed to ansible/deploy-to-node.yaml

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
# ansible playbook to set up some docker containers
22

3-
- name: Deploy to dev node
3+
- name: Deploy to node
44
hosts: dev
55
gather_facts: true
66
vars:
77
stack_name: "dev"
88
image_tag: latest
99
backend_port: 8080
1010
website_port: 3000
11+
postgres_password: postgres
12+
web_api_key: "1234"
1113
tasks:
1214
- name: Create network
1315
community.docker.docker_network:
@@ -44,6 +46,14 @@
4446
volumes:
4547
- "./{{ stack_name }}/redis.conf:/usr/local/etc/redis/redis.conf"
4648

49+
- name: Create volumes for postgres
50+
community.docker.docker_volume:
51+
name: "oasst-{{ stack_name }}-postgres-{{ item.name }}"
52+
state: present
53+
loop:
54+
- name: backend
55+
- name: web
56+
4757
- name: Create postgres containers
4858
community.docker.docker_container:
4959
name: "oasst-{{ stack_name }}-postgres-{{ item.name }}"
@@ -54,8 +64,12 @@
5464
network_mode: "oasst-{{ stack_name }}"
5565
env:
5666
POSTGRES_USER: postgres
57-
POSTGRES_PASSWORD: postgres
67+
POSTGRES_PASSWORD: "{{ postgres_password }}"
5868
POSTGRES_DB: postgres
69+
OFFICIAL_WEB_API_KEY: "{{ web_api_key }}"
70+
volumes:
71+
- "oasst-{{ stack_name }}-postgres-{{ item.name
72+
}}:/var/lib/postgresql/data"
5973
healthcheck:
6074
test: ["CMD", "pg_isready", "-U", "postgres"]
6175
interval: 2s
@@ -76,15 +90,17 @@
7690
network_mode: "oasst-{{ stack_name }}"
7791
env:
7892
POSTGRES_HOST: "oasst-{{ stack_name }}-postgres-backend"
93+
POSTGRES_PASSWORD: "{{ postgres_password }}"
7994
REDIS_HOST: "oasst-{{ stack_name }}-redis"
80-
DEBUG_ALLOW_DEBUG_API_KEY: "true"
81-
DEBUG_USE_SEED_DATA: "true"
95+
DEBUG_USE_SEED_DATA:
96+
"{{ 'true' if stack_name == 'dev' else 'false' }}"
8297
DEBUG_ALLOW_SELF_LABELING:
8398
"{{ 'true' if stack_name == 'dev' else 'false' }}"
8499
MAX_WORKERS: "1"
85100
RATE_LIMIT: "{{ 'false' if stack_name == 'dev' else 'true' }}"
86101
DEBUG_SKIP_EMBEDDING_COMPUTATION: "true"
87-
DEBUG_SKIP_TOXICITY_CALCULATION: "true"
102+
DEBUG_SKIP_TOXICITY_CALCULATION:
103+
"{{ 'true' if stack_name == 'dev' else 'false' }}"
88104
ports:
89105
- "{{ backend_port }}:8080"
90106

@@ -100,9 +116,9 @@
100116
env:
101117
ADMIN_USERS: "{{ lookup('ansible.builtin.env', 'WEB_ADMIN_USERS') }}"
102118
DATABASE_URL:
103-
"postgres://postgres:postgres@oasst-{{ stack_name
119+
"postgres://postgres:{{ postgres_password }}@oasst-{{ stack_name
104120
}}-postgres-web/postgres"
105-
DEBUG_LOGIN: "true"
121+
DEBUG_LOGIN: "{{ 'true' if stack_name == 'dev' else 'false' }}"
106122
DISCORD_CLIENT_ID:
107123
"{{ lookup('ansible.builtin.env', 'WEB_DISCORD_CLIENT_ID') }}"
108124
DISCORD_CLIENT_SECRET:
@@ -117,7 +133,7 @@
117133
EMAIL_SERVER_USER:
118134
"{{ lookup('ansible.builtin.env', 'WEB_EMAIL_SERVER_USER') }}"
119135
FASTAPI_URL: "http://oasst-{{ stack_name }}-backend:8080"
120-
FASTAPI_KEY: "1234"
136+
FASTAPI_KEY: "{{ web_api_key }}"
121137
NEXTAUTH_SECRET:
122138
"{{ lookup('ansible.builtin.env', 'WEB_NEXTAUTH_SECRET') }}"
123139
NEXTAUTH_URL: http://web.{{ stack_name }}.open-assistant.io/

backend/main.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from fastapi_limiter import FastAPILimiter
1212
from fastapi_utils.tasks import repeat_every
1313
from loguru import logger
14-
from oasst_backend.api.deps import get_dummy_api_client
14+
from oasst_backend.api.deps import api_auth, create_api_client
1515
from oasst_backend.api.v1.api import api_router
1616
from oasst_backend.api.v1.utils import prepare_conversation
1717
from oasst_backend.config import settings
@@ -76,6 +76,20 @@ def alembic_upgrade():
7676
logger.exception("Alembic upgrade failed on startup")
7777

7878

79+
if settings.OFFICIAL_WEB_API_KEY:
80+
81+
@app.on_event("startup")
82+
def create_official_web_api_client():
83+
with Session(engine) as session:
84+
create_api_client(
85+
session=session,
86+
api_key=settings.OFFICIAL_WEB_API_KEY,
87+
description="The official web client for the OASST backend.",
88+
frontend_type="web",
89+
trusted=True,
90+
)
91+
92+
7993
if settings.RATE_LIMIT:
8094

8195
@app.on_event("startup")
@@ -111,10 +125,13 @@ class DummyMessage(BaseModel):
111125
role: str
112126
tree_state: Optional[message_tree_state.State]
113127

128+
if not settings.OFFICIAL_WEB_API_KEY:
129+
raise ValueError("Cannot use seed data without OFFICIAL_WEB_API_KEY")
130+
114131
try:
115132
logger.info("Seed data check began")
116133
with Session(engine) as db:
117-
api_client = get_dummy_api_client(db)
134+
api_client = api_auth(settings.OFFICIAL_WEB_API_KEY, db=db)
118135
dummy_user = protocol_schema.User(id="__dummy_user__", display_name="Dummy User", auth_method="local")
119136

120137
ur = UserRepository(db=db, api_client=api_client)

backend/oasst_backend/api/deps.py

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -61,33 +61,11 @@ def create_api_client(
6161
return api_client
6262

6363

64-
def get_dummy_api_client(session: Session) -> ApiClient:
65-
# make sure that a dummy api key exits in db (foreign key references)
66-
DUMMY_API_KEY = "1234"
67-
api_client: ApiClient = session.query(ApiClient).filter(ApiClient.api_key == DUMMY_API_KEY).first()
68-
if api_client is None:
69-
logger.info(f"ANY_API_KEY missing, inserting api_key: {DUMMY_API_KEY}")
70-
api_client = create_api_client(
71-
session=session,
72-
api_key=DUMMY_API_KEY,
73-
description="Dummy api key for debugging",
74-
trusted=True,
75-
frontend_type="Test frontend",
76-
)
77-
session.add(api_client)
78-
session.commit()
79-
return api_client
80-
81-
8264
def api_auth(
8365
api_key: APIKey,
8466
db: Session,
8567
) -> ApiClient:
86-
if api_key or settings.DEBUG_SKIP_API_KEY_CHECK:
87-
88-
if settings.DEBUG_SKIP_API_KEY_CHECK or settings.DEBUG_ALLOW_DEBUG_API_KEY:
89-
return get_dummy_api_client(db)
90-
68+
if api_key:
9169
api_client = db.query(ApiClient).filter(ApiClient.api_key == api_key).first()
9270
if api_client is not None and api_client.enabled:
9371
return api_client

backend/oasst_backend/config.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class TreeManagerConfiguration(BaseModel):
5959
class Settings(BaseSettings):
6060
PROJECT_NAME: str = "open-assistant backend"
6161
API_V1_STR: str = "/api/v1"
62+
OFFICIAL_WEB_API_KEY: str = "1234"
6263

6364
POSTGRES_HOST: str = "localhost"
6465
POSTGRES_PORT: str = "5432"
@@ -71,8 +72,6 @@ class Settings(BaseSettings):
7172
REDIS_HOST: str = "localhost"
7273
REDIS_PORT: str = "6379"
7374

74-
DEBUG_ALLOW_DEBUG_API_KEY: bool = False
75-
DEBUG_SKIP_API_KEY_CHECK: bool = False
7675
DEBUG_USE_SEED_DATA: bool = False
7776
DEBUG_USE_SEED_DATA_PATH: Optional[FilePath] = (
7877
Path(__file__).parent.parent / "test_data/realistic/realistic_seed_data.json"

copilot/api/manifest.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ environments:
2929
variables:
3030
# Note: this has to be a valid JSON list for Pydantic to parse it.
3131
BACKEND_CORS_ORIGINS: '["https://web.staging.open-assistant.surfacedata.org"]'
32-
DEBUG_ALLOW_DEBUG_API_KEY: True
33-
DEBUG_SKIP_API_KEY_CHECK: True
3432
MAX_WORKERS: 1
3533

3634
secrets:

docker-compose.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ services:
9797
environment:
9898
- POSTGRES_HOST=db
9999
- REDIS_HOST=redis
100-
- DEBUG_SKIP_API_KEY_CHECK=True
101100
- DEBUG_USE_SEED_DATA=True
102101
- DEBUG_ALLOW_SELF_LABELING=True
103102
- MAX_WORKERS=1

scripts/backend-development/run-local.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
44
# switch to backend directory
55
pushd "$parent_path/../../backend"
66

7-
export DEBUG_SKIP_API_KEY_CHECK=False
87
export DEBUG_USE_SEED_DATA=True
98
export DEBUG_SKIP_TOXICITY_CALCULATION=True
109
export DEBUG_ALLOW_SELF_LABELING=True

0 commit comments

Comments
 (0)