Skip to content

Commit

Permalink
Update deploy docs (#561)
Browse files Browse the repository at this point in the history
* Fix warning for broken link

* Add output to docker and fly.io deploy commands

* Update cookiecutter generated files

* Make output collapsible
  • Loading branch information
kumaranvpl authored Nov 12, 2024
1 parent a46ee63 commit 6ca0bc5
Show file tree
Hide file tree
Showing 14 changed files with 203 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/docs/en/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
181 changes: 181 additions & 0 deletions docs/docs/en/user-guide/getting-started/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

<details>
<summary>Output</summary>
```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
```
</details>

### Running the Docker Image

Similarly, running the Docker container is as simple as running the provided script, as shown below:
Expand All @@ -262,10 +301,152 @@ 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:

<details>
<summary>Output</summary>
```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: <fastagency.ui.mesop.mesop.MesopUI object at 0x74b4128986b0>
2024-11-12 07:52:49,059 [INFO] Initialized MesopUI: <fastagency.ui.mesop.mesop.MesopUI object at 0x74b4128986b0>
2024-11-12 07:52:49,059 [INFO] Initializing MesopUI: <fastagency.ui.mesop.mesop.MesopUI object at 0x74b403fffb30>
2024-11-12 07:52:49,059 [INFO] Initialized MesopUI: <fastagency.ui.mesop.mesop.MesopUI object at 0x74b403fffb30>
2024-11-12 07:52:49,059 [INFO] Initializing FastAgency <FastAgency title=Write FastAgency Docs> with workflows: <fastagency.adapters.fastapi.base.FastAPIProvider object at 0x74b416f21010> and UI: <fastagency.ui.mesop.mesop.MesopUI object at 0x74b403fffb30>
2024-11-12 07:52:49,059 [INFO] Initialized FastAgency: <FastAgency title=Write FastAgency Docs>
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)
```
</details>

### 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:

```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:

<details>
<summary>Output</summary>
```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: <none> (not requested)
Redis: <none> (not requested)
Tigris: <none> (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
```
</details>
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -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
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -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
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6ca0bc5

Please sign in to comment.