Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/aai 3 copilot deployment #3

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
**/build
**/dist
**/.sst
**/copilot
copilot
docker
node_modules

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
.DS_Store

## env
*.env
.env.local
.env.development.local
.env.test.local
Expand Down
60 changes: 60 additions & 0 deletions DEPLOYMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
## Deploying an Environment for an Existing Application with AWS Copilot CLI

Before you start, make sure you have the following prerequisites:

- AWS account
- AWS CLI installed and configured with the new customer's AWS account
- Docker installed
- Copilot CLI installed
- Environment variables for the application

Here are the environment variables required:

| Variable | Description |
| -------------------------------- | ----------------------------------------------------- |
| PORT | The port the application runs on |
| APIKEY_PATH | The path to the API key |
| SECRETKEY_PATH | The path to the secret key |
| LOG_PATH | The path to the log files |
| DISABLE_FLOWISE_TELEMETRY | Flag to disable telemetry |
| IFRAME_ORIGINS | Origins allowed to embed the application in an iframe |
| MY_APP_VITE_AUTH_DOMAIN | Auth0 domain |
| MY_APP_VITE_AUTH_CLIENT_ID | Auth0 client ID |
| MY_APP_VITE_AUTH_AUDIENCE | Auth0 audience |
| MY_APP_VITE_AUTH_ORGANIZATION_ID | Auth0 organization ID |
| DOMAIN | The domain of the application |
| ANSWERAI_DOMAIN | The domain of AnswerAI |
| AUTH0_JWKS_URI | URI of Auth0 JWKS |
| AUTH0_ISSUER_BASE_URL | Base URL of Auth0 issuer |
| AUTH0_BASE_URL | Base URL of Auth0 |
| AUTH0_CLIENT_ID | Client ID of Auth0 |
| AUTH0_CLIENT_SECRET | Client secret of Auth0 |
| AUTH0_AUDIENCE | Audience of Auth0 |
| AUTH0_SCOPE | Scope of Auth0 |
| AUTH0_TOKEN_SIGN_ALG | Token signing algorithm of Auth0 |
| AUTH0_ORGANIZATION_ID | Organization ID of Auth0 |

Here are the steps to deploy an environment for an existing application:

1. **Clone the application repository**. This will get you the application code and configuration.

```bash
git clone https://github.com/answers-AI/Flowise
cd Flowise
```

2. **Create a new environment**. This will create a new environment, which is a standalone instance of your application.

```bash
copilot env init --name <env-name> --profile default

3. **Deploy the service**. This will build your Docker image, push it to Amazon ECR, and deploy it to Amazon ECS.
```

````bash
copilot svc deploy --env <env-name>

