Skip to content

Commit faf08e0

Browse files
committed
feat: add ecs-and-deepseek-build-personal-website solution
- Add Terraform templates for ECS and DeepSeek personal website - Include VPC, VSwitch, ECS instance, security groups - Add DeepSeek AI application installation script - Generate comprehensive README documentation - Format all Terraform files with terraform fmt
1 parent c80ffa4 commit faf08e0

File tree

4 files changed

+221
-0
lines changed

4 files changed

+221
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<!-- DOCS_DESCRIPTION_CN -->
2+
本示例用于实现解决方案[低成本搭建 DeepSeek 专属 AI 网站](https://www.aliyun.com/solution/tech-solution/ecs-and-deepseek-build-personal-website), 涉及到专有网络(VPC)、交换机(VSwitch)、云服务器(ECS)、RAM 用户等资源的创建。
3+
<!-- DOCS_DESCRIPTION_CN -->
4+
5+
<!-- DOCS_DESCRIPTION_EN -->
6+
This example is used to implement solution [ECS and Deepseek Build Personal Website](https://www.aliyun.com/solution/tech-solution/ecs-and-deepseek-build-personal-website), which involves the creation and deployment of resources such as Virtual Private Cloud (VPC), VSwitch, Elastic Compute Service (ECS), and RAM users.
7+
<!-- DOCS_DESCRIPTION_EN --
8+
9+
<!-- BEGIN_TF_DOCS -->
10+
## Providers
11+
12+
| Name | Version |
13+
|------|---------|
14+
| <a name="provider_alicloud"></a> [alicloud](#provider\_alicloud) | n/a |
15+
| <a name="provider_random"></a> [random](#provider\_random) | n/a |
16+
17+
## Modules
18+
19+
No modules.
20+
21+
## Resources
22+
23+
| Name | Type |
24+
|------|------|
25+
| [alicloud_ecs_command.install_app](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/ecs_command) | resource |
26+
| [alicloud_ecs_invocation.invoke_script](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/ecs_invocation) | resource |
27+
| [alicloud_instance.ecs_instance](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/instance) | resource |
28+
| [alicloud_ram_user.user](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/ram_user) | resource |
29+
| [alicloud_security_group.security_group](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/security_group) | resource |
30+
| [alicloud_security_group_rule.allow_tcp_8080](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/security_group_rule) | resource |
31+
| [alicloud_vpc.vpc](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/vpc) | resource |
32+
| [alicloud_vswitch.vswitch](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/vswitch) | resource |
33+
| [random_id.suffix](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/id) | resource |
34+
| [alicloud_regions.current](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/data-sources/regions) | data source |
35+
36+
## Inputs
37+
38+
| Name | Description | Type | Default | Required |
39+
|------|-------------|------|---------|:--------:|
40+
| <a name="input_CommonName"></a> [CommonName](#input\_CommonName) | n/a | `string` | `"deepseek-private-ai"` | no |
41+
| <a name="input_InstanceType"></a> [InstanceType](#input\_InstanceType) | {<br/> "AssociationProperty": "ALIYUN::ECS::Instance::InstanceType",<br/> "AssociationPropertyMetadata": {<br/> "ZoneId": "${ZoneId}",<br/> "InstanceChargeType": "PostPaid",<br/> "SystemDiskCategory": "cloud\_essd",<br/> "Constraints": {<br/> "Architecture": ["X86"],<br/> "vCPU": [2],<br/> "Memory": [2]<br/> }<br/> },<br/> "Label": {<br/> "zh-cn": "实例类型",<br/> "en": "Instance Type"<br/> }<br/> } | `string` | `"ecs.e-c1m1.large"` | no |
42+
| <a name="input_ZoneId"></a> [ZoneId](#input\_ZoneId) | {<br/> "AssociationProperty": "ALIYUN::ECS::Instance::ZoneId",<br/> "Description": {<br/> "zh-cn": "可用区",<br/> "en": "Availability Zone"<br/> },<br/> "Label": {<br/> "zh-cn": "可用区",<br/> "en": "Availability Zone"<br/> }<br/> } | `string` | `"cn-hangzhou-f"` | no |
43+
| <a name="input_bai_lian_api_key"></a> [bai\_lian\_api\_key](#input\_bai\_lian\_api\_key) | 百炼 API-KEY,需开通百炼模型服务再获取 API-KEY,详情请参考:https://help.aliyun.com/zh/model-studio/developer-reference/get-api-key | `string` | n/a | yes |
44+
| <a name="input_ecs_instance_password"></a> [ecs\_instance\_password](#input\_ecs\_instance\_password) | 服务器登录密码,长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符号)` | `string` | n/a | yes |
45+
| <a name="input_region"></a> [region](#input\_region) | 地域,例如:cn-hangzhou。所有地域及可用区请参见文档:https://help.aliyun.com/document_detail/40654.html#09f1dc16b0uke | `string` | `"cn-hangzhou"` | no |
46+
<!-- END_TF_DOCS -->
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
provider "alicloud" {
2+
region = var.region
3+
}
4+
5+
resource "random_id" "suffix" {
6+
byte_length = 8
7+
}
8+
9+
locals {
10+
common_name = "${var.CommonName}-${random_id.suffix.hex}"
11+
}
12+
13+
resource "alicloud_vpc" "vpc" {
14+
cidr_block = "192.168.0.0/16"
15+
vpc_name = "${local.common_name}-vpc"
16+
}
17+
18+
resource "alicloud_vswitch" "vswitch" {
19+
vpc_id = alicloud_vpc.vpc.id
20+
cidr_block = "192.168.0.0/24"
21+
zone_id = var.ZoneId
22+
vswitch_name = "${local.common_name}-vsw"
23+
}
24+
25+
resource "alicloud_security_group" "security_group" {
26+
vpc_id = alicloud_vpc.vpc.id
27+
security_group_name = "${local.common_name}-sg"
28+
}
29+
30+
resource "alicloud_security_group_rule" "allow_tcp_8080" {
31+
type = "ingress"
32+
ip_protocol = "tcp"
33+
nic_type = "intranet"
34+
policy = "accept"
35+
port_range = "8080/8080"
36+
priority = 1
37+
security_group_id = alicloud_security_group.security_group.id
38+
cidr_ip = "0.0.0.0/0"
39+
}
40+
41+
resource "alicloud_instance" "ecs_instance" {
42+
instance_name = "${local.common_name}-ecs"
43+
system_disk_category = "cloud_essd"
44+
image_id = "aliyun_3_x64_20G_alibase_20250117.vhd"
45+
vswitch_id = alicloud_vswitch.vswitch.id
46+
password = var.ecs_instance_password
47+
instance_type = var.InstanceType
48+
internet_max_bandwidth_out = 10
49+
security_groups = [alicloud_security_group.security_group.id]
50+
}
51+
52+
resource "alicloud_ram_user" "user" {
53+
name = "create_by_solution-${local.common_name}"
54+
}
55+
56+
resource "alicloud_ecs_command" "install_app" {
57+
name = "install-deepseek-app"
58+
command_content = base64encode(<<EOF
59+
#!/bin/bash
60+
cat <<EOT >> ~/.bash_profile
61+
export API_KEY="${var.bai_lian_api_key}"
62+
export ROS_DEPLOY=true
63+
EOT
64+
65+
source ~/.bash_profile
66+
curl -fsSL https://static-aliyun-doc.oss-cn-hangzhou.aliyuncs.com/install-script/deepseek-r1-private/install.sh|bash
67+
EOF
68+
)
69+
working_dir = "/root"
70+
type = "RunShellScript"
71+
timeout = 3600
72+
}
73+
74+
resource "alicloud_ecs_invocation" "invoke_script" {
75+
instance_id = [alicloud_instance.ecs_instance.id]
76+
command_id = alicloud_ecs_command.install_app.id
77+
timeouts {
78+
create = "15m"
79+
}
80+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
output "ecs_login_address" {
2+
description = <<EOT
3+
{
4+
"Description": {
5+
"en": "Ecs login address.",
6+
"zh-cn": "ECS登录地址。"
7+
}
8+
}
9+
EOT
10+
value = "https://ecs-workbench.aliyun.com/?from=EcsConsole&instanceType=ecs&regionId=${data.alicloud_regions.current.id}&instanceId=${alicloud_instance.ecs_instance.id}"
11+
}
12+
13+
output "demo_url" {
14+
description = <<EOT
15+
{
16+
"Label": {
17+
"zh-cn": "体验地址",
18+
"en": "Experience Addresses"
19+
},
20+
"Description": {
21+
"en": "Experience address.",
22+
"zh-cn": "体验地址。"
23+
}
24+
}
25+
EOT
26+
value = "http://${alicloud_instance.ecs_instance.public_ip}:8080"
27+
}
28+
29+
# 获取当前区域信息的数据源
30+
data "alicloud_regions" "current" {
31+
current = true
32+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
variable "region" {
2+
type = string
3+
default = "cn-hangzhou"
4+
description = "地域,例如:cn-hangzhou。所有地域及可用区请参见文档:https://help.aliyun.com/document_detail/40654.html#09f1dc16b0uke"
5+
}
6+
7+
variable "ZoneId" {
8+
type = string
9+
default = "cn-hangzhou-f"
10+
description = <<EOT
11+
{
12+
"AssociationProperty": "ALIYUN::ECS::Instance::ZoneId",
13+
"Description": {
14+
"zh-cn": "可用区",
15+
"en": "Availability Zone"
16+
},
17+
"Label": {
18+
"zh-cn": "可用区",
19+
"en": "Availability Zone"
20+
}
21+
}
22+
EOT
23+
}
24+
25+
variable "InstanceType" {
26+
type = string
27+
default = "ecs.e-c1m1.large"
28+
description = <<EOT
29+
{
30+
"AssociationProperty": "ALIYUN::ECS::Instance::InstanceType",
31+
"AssociationPropertyMetadata": {
32+
"ZoneId": "$${ZoneId}",
33+
"InstanceChargeType": "PostPaid",
34+
"SystemDiskCategory": "cloud_essd",
35+
"Constraints": {
36+
"Architecture": ["X86"],
37+
"vCPU": [2],
38+
"Memory": [2]
39+
}
40+
},
41+
"Label": {
42+
"zh-cn": "实例类型",
43+
"en": "Instance Type"
44+
}
45+
}
46+
EOT
47+
}
48+
49+
variable "ecs_instance_password" {
50+
type = string
51+
sensitive = true
52+
description = "服务器登录密码,长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符号)"
53+
}
54+
55+
variable "bai_lian_api_key" {
56+
type = string
57+
description = "百炼 API-KEY,需开通百炼模型服务再获取 API-KEY,详情请参考:https://help.aliyun.com/zh/model-studio/developer-reference/get-api-key"
58+
}
59+
60+
variable "CommonName" {
61+
type = string
62+
default = "deepseek-private-ai"
63+
}

0 commit comments

Comments
 (0)