diff --git a/docs/docs/en/example.md b/docs/docs/en/example.md index 171aebc2..e2c92ebf 100644 --- a/docs/docs/en/example.md +++ b/docs/docs/en/example.md @@ -2,7 +2,7 @@ ### Project setup -We **strongly recommend** using [**Cookiecutter**](../cookiecutter/index.md) for setting up a FastAgency project. It creates the project folder structure, default workflow, automatically installs all the necessary requirements, and creates a [devcontainer](https://code.visualstudio.com/docs/devcontainers/containers){target="_blank"} that can be used with [Visual Studio Code](https://code.visualstudio.com/){target="_blank"} for development. +We **strongly recommend** using [**Cookiecutter**](./user-guide/cookiecutter/index.md) for setting up a FastAgency project. It creates the project folder structure, default workflow, automatically installs all the necessary requirements, and creates a [devcontainer](https://code.visualstudio.com/docs/devcontainers/containers){target="_blank"} that can be used with [Visual Studio Code](https://code.visualstudio.com/){target="_blank"} for development. 1. Install Cookiecutter with the following command: ```console diff --git a/docs/docs/en/user-guide/getting-started/index.md b/docs/docs/en/user-guide/getting-started/index.md index f2e58c99..2fffd402 100644 --- a/docs/docs/en/user-guide/getting-started/index.md +++ b/docs/docs/en/user-guide/getting-started/index.md @@ -254,6 +254,45 @@ If you created the project using Cookiecutter, then building the Docker image is ./scripts/build_docker.sh ``` +Running the above command will build the Docker image. If the build is successful, you will see output similar to the following: + +
+ Output + ```console + Building fastagency docker image + #0 building with "default" instance using docker driver + + #1 [internal] load build definition from Dockerfile + #1 transferring dockerfile: 1.41kB done + #1 DONE 0.0s + + #2 [internal] load metadata for docker.io/library/python:3.12 + #2 DONE 1.6s + + #3 [internal] load .dockerignore + #3 transferring context: 34B done + #3 DONE 0.0s + + #4 [internal] load build context + #4 transferring context: 14.06kB done + #4 DONE 0.0s + + #5 [1/8] FROM docker.io/library/python:3.12@sha256:fccc38d7080ff9883ee85a65a340384d04eb1c148a7222439b3dc5d4f0f72025 + ... + ... + ... + #12 DONE 0.2s + + #13 exporting to image + #13 exporting layers + #13 exporting layers 0.9s done + #13 writing image sha256:d5b5432294fa293e3f8d5a2128c2ff012faa640fb552c43ce5faf240bce8bc0f done + #13 naming to docker.io/library/deploy_fastagency done + #13 DONE 0.9s + Successfully built fastagency docker image + ``` +
+ ### Running the Docker Image Similarly, running the Docker container is as simple as running the provided script, as shown below: @@ -262,6 +301,69 @@ Similarly, running the Docker container is as simple as running the provided scr ./scripts/run_docker.sh ``` +Running the above command will start the Docker container in the foreground with the following output: + +
+ Output + ```console + Number of workers: 1 + Nginx config: + upstream mesop_backend { + # Enable sticky sessions with IP hash + ip_hash; + + server 127.0.0.1:8889; + + } + + server { + listen 8888; + server_name localhost; + + # Security headers + add_header X-Frame-Options "SAMEORIGIN"; + add_header X-Content-Type-Options "nosniff"; + add_header X-XSS-Protection "1; mode=block"; + + location / { + proxy_pass http://mesop_backend; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_redirect off; + proxy_buffering off; + + # WSGI support + proxy_set_header X-Forwarded-Host $server_name; + + # WebSocket support + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + } + } + Starting gunicorn on port 8889 + 2024/11/12 07:52:47 [warn] 10#10: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1 + [2024-11-12 07:52:47 +0000] [12] [INFO] Starting gunicorn 23.0.0 + [2024-11-12 07:52:47 +0000] [12] [INFO] Listening at: http://0.0.0.0:8889 (12) + [2024-11-12 07:52:47 +0000] [12] [INFO] Using worker: sync + [2024-11-12 07:52:47 +0000] [29] [INFO] Booting worker with pid: 29 + flaml.automl is not available. Please install flaml[automl] to enable AutoML functionalities. + 2024-11-12 07:52:49,054 [INFO] Patching static file serving in Mesop + 2024-11-12 07:52:49,055 [INFO] Initializing MesopUI: + 2024-11-12 07:52:49,059 [INFO] Initialized MesopUI: + 2024-11-12 07:52:49,059 [INFO] Initializing MesopUI: + 2024-11-12 07:52:49,059 [INFO] Initialized MesopUI: + 2024-11-12 07:52:49,059 [INFO] Initializing FastAgency with workflows: and UI: + 2024-11-12 07:52:49,059 [INFO] Initialized FastAgency: + 2024-11-12 07:52:49,068 [INFO] Importing autogen.base.py + INFO: Started server process [11] + INFO: Waiting for application startup. + INFO: Application startup complete. + INFO: Uvicorn running on http://0.0.0.0:8008 (Press CTRL+C to quit) + ``` +
+ ### Deploying to Fly.io If you created the project using Cookiecutter, there is a built-in script to deploy your workflow to [**Fly.io**](https://fly.io/). Run it as shown below: @@ -269,3 +371,82 @@ If you created the project using Cookiecutter, there is a built-in script to dep ```console ./scripts/deploy_to_fly_io.sh ``` + +Running the above command will prompt you to log in to your Fly.io account (if not already logged in) by opening a fly.io URL in your browser. The login prompt will look like this: + +```console +Logging into fly.io +failed opening browser. Copy the url (https://fly.io/app/auth/cli/78366a6d347a377a6e346465776167726f6b693537666a333674346978626d37) into a browser and continue +Opening https://fly.io/app/auth/cli/78366a6d347a377a6e346465776167726f6b693537666a333674346978626d37 ... + +Waiting for session... +``` + +After logging in, the script will deploy your application to Fly.io without any further input. The output will look like this: + +
+ Output + ```console + successfully logged in + Deploying to fly.io + An existing fly.toml file was found for app write-fastagency-docs-cool-dew-7193 + Using build strategies '[the "docker/Dockerfile" dockerfile]'. Remove [build] from fly.toml to force a rescan + Creating app in /workspaces/write_fastagency_docs + We're about to launch your app on Fly.io. Here's what you're getting: + + Organization: Organization Name (fly launch defaults to the personal org) + Name: write-fastagency-docs-delicate-waterfall-7272 (generated) + Region: Amsterdam, Netherlands (from your fly.toml) + App Machines: shared-cpu-1x, 1GB RAM (from your fly.toml) + Postgres: (not requested) + Redis: (not requested) + Tigris: (not requested) + + Created app 'write-fastagency-docs-delicate-waterfall-7272' in organization 'personal' + Admin URL: https://fly.io/apps/write-fastagency-docs-delicate-waterfall-7272 + Hostname: write-fastagency-docs-delicate-waterfall-7272.fly.dev + Wrote config file fly.toml + Validating /workspaces/write_fastagency_docs/fly.toml + ✓ Configuration is valid + ==> Building image + ==> Building image with Depot + --> build: (​) + [+] Building 15.2s (13/13) FINISHED + ... + ... + ... + --> Build Summary: (​) + --> Building image done + image: registry.fly.io/write-fastagency-docs-delicate-waterfall-7272:deployment-01JCFQP31QFJWA9HVVYPZYH1QN + image size: 498 MB + + Watch your deployment at https://fly.io/apps/write-fastagency-docs-delicate-waterfall-7272/monitoring + + Provisioning ips for write-fastagency-docs-delicate-waterfall-7272 + Dedicated ipv6: 2a09:8280:1::4f:f553:0 + Shared ipv4: 66.241.124.140 + Add a dedicated ipv4 with: fly ips allocate-v4 + + This deployment will: + * create 2 "app" machines + + No machines in group app, launching a new machine + Creating a second machine to increase service availability + Finished launching new machines + ------- + NOTE: The machines for [app] have services with 'auto_stop_machines = "stop"' that will be stopped when idling + + ------- + Checking DNS configuration for write-fastagency-docs-delicate-waterfall-7272.fly.dev + + Visit your newly deployed app at https://write-fastagency-docs-delicate-waterfall-7272.fly.dev/ + Setting secrets + Updating existing machines in 'write-fastagency-docs-delicate-waterfall-7272' with rolling strategy + + ------- + ✔ [1/2] Machine 48e2764ce93e58 [app] update succeeded + ✔ [2/2] Machine e825942c739518 [app] update succeeded + ------- + Checking DNS configuration for write-fastagency-docs-delicate-waterfall-7272.fly.dev + ``` +
diff --git a/docs/docs_src/getting_started/fastapi/my_fastagency_app/.dockerignore b/docs/docs_src/getting_started/fastapi/my_fastagency_app/.dockerignore new file mode 100644 index 00000000..e69de29b diff --git a/docs/docs_src/getting_started/fastapi/my_fastagency_app/docker/content/run_fastagency.sh b/docs/docs_src/getting_started/fastapi/my_fastagency_app/docker/content/run_fastagency.sh index 3fc2acf4..bbce57e3 100755 --- a/docs/docs_src/getting_started/fastapi/my_fastagency_app/docker/content/run_fastagency.sh +++ b/docs/docs_src/getting_started/fastapi/my_fastagency_app/docker/content/run_fastagency.sh @@ -18,6 +18,7 @@ do sed -i "5i\ server 127.0.0.1:$PORT;" nginx.conf.template done envsubst '${MESOP_PORT}' < nginx.conf.template >/etc/nginx/conf.d/default.conf +echo "Nginx config:" cat /etc/nginx/conf.d/default.conf # Start nginx diff --git a/docs/docs_src/getting_started/fastapi/my_fastagency_app/scripts/build_docker.sh b/docs/docs_src/getting_started/fastapi/my_fastagency_app/scripts/build_docker.sh index fc83d0ce..47a834bc 100755 --- a/docs/docs_src/getting_started/fastapi/my_fastagency_app/scripts/build_docker.sh +++ b/docs/docs_src/getting_started/fastapi/my_fastagency_app/scripts/build_docker.sh @@ -1,3 +1,5 @@ #!/bin/bash -docker build -t deploy_fastagency -f docker/Dockerfile --progress plain . +echo -e "\033[0;32mBuilding fastagency docker image\033[0m" +docker build -t deploy_fastagency -f docker/Dockerfile --progress plain . && \ +echo -e "\033[0;32mSuccessfully built fastagency docker image\033[0m" diff --git a/docs/docs_src/getting_started/fastapi/my_fastagency_app/scripts/deploy_to_fly_io.sh b/docs/docs_src/getting_started/fastapi/my_fastagency_app/scripts/deploy_to_fly_io.sh index 3d557d1c..46e58ff5 100755 --- a/docs/docs_src/getting_started/fastapi/my_fastagency_app/scripts/deploy_to_fly_io.sh +++ b/docs/docs_src/getting_started/fastapi/my_fastagency_app/scripts/deploy_to_fly_io.sh @@ -1,7 +1,10 @@ #!/bin/bash +echo -e "\033[0;32mLogging into fly.io\033[0m" fly auth login +echo -e "\033[0;32mDeploying to fly.io\033[0m" fly launch --config fly.toml --copy-config --yes +echo -e "\033[0;32mSetting secrets\033[0m" fly secrets set OPENAI_API_KEY=$OPENAI_API_KEY diff --git a/docs/docs_src/getting_started/mesop/my_fastagency_app/.dockerignore b/docs/docs_src/getting_started/mesop/my_fastagency_app/.dockerignore new file mode 100644 index 00000000..e69de29b diff --git a/docs/docs_src/getting_started/mesop/my_fastagency_app/docker/content/run_fastagency.sh b/docs/docs_src/getting_started/mesop/my_fastagency_app/docker/content/run_fastagency.sh index 292fc846..01761049 100755 --- a/docs/docs_src/getting_started/mesop/my_fastagency_app/docker/content/run_fastagency.sh +++ b/docs/docs_src/getting_started/mesop/my_fastagency_app/docker/content/run_fastagency.sh @@ -16,6 +16,7 @@ do sed -i "5i\ server 127.0.0.1:$PORT;" nginx.conf.template done envsubst '${MESOP_PORT}' < nginx.conf.template >/etc/nginx/conf.d/default.conf +echo "Nginx config:" cat /etc/nginx/conf.d/default.conf # Start nginx diff --git a/docs/docs_src/getting_started/mesop/my_fastagency_app/scripts/build_docker.sh b/docs/docs_src/getting_started/mesop/my_fastagency_app/scripts/build_docker.sh index fc83d0ce..47a834bc 100755 --- a/docs/docs_src/getting_started/mesop/my_fastagency_app/scripts/build_docker.sh +++ b/docs/docs_src/getting_started/mesop/my_fastagency_app/scripts/build_docker.sh @@ -1,3 +1,5 @@ #!/bin/bash -docker build -t deploy_fastagency -f docker/Dockerfile --progress plain . +echo -e "\033[0;32mBuilding fastagency docker image\033[0m" +docker build -t deploy_fastagency -f docker/Dockerfile --progress plain . && \ +echo -e "\033[0;32mSuccessfully built fastagency docker image\033[0m" diff --git a/docs/docs_src/getting_started/mesop/my_fastagency_app/scripts/deploy_to_fly_io.sh b/docs/docs_src/getting_started/mesop/my_fastagency_app/scripts/deploy_to_fly_io.sh index 3d557d1c..46e58ff5 100755 --- a/docs/docs_src/getting_started/mesop/my_fastagency_app/scripts/deploy_to_fly_io.sh +++ b/docs/docs_src/getting_started/mesop/my_fastagency_app/scripts/deploy_to_fly_io.sh @@ -1,7 +1,10 @@ #!/bin/bash +echo -e "\033[0;32mLogging into fly.io\033[0m" fly auth login +echo -e "\033[0;32mDeploying to fly.io\033[0m" fly launch --config fly.toml --copy-config --yes +echo -e "\033[0;32mSetting secrets\033[0m" fly secrets set OPENAI_API_KEY=$OPENAI_API_KEY diff --git a/docs/docs_src/getting_started/nats_n_fastapi/my_fastagency_app/.dockerignore b/docs/docs_src/getting_started/nats_n_fastapi/my_fastagency_app/.dockerignore new file mode 100644 index 00000000..e69de29b diff --git a/docs/docs_src/getting_started/nats_n_fastapi/my_fastagency_app/docker/content/run_fastagency.sh b/docs/docs_src/getting_started/nats_n_fastapi/my_fastagency_app/docker/content/run_fastagency.sh index f219f114..f1ec4c0e 100755 --- a/docs/docs_src/getting_started/nats_n_fastapi/my_fastagency_app/docker/content/run_fastagency.sh +++ b/docs/docs_src/getting_started/nats_n_fastapi/my_fastagency_app/docker/content/run_fastagency.sh @@ -20,6 +20,7 @@ do sed -i "5i\ server 127.0.0.1:$PORT;" nginx.conf.template done envsubst '${MESOP_PORT}' < nginx.conf.template >/etc/nginx/conf.d/default.conf +echo "Nginx config:" cat /etc/nginx/conf.d/default.conf # Start nginx diff --git a/docs/docs_src/getting_started/nats_n_fastapi/my_fastagency_app/scripts/build_docker.sh b/docs/docs_src/getting_started/nats_n_fastapi/my_fastagency_app/scripts/build_docker.sh index fc83d0ce..47a834bc 100755 --- a/docs/docs_src/getting_started/nats_n_fastapi/my_fastagency_app/scripts/build_docker.sh +++ b/docs/docs_src/getting_started/nats_n_fastapi/my_fastagency_app/scripts/build_docker.sh @@ -1,3 +1,5 @@ #!/bin/bash -docker build -t deploy_fastagency -f docker/Dockerfile --progress plain . +echo -e "\033[0;32mBuilding fastagency docker image\033[0m" +docker build -t deploy_fastagency -f docker/Dockerfile --progress plain . && \ +echo -e "\033[0;32mSuccessfully built fastagency docker image\033[0m" diff --git a/docs/docs_src/getting_started/nats_n_fastapi/my_fastagency_app/scripts/deploy_to_fly_io.sh b/docs/docs_src/getting_started/nats_n_fastapi/my_fastagency_app/scripts/deploy_to_fly_io.sh index 3d557d1c..46e58ff5 100755 --- a/docs/docs_src/getting_started/nats_n_fastapi/my_fastagency_app/scripts/deploy_to_fly_io.sh +++ b/docs/docs_src/getting_started/nats_n_fastapi/my_fastagency_app/scripts/deploy_to_fly_io.sh @@ -1,7 +1,10 @@ #!/bin/bash +echo -e "\033[0;32mLogging into fly.io\033[0m" fly auth login +echo -e "\033[0;32mDeploying to fly.io\033[0m" fly launch --config fly.toml --copy-config --yes +echo -e "\033[0;32mSetting secrets\033[0m" fly secrets set OPENAI_API_KEY=$OPENAI_API_KEY