4. **Access the service**. You can see the URL of your service by running:
```bash
copilot svc show
````
1 change: 1 addition & 0 deletions copilot/.workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
application: flowise
3 changes: 3 additions & 0 deletions copilot/environments/addons/addons.parameters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Parameters:
VPCID: !Ref VPC
PrivateSubnets: !Join [ ',', [ !Ref PrivateSubnet1, !Ref PrivateSubnet2 ] ]
149 changes: 149 additions & 0 deletions copilot/environments/addons/flowise-cluster.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
Parameters:
App:
Type: String
Description: Your application's name.
Env:
Type: String
Description: The name of the environment being deployed.
# Customize your Aurora Serverless cluster by setting the default value of the following parameters.
flowiseclusterDBName:
Type: String
Description: The name of the initial database to be created in the Aurora Serverless v2 cluster.
Default: flowise
# Cannot have special characters
# Naming constraints: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Limits.html#RDS_Limits.Constraints
VPCID:
Type: String
Description: The ID of the VPC in which to create the Aurora Serverless v2 cluster.
Default: ""
PrivateSubnets:
Type: String
Description: The IDs of the private subnets in which to create the Aurora Serverless v2 cluster.
Default: ""

Mappings:
flowiseclusterEnvScalingConfigurationMap:
staging:
"DBMinCapacity": 0.5 # AllowedValues: from 0.5 through 128
"DBMaxCapacity": 8 # AllowedValues: from 0.5 through 128

All:
"DBMinCapacity": 0.5 # AllowedValues: from 0.5 through 128
"DBMaxCapacity": 8 # AllowedValues: from 0.5 through 128

Resources:
flowiseclusterDBSubnetGroup:
Type: 'AWS::RDS::DBSubnetGroup'
Properties:
DBSubnetGroupDescription: Group of private subnets for Aurora Serverless v2 cluster.
SubnetIds:
!Split [',', !Ref PrivateSubnets]

flowiseclusterWorkloadSecurityGroup:
Metadata:
'aws:copilot:description': 'A security group for one or more workloads to access the Aurora Serverless v2 cluster flowisecluster'
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupDescription: 'The Security Group to access Aurora Serverless v2 cluster flowisecluster.'
VpcId: !Ref VPCID
Tags:
- Key: Name
Value: !Sub 'copilot-${App}-${Env}-Aurora'

flowiseclusterDBClusterSecurityGroup:
Metadata:
'aws:copilot:description': 'A security group for your Aurora Serverless v2 cluster flowisecluster'
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: The Security Group for the Aurora Serverless v2 cluster.
VpcId: !Ref VPCID
Tags:
- Key: Name
Value: !Sub 'copilot-${App}-${Env}-Aurora'

flowiseclusterDBClusterSecurityGroupIngressFromWorkload:
Type: AWS::EC2::SecurityGroupIngress
Properties:
Description: Ingress from one or more workloads in the environment.
GroupId: !Ref flowiseclusterDBClusterSecurityGroup
IpProtocol: tcp
ToPort: 5432
FromPort: 5432
SourceSecurityGroupId: !Ref flowiseclusterWorkloadSecurityGroup

flowiseclusterAuroraSecret:
Metadata:
'aws:copilot:description': 'A Secrets Manager secret to store your DB credentials'
Type: AWS::SecretsManager::Secret
Properties:
Description: !Sub Aurora main user secret for ${AWS::StackName}
GenerateSecretString:
SecretStringTemplate: '{"username": "postgres"}'
GenerateStringKey: "password"
ExcludePunctuation: true
IncludeSpace: false
PasswordLength: 16
flowiseclusterDBClusterParameterGroup:
Metadata:
'aws:copilot:description': 'A DB parameter group for engine configuration values'
Type: 'AWS::RDS::DBClusterParameterGroup'
Properties:
Description: !Ref 'AWS::StackName'
Family: 'aurora-postgresql14'
Parameters:
client_encoding: 'UTF8'

flowiseclusterDBCluster:
Metadata:
'aws:copilot:description': 'The flowisecluster Aurora Serverless v2 database cluster'
Type: 'AWS::RDS::DBCluster'
Properties:
MasterUsername:
!Join [ "", [ '{{resolve:secretsmanager:', !Ref flowiseclusterAuroraSecret, ":SecretString:username}}" ]]
MasterUserPassword:
!Join [ "", [ '{{resolve:secretsmanager:', !Ref flowiseclusterAuroraSecret, ":SecretString:password}}" ]]
DatabaseName: !Ref flowiseclusterDBName
Engine: 'aurora-postgresql'
EngineVersion: '14.4'
DBClusterParameterGroupName: !Ref flowiseclusterDBClusterParameterGroup
DBSubnetGroupName: !Ref flowiseclusterDBSubnetGroup
Port: 5432
VpcSecurityGroupIds:
- !Ref flowiseclusterDBClusterSecurityGroup
ServerlessV2ScalingConfiguration:
# Replace "All" below with "!Ref Env" to set different autoscaling limits per environment.
MinCapacity: !FindInMap [flowiseclusterEnvScalingConfigurationMap, All, DBMinCapacity]
MaxCapacity: !FindInMap [flowiseclusterEnvScalingConfigurationMap, All, DBMaxCapacity]

flowiseclusterDBWriterInstance:
Metadata:
'aws:copilot:description': 'The flowisecluster Aurora Serverless v2 writer instance'
Type: 'AWS::RDS::DBInstance'
Properties:
DBClusterIdentifier: !Ref flowiseclusterDBCluster
DBInstanceClass: db.serverless
Engine: 'aurora-postgresql'
PromotionTier: 1
AvailabilityZone: !Select
- 0
- !GetAZs
Ref: AWS::Region

flowiseclusterSecretAuroraClusterAttachment:
Type: AWS::SecretsManager::SecretTargetAttachment
Properties:
SecretId: !Ref flowiseclusterAuroraSecret
TargetId: !Ref flowiseclusterDBCluster
TargetType: AWS::RDS::DBCluster

Outputs:
flowiseclusterSecret:
Description: "The JSON secret that holds the database username and password. Fields are 'host', 'port', 'dbname', 'username', 'password', 'dbClusterIdentifier' and 'engine'"
Value: !Ref flowiseclusterAuroraSecret
Export:
Name: !Sub ${App}-${Env}-flowiseclusterAuroraSecret
flowiseclusterSecurityGroup:
Description: "The security group to attach to the workload."
Value: !Ref flowiseclusterWorkloadSecurityGroup
Export:
Name: !Sub ${App}-${Env}-flowiseclusterSecurityGroup
21 changes: 21 additions & 0 deletions copilot/environments/staging/manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# The manifest for the "staging" environment.
# Read the full specification for the "Environment" type at:
# https://aws.github.io/copilot-cli/docs/manifest/environment/

# Your environment name will be used in naming your resources like VPC, cluster, etc.
name: staging
type: Environment

# Import your own VPC and subnets or configure how they should be created.
# network:
# vpc:
# id:

# Configure the load balancers in your environment, once created.
# http:
# public:
# private:

# Configure observability for your environment resources.
observability:
container_insights: false
61 changes: 61 additions & 0 deletions copilot/flowise/manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# The manifest for the "flowise" service.
# Read the full specification for the "Load Balanced Web Service" type at:
# https://aws.github.io/copilot-cli/docs/manifest/lb-web-service/

# Your service name will be used in naming your resources like log groups, ECS services, etc.
name: flowise
type: Load Balanced Web Service

# Distribute traffic to your service.
http:
# Requests to this path will be forwarded to your service.
# To match all requests you can use the "/" path.
path: '/'
# You can specify a custom health check path. The default is "/".
# healthcheck: '/'
alias: ${COPILOT_ENVIRONMENT_NAME}.flowise.theanswer.ai

# Configuration for your containers and service.
image:
# Docker build arguments. For additional overrides: https://aws.github.io/copilot-cli/docs/manifest/lb-web-service/#image-build
build: Dockerfile
cache_from:
- theanswerai/flowise:latest

# Port exposed through your container to route traffic to it.
port: 4000

cpu: 256 # Number of CPU units for the task.
memory: 512 # Amount of memory i n MiB used by the task.
count: 1 # Number of tasks that should be running in your service.
exec: true # Enable running commands in your container.
network:
connect: true # Enable Service Connect for intra-environment traffic between services.
vpc:
security_groups:
- from_cfn: ${COPILOT_APPLICATION_NAME}-${COPILOT_ENVIRONMENT_NAME}-flowiseclusterSecurityGroup

storage:
volumes:
myManagedEFSVolume:
efs: true
path: /var/efs
read_only: false
# readonly_fs: true # Limit to read-only access to mounted root filesystems.

# Optional fields for more advanced use-cases.
#
#variables: # Pass environment variables as key value pairs.
# LOG_LEVEL: info

secrets: # Pass secrets from AWS Systems Manager (SSM) Parameter Store.
DATABASE_SECRET:
from_cfn: ${COPILOT_APPLICATION_NAME}-${COPILOT_ENVIRONMENT_NAME}-flowiseclusterAuroraSecret

# You can override any of the values defined above by environment.
environments:
staging:
env_file: /${COPILOT_ENVIRONMENT_NAME}.env
# count: 2 # Number of tasks to run for the "test" environment.
# deployment: # The deployment strategy for the "test" environment.
# rolling: 'recreate' # Stops existing tasks before new ones are started for faster deployments.
11 changes: 11 additions & 0 deletions packages/server/src/commands/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,17 @@ export default class Start extends Command {
if (flags.DATABASE_SSL) process.env.DATABASE_SSL = flags.DATABASE_SSL
if (flags.DATABASE_SSL_KEY_BASE64) process.env.DATABASE_SSL_KEY_BASE64 = flags.DATABASE_SSL_KEY_BASE64

// Copilot database secret

if (process.env.DATABASE_SECRET) {
const { host, port, dbname, username, password } = JSON.parse(process.env.DATABASE_SECRET)
process.env.DATABASE_HOST = host
process.env.DATABASE_PORT = port
process.env.DATABASE_NAME = dbname
process.env.DATABASE_USER = username
process.env.DATABASE_PASSWORD = password
}

// Langsmith tracing
if (flags.LANGCHAIN_TRACING_V2) process.env.LANGCHAIN_TRACING_V2 = flags.LANGCHAIN_TRACING_V2
if (flags.LANGCHAIN_ENDPOINT) process.env.LANGCHAIN_ENDPOINT = flags.LANGCHAIN_ENDPOINT
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import useNotifyParentOfNavigation from './utils/useNotifyParentOfNavigation'

const App = () => {
const customization = useSelector((state) => state.customization)
const { getAccessTokenSilently } = useAuth0()
const { getAccessTokenSilently, error } = useAuth0()
useNotifyParentOfNavigation()
React.useEffect(() => {
;(async () => {
Expand Down