-
Notifications
You must be signed in to change notification settings - Fork 35
/
ecs-instance-dify.yml
219 lines (209 loc) · 6.89 KB
/
ecs-instance-dify.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
ROSTemplateFormatVersion: '2015-09-01'
Description:
zh-cn: 创建VPC、安全组、ECS实例,配置Dify应用开发平台(CentOS 7),含Docker与Dify安装,提供公网访问。
en: Create a Virtual Private Cloud (VPC), security groups, Elastic Compute Service
(ECS) instances, and configure the Dify application development platform (CentOS
7), including the installation of Docker and Dify, with public internet accessibility.
Parameters:
ZoneId:
Type: String
Label:
en: Availability Zone
zh-cn: 可用区ID
AssociationProperty: ALIYUN::ECS::Instance:ZoneId
Description:
en: <b><font color='blue'>This template will pull the Docker image. There may be network problems when using it in domestic regions. You can switch to overseas regions.</font></b>
zh-cn: <b><font color='blue'>本模板会拉取 Docker 镜像,在国内地域使用可能会有网络问题,可切换至海外地域。</font></b>
InstanceType:
Type: String
Label:
en: Instance Type
zh-cn: 实例类型
AssociationProperty: ALIYUN::ECS::Instance::InstanceType
AssociationPropertyMetadata:
ZoneId: ${ZoneId}
DefaultValueStrategy: recent
SystemDiskCategory:
Type: String
Label:
en: System Disk Type
zh-cn: 系统盘类型
AssociationProperty: ALIYUN::ECS::Disk::SystemDiskCategory
AssociationPropertyMetadata:
LocaleKey: DiskCategory
ZoneId: ${ZoneId}
InstanceType: ${InstanceType}
AutoSelectFirst: true
AutoChangeType: false
Default: cloud_essd
InstancePassword:
Type: String
Label:
en: Instance Password
zh-cn: 实例密码
Description:
en: Server login password, Length 8-30, must contain three(Capital letters,
lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol
in).
zh-cn: 服务器登录密码,长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符号)。
ConstraintDescription:
en: Length 8-30, must contain three(Capital letters, lowercase letters, numbers,
()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in).
zh-cn: 长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符号)。
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Equals:
- ${SelectInstance}
- false
Default:
AllowedPattern: '[0-9A-Za-z\_\-\&:;''<>,=%`~!@#\(\)\$\^\*\+\|\{\}\[\]\.\?\/]+$'
MinLength: 8
MaxLength: 30
NoEcho: true
Resources:
Vpc:
Type: ALIYUN::ECS::VPC
Properties:
CidrBlock: 192.168.0.0/16
VSwitch:
Type: ALIYUN::ECS::VSwitch
Properties:
ZoneId:
Ref: ZoneId
VpcId:
Ref: Vpc
CidrBlock: 192.168.0.0/24
SecurityGroup:
Type: ALIYUN::ECS::SecurityGroup
Properties:
VpcId:
Ref: Vpc
SecurityGroupIngress_80:
Type: ALIYUN::ECS::SecurityGroupIngress
Properties:
SecurityGroupId:
Ref: SecurityGroup
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: intranet
PortRange: 80/80
InstanceGroup:
Type: ALIYUN::ECS::InstanceGroup
Properties:
VpcId:
Ref: Vpc
VSwitchId:
Ref: VSwitch
SecurityGroupId:
Ref: SecurityGroup
ImageId: centos_7_9
InstanceName: dify
InstanceType:
Ref: InstanceType
SystemDiskCategory:
Ref: SystemDiskCategory
Password:
Ref: InstancePassword
IoOptimized: optimized
MaxAmount: 1
DS_Instances:
Type: DATASOURCE::ECS::Instances
Properties:
InstanceIds:
Fn::GetAtt:
- InstanceGroup
- InstanceIds
InstallDify:
Type: ALIYUN::ECS::RunCommand
Properties:
InstanceIds:
Fn::GetAtt:
- InstanceGroup
- InstanceIds
Type: RunShellScript
Sync: true
Timeout: 2400
CommandContent: |
#!/bin/bash
echo "#########################"
echo "# Install Docker"
echo "#########################"
wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum -y install docker-ce
systemctl start docker
systemctl enable docker
echo "#########################"
echo "# Install Dify"
echo "#########################"
yum -y install git
REPO_URL="https://github.com/langgenius/dify.git"
TARGET_DIR="/opt/dify"
max_attempts=30
attempt=0
while (( attempt < max_attempts )); do
git clone --depth 1 "$REPO_URL" "$TARGET_DIR"
if [ $? -eq 0 ]; then
echo "Cloning success!"
break
else
attempt=$((attempt + 1))
echo "Cloning failed! attempts: $attempt"
rm -rf "$TARGET_DIR"
sleep 5
fi
done
if [ $attempt -ge $max_attempts ]; then
echo "The maximum number of attempts ($max_attempts) is reached."
exit 1
fi
cd /opt/dify/docker
echo '{
"registry-mirrors": [
"https://docker.registry.cyou",
"https://docker-cf.registry.cyou",
"https://dockercf.jsdelivr.fyi",
"https://docker.jsdelivr.fyi",
"https://dockertest.jsdelivr.fyi",
"https://mirror.aliyuncs.com",
"https://dockerproxy.com",
"https://mirror.baidubce.com",
"https://docker.m.daocloud.io",
"https://docker.nju.edu.cn",
"https://docker.mirrors.sjtug.sjtu.edu.cn",
"https://docker.mirrors.ustc.edu.cn",
"https://mirror.iscas.ac.cn",
"https://docker.rainbond.cc"
]
}' | sudo tee /etc/docker/daemon.json
systemctl daemon-reload
systemctl restart docker
attempt=0
until docker compose up -d; do
attempt=$((attempt + 1))
echo "Attempt $attempt failed! Retrying..."
if [ $attempt -ge $max_attempts ]; then
echo "Reached maximum attempts. Exiting."
exit 1
fi
sleep 5
done
docker compose ps
Outputs:
DifyUrl:
Description: Dify default address.
Value:
Fn::Sub:
- http://${IP}
- IP:
Fn::Jq:
- First
- if .[0].PublicIpAddress != [] then .[0].PublicIpAddress[0] else .[0].EipAddress.IpAddress
end
- Fn::GetAtt:
- DS_Instances
- Instances
Metadata:
ALIYUN::ROS::Interface:
TemplateTags:
- acs:example:AI:在ECS实例(CentOS 7)上搭建大语言模型(LLM) 应用开发平台Dify