Skip to content
This repository was archived by the owner on Mar 18, 2026. It is now read-only.

Commit 68572e8

Browse files
authored
Add job (#20)
* init # Conflicts: # scripts/sreg-storage.sh * support job * fix s3 no check bucket * use copyto * save docker config * optimize job example * fix * remove debug log
1 parent b6590bb commit 68572e8

6 files changed

Lines changed: 283 additions & 29 deletions

File tree

scripts/.dockerignore

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Git 相关
2+
.git
3+
.gitignore
4+
.gitattributes
5+
6+
# 文档
7+
*.md
8+
README*
9+
CHANGELOG*
10+
LICENSE
11+
docs/
12+
13+
# 构建产物
14+
bin/
15+
dist/
16+
build/
17+
*.exe
18+
*.dll
19+
*.so
20+
*.dylib
21+
*.test
22+
*.out
23+
24+
# 临时文件
25+
*.tmp
26+
*.temp
27+
*.log
28+
*.swp
29+
*.swo
30+
*~
31+
.DS_Store
32+
33+
# IDE 和编辑器
34+
.idea/
35+
.vscode/
36+
*.iml
37+
.vs/
38+
*.suo
39+
*.user
40+
41+
# 测试和覆盖率
42+
*.coverprofile
43+
coverage.html
44+
coverage.txt
45+
vendor/
46+
47+
# 其他
48+
scripts/config*.yaml
49+
!.dockerignore
50+
Dockerfile*

scripts/Dockerfile.sreg-storage

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# 多阶段构建 - 构建阶段
2+
FROM golang:1.23-alpine AS builder
3+
4+
# 安装构建依赖和 CGO 所需的 C 库
5+
RUN apk add --no-cache \
6+
git \
7+
make \
8+
gcc \
9+
musl-dev \
10+
gpgme-dev \
11+
btrfs-progs-dev \
12+
lvm2-dev
13+
14+
# 设置工作目录
15+
WORKDIR /build
16+
17+
# 复制 go.mod 和 go.sum
18+
COPY go.mod go.sum ./
19+
20+
# 下载依赖
21+
RUN go mod download
22+
23+
# 复制源代码
24+
COPY . .
25+
26+
# 构建 sreg 二进制文件(使用 CGO 和正确的构建标签)
27+
RUN CGO_ENABLED=0 \
28+
go build \
29+
-tags "containers_image_openpgp netgo exclude_graphdriver_devicemapper osusergo exclude_graphdriver_btrfs" \
30+
-ldflags="-s -w" \
31+
-o sreg .
32+
33+
# 运行阶段
34+
FROM alpine:3.19
35+
36+
# 安装运行时依赖和 CGO 运行时库
37+
RUN apk add --no-cache \
38+
bash \
39+
python3 \
40+
py3-yaml \
41+
tar \
42+
gzip \
43+
ca-certificates \
44+
tzdata \
45+
gpgme \
46+
lvm2 \
47+
libressl
48+
49+
# 安装 rclone (直接使用 apk 包)
50+
RUN apk add --no-cache rclone
51+
52+
# 从构建阶段复制 sreg 二进制文件
53+
COPY --from=builder /build/sreg /usr/local/bin/sreg
54+
55+
# 复制脚本文件
56+
COPY scripts/sreg-storage.sh /usr/local/bin/sreg-storage.sh
57+
58+
# 设置脚本可执行权限
59+
RUN chmod +x /usr/local/bin/sreg-storage.sh && \
60+
chmod +x /usr/local/bin/sreg
61+
62+
# 创建工作目录
63+
RUN mkdir -p /tmp/sreg-storage
64+
65+
# 设置工作目录
66+
WORKDIR /tmp/sreg-storage
67+
68+
# 定义默认入口点
69+
ENTRYPOINT ["/usr/local/bin/sreg-storage.sh"]
70+
71+
# 默认命令(显示帮助信息)
72+
CMD ["--help"]

scripts/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,21 +124,31 @@ kubectl logs -l job-name=sreg-storage-load -f
124124
rclone:
125125
remote: "myremote"
126126
config:
127+
# 顶层写法也兼容,脚本会自动按运行参数处理
128+
no_check_certificate: true
129+
s3-no-check-bucket: true
127130
type: "s3"
128131
provider: "Other"
129132
endpoint: "https://objectstorage.example.com"
130133
access_key_id: "admin"
131134
secret_access_key: "secret"
132135
override:
133136
no_check_certificate: true
137+
s3-no-check-bucket: true
134138
```
135139

140+
推荐将运行时开关放在 `override` 或 `global` 下;如果直接写在 `rclone.config` 顶层,当前脚本也会兼容处理。
141+
136142
如果对象存储使用自签名证书,需确认:
137143

138144
- 服务端证书域名与访问域名一致
139145
- 证书链完整
140146
- 或显式允许跳过证书校验
141147

148+
如果对象存储不支持 bucket 存在性探测,需同时启用:
149+
150+
- `s3-no-check-bucket: true`
151+
142152
## 6. 清理与排查
143153

144154
查看任务:

scripts/job-load.example.yaml

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: batch/v1
22
kind: Job
33
metadata:
44
name: sreg-storage-load
5-
namespace: default
5+
namespace: ns-admin
66
spec:
77
ttlSecondsAfterFinished: 604800
88
backoffLimit: 1
@@ -13,14 +13,17 @@ spec:
1313
restartPolicy: Never
1414
containers:
1515
- name: sreg-storage
16-
image: your-registry/sreg-storage:latest
16+
image: registry.cn-hangzhou.aliyuncs.com/bxy4543/sreg-storage:0313.1655
1717
imagePullPolicy: IfNotPresent
1818
command: ["/usr/local/bin/sreg-storage.sh", "load", "--config=/config/config.yaml"]
1919
volumeMounts:
2020
- name: config
2121
mountPath: /config
2222
- name: tmp
2323
mountPath: /tmp/sreg-storage
24+
- name: image-cri-shim-config
25+
mountPath: /etc/image-cri-shim.yaml
26+
readOnly: true
2427
resources:
2528
requests:
2629
cpu: "500m"
@@ -35,30 +38,34 @@ spec:
3538
- name: tmp
3639
emptyDir:
3740
sizeLimit: 20Gi
41+
- name: image-cri-shim-config
42+
hostPath:
43+
path: /etc/image-cri-shim.yaml
44+
type: File
3845
---
3946
apiVersion: v1
4047
kind: ConfigMap
4148
metadata:
4249
name: sreg-storage-load-config
43-
namespace: default
50+
namespace: ns-admin
4451
data:
4552
config.yaml: |
4653
rclone:
4754
remote: "myremote"
4855
config:
4956
type: "s3"
5057
provider: "Other"
51-
endpoint: "https://objectstorage.example.com"
52-
access_key_id: "replace-me"
53-
secret_access_key: "replace-me"
54-
override:
55-
no_check_certificate: true
58+
endpoint: "objectstorageapi.192.168.10.70.nip.io"
59+
access_key_id: "admin"
60+
secret_access_key: "lvn25znf4tl5mtww"
61+
no_check_certificate: true
62+
s3-no-check-bucket: true
5663
tmp_dir: "/tmp/sreg-storage"
5764
load:
5865
source:
59-
remote: "myremote:admin-test-sreg/registry-backups/registry-20260312141027.tar.gz"
66+
remote: "myremote:admin-test-sreg/registry-backups/registry-20260313093103.tar.gz"
6067
extract_dir: "/tmp/sreg-storage/extracted"
6168
local_registry:
6269
port: 15001
6370
dest_registry:
64-
url: "localhost:5000"
71+
url: "sealos.hub:5000"

scripts/job-save.example.yaml

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: batch/v1
22
kind: Job
33
metadata:
44
name: sreg-storage-save
5-
namespace: default
5+
namespace: ns-admin
66
spec:
77
ttlSecondsAfterFinished: 604800
88
backoffLimit: 1
@@ -13,14 +13,17 @@ spec:
1313
restartPolicy: Never
1414
containers:
1515
- name: sreg-storage
16-
image: your-registry/sreg-storage:latest
16+
image: registry.cn-hangzhou.aliyuncs.com/bxy4543/sreg-storage:0313.1655
1717
imagePullPolicy: IfNotPresent
1818
command: ["/usr/local/bin/sreg-storage.sh", "save", "--config=/config/config.yaml"]
1919
volumeMounts:
2020
- name: config
2121
mountPath: /config
2222
- name: tmp
2323
mountPath: /tmp/sreg-storage
24+
- name: image-cri-shim-config
25+
mountPath: /etc/image-cri-shim.yaml
26+
readOnly: true
2427
resources:
2528
requests:
2629
cpu: "500m"
@@ -35,28 +38,31 @@ spec:
3538
- name: tmp
3639
emptyDir:
3740
sizeLimit: 20Gi
41+
- name: image-cri-shim-config
42+
hostPath:
43+
path: /etc/image-cri-shim.yaml
44+
type: File
3845
---
3946
apiVersion: v1
4047
kind: ConfigMap
4148
metadata:
4249
name: sreg-storage-save-config
43-
namespace: default
50+
namespace: ns-admin
4451
data:
4552
config.yaml: |
4653
rclone:
4754
remote: "myremote"
4855
config:
4956
type: "s3"
5057
provider: "Other"
51-
endpoint: "https://objectstorage.example.com"
52-
access_key_id: "replace-me"
53-
secret_access_key: "replace-me"
54-
override:
55-
no_check_certificate: true
58+
endpoint: "objectstorageapi.192.168.10.70.nip.io"
59+
access_key_id: "admin"
60+
secret_access_key: "lvn25znf4tl5mtww"
61+
no_check_certificate: true
62+
s3-no-check-bucket: true
5663
tmp_dir: "/tmp/sreg-storage"
5764
save:
5865
path: "admin-test-sreg/registry-backups"
66+
filename: "my-registry-test.tar.gz" # 可选: 自定义文件名,支持 {timestamp} 占位符
5967
images:
60-
- "nginx:latest"
61-
- "redis:7-alpine"
62-
- "busybox:latest"
68+
- "hello-world"

0 commit comments

Comments
 (0)