Skip to content

Commit 64cc6b1

Browse files
author
Sunser
committed
Initial release
0 parents  commit 64cc6b1

34 files changed

Lines changed: 7320 additions & 0 deletions

.dockerignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.env
2+
.env.*
3+
!.env.example
4+
5+
.git
6+
.gitignore
7+
8+
data
9+
settings.yaml
10+
state.json
11+
config.yaml
12+
13+
ecs-controller
14+
ecs-controller.exe
15+
16+
*.log
17+
*.out
18+
coverage.txt
19+
20+
.DS_Store
21+
Thumbs.db

.env.example

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# [可选] Web 监听地址;容器内保持 :8080,compose 通过 43210:8080 暴露。
2+
EC_LISTEN=:8080
3+
4+
# [可选] 后台巡检间隔,支持 30s、5m、1h 这类 Go duration。
5+
EC_REFRESH_INTERVAL=5m
6+
7+
# [可选] 单次阿里云 API 请求超时。
8+
EC_REQUEST_TIMEOUT=20s
9+
10+
# [必填] Web 登录密码;建议改成足够长的随机字符串。
11+
EC_PASSWORD=change-me-to-a-long-random-password
12+
13+
# [可选] 地域列表缓存时间;regions=auto 时用于减少 DescribeRegions 调用。
14+
EC_REGION_REFRESH_INTERVAL=24h
15+
16+
# [可选] 预留并发上限,默认 4。
17+
EC_MAX_CONCURRENCY=4
18+
19+
# [可选] 流量告警阈值百分比;例如 95 表示达到 95% 后告警或转人工。
20+
EC_TRAFFIC_WARNING_PERCENT=95
21+
22+
# [可选] 日志级别,可填 debug、info、warn、error。
23+
EC_LOG_LEVEL=info
24+
25+
# [可选] 是否启用企业微信应用通知。
26+
EC_NOTIFY_ENABLED=false
27+
28+
# [可选] 企业微信 corpid;启用通知时必填。
29+
EC_WECHAT_CORPID=
30+
31+
# [可选] 企业微信 corpsecret;启用通知时必填。
32+
EC_WECHAT_CORPSECRET=
33+
34+
# [可选] 企业微信 agentid;启用通知时必填。
35+
EC_WECHAT_AGENTID=0
36+
37+
# [可选] 企业微信接收人;单人 user1,多人 user1,user2。
38+
EC_WECHAT_TOUSER=
39+
40+
# [可选] 通知事件;可填 auto_start,manual_start,manual_stop,manual_required,traffic_exceeded,error 或 all。
41+
EC_NOTIFY_EVENTS=auto_start,manual_start,manual_stop,manual_required,traffic_exceeded,error
42+
43+
# [可选] 是否启用后台自动保活。
44+
EC_KEEP_ALIVE_ENABLED=true
45+
46+
# [可选] 保活目标:disabled、all、spot_only、include_list。
47+
EC_KEEP_ALIVE_TARGET=spot_only
48+
49+
# [可选] 流量策略:ignore_limit、pause_when_exceeded、manual_only_when_exceeded。
50+
EC_TRAFFIC_POLICY=manual_only_when_exceeded
51+
52+
# [可选] 同一实例重复启动保护间隔。
53+
EC_START_COOLDOWN=10m
54+
55+
# [可选] 默认停机模式:StopCharging 为节省停机(非包年包月实例可用),KeepCharging 为普通停机。
56+
EC_STOP_MODE=StopCharging
57+
58+
# [可选] 指定保活实例 ID;EC_KEEP_ALIVE_TARGET=include_list 时使用,多个用逗号分隔。
59+
EC_INCLUDE_INSTANCE_IDS=
60+
61+
# [必填] 阿里云账号别名列表,多个用逗号分隔;每个别名会转换成变量名前缀。
62+
EC_ACCOUNTS=CN1,INTL1
63+
64+
# [可选] 账号 CN1 展示名称。
65+
EC_ACCOUNT_CN1_NAME=aliyun-cn-1
66+
67+
# [必填] 账号 CN1 站点:china 或 international。
68+
EC_ACCOUNT_CN1_SITE=china
69+
70+
# [必填] 账号 CN1 AccessKey ID。
71+
EC_ACCOUNT_CN1_ACCESS_KEY_ID=your-china-site-ak
72+
73+
# [必填] 账号 CN1 AccessKey Secret。
74+
EC_ACCOUNT_CN1_ACCESS_KEY_SECRET=your-china-site-sk
75+
76+
# [可选] 账号 CN1 地域列表;auto 表示自动探测,多个地域用逗号分隔。
77+
EC_ACCOUNT_CN1_REGIONS=auto
78+
79+
# [可选] 账号 CN1 中国内地 CDT 月额度,单位 GB。
80+
EC_ACCOUNT_CN1_MAINLAND_TRAFFIC_LIMIT=20
81+
82+
# [可选] 账号 CN1 非中国内地 CDT 月额度,单位 GB。
83+
EC_ACCOUNT_CN1_OVERSEAS_TRAFFIC_LIMIT=200
84+
85+
# [可选] 账号 INTL1 展示名称。
86+
EC_ACCOUNT_INTL1_NAME=aliyun-intl-1
87+
88+
# [必填] 账号 INTL1 站点:china 或 international。
89+
EC_ACCOUNT_INTL1_SITE=international
90+
91+
# [必填] 账号 INTL1 AccessKey ID。
92+
EC_ACCOUNT_INTL1_ACCESS_KEY_ID=your-international-site-ak
93+
94+
# [必填] 账号 INTL1 AccessKey Secret。
95+
EC_ACCOUNT_INTL1_ACCESS_KEY_SECRET=your-international-site-sk
96+
97+
# [可选] 账号 INTL1 地域列表;auto 表示自动探测,多个地域用逗号分隔。
98+
EC_ACCOUNT_INTL1_REGIONS=auto
99+
100+
# [可选] 账号 INTL1 中国内地 CDT 月额度,单位 GB。
101+
EC_ACCOUNT_INTL1_MAINLAND_TRAFFIC_LIMIT=20
102+
103+
# [可选] 账号 INTL1 非中国内地 CDT 月额度,单位 GB。
104+
EC_ACCOUNT_INTL1_OVERSEAS_TRAFFIC_LIMIT=200

.github/workflows/docker-image.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- "v*.*.*"
9+
pull_request:
10+
branches:
11+
- main
12+
13+
permissions:
14+
contents: read
15+
packages: write
16+
17+
jobs:
18+
docker:
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
25+
- name: Set image name
26+
shell: bash
27+
run: echo "IMAGE_NAME=ghcr.io/${GITHUB_REPOSITORY,,}" >> "$GITHUB_ENV"
28+
29+
- name: Set up Docker Buildx
30+
uses: docker/setup-buildx-action@v3
31+
32+
- name: Login to GitHub Container Registry
33+
if: github.event_name != 'pull_request'
34+
uses: docker/login-action@v3
35+
with:
36+
registry: ghcr.io
37+
username: ${{ github.actor }}
38+
password: ${{ secrets.GITHUB_TOKEN }}
39+
40+
- name: Docker metadata
41+
id: meta
42+
uses: docker/metadata-action@v5
43+
with:
44+
images: ${{ env.IMAGE_NAME }}
45+
tags: |
46+
type=raw,value=latest,enable={{is_default_branch}}
47+
type=ref,event=branch
48+
type=ref,event=pr
49+
type=semver,pattern={{version}}
50+
type=semver,pattern={{major}}.{{minor}}
51+
type=sha,prefix=sha-
52+
53+
- name: Build and push
54+
uses: docker/build-push-action@v6
55+
with:
56+
context: .
57+
platforms: linux/amd64
58+
push: ${{ github.event_name != 'pull_request' }}
59+
tags: ${{ steps.meta.outputs.tags }}
60+
labels: ${{ steps.meta.outputs.labels }}

.gitignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.env
2+
.env.*
3+
!.env.example
4+
5+
/data/
6+
/settings.yaml
7+
/state.json
8+
/config.yaml
9+
10+
/ecs-controller
11+
/ecs-controller.exe
12+
13+
*.log
14+
*.out
15+
coverage.txt
16+
17+
.DS_Store
18+
Thumbs.db

Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM golang:1.22-alpine AS builder
2+
3+
WORKDIR /src
4+
COPY go.mod ./
5+
COPY cmd ./cmd
6+
COPY internal ./internal
7+
8+
RUN mkdir -p /out && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags="-s -w" -o /out/ecs-controller ./cmd/ecs-controller
9+
10+
FROM alpine:3.20
11+
12+
RUN apk add --no-cache ca-certificates tzdata
13+
WORKDIR /app
14+
COPY --from=builder /out/ecs-controller ./ecs-controller
15+
COPY web ./web
16+
17+
EXPOSE 8080
18+
VOLUME ["/data"]
19+
20+
ENTRYPOINT ["/app/ecs-controller"]

0 commit comments

Comments
 (0)