在单服务器搭最小规模的 CICD 的技术栈是什么

2024-11-02 17:23:06 +08:00
 importmeta

搞了个应用, 有前端, Node 后端, Redis, Postgres, Nginx, Grafana Loki Promtail.

用 Docker Compose 启动了一下, 每次发现改点代码都要手动把文件传上去构建镜像, 老麻烦了.

一看阿里云容器镜像服务, 收费还很贵, 不适合我.

谢谢了.

11581 次点击
所在节点    DevOps
67 条回复
agagega
2024-11-02 17:23:58 +08:00
Buildbot ?
tms
2024-11-02 17:42:19 +08:00
Gitea ?
RightHand
2024-11-02 17:46:30 +08:00
gitea+Jenkins 配合 docker 基本满足
iminto
2024-11-02 17:47:57 +08:00
jenkins,靠谱,不依赖 docker,离线部署
zhcode
2024-11-02 17:54:36 +08:00
只在公司用过 Jenkins ,轻量的话 听说 drone 不错
Livid
2024-11-02 17:55:42 +08:00
GitHub Action + 本地 runner
Cola98
2024-11-02 17:57:10 +08:00
makefile ?
crackidz
2024-11-02 18:06:25 +08:00
Github Action / GitLab Runner
KagurazakaNyaa
2024-11-02 18:07:49 +08:00
gitea+gitea runner ,兼容 GitHub Action 语法
参考写法
```yaml
services:
server:
image: gitea/gitea:latest
restart: always
ports:
- "3000:3000"
- "127.0.0.1:2222:22"
environment:
- USER_UID=998
- USER_GID=974
volumes:
- ./data:/data
- /home/git/.ssh/:/data/git/.ssh
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro

runner:
image: gitea/act_runner:latest
restart: always
depends_on:
- server
ports:
- "8088:8088"
volumes:
- ./runner_data:/data
- ./runner_config.yaml:/config.yaml
- /etc/localtime:/etc/localtime:ro
- /var/run/docker.sock:/var/run/docker.sock
environment:
- CONFIG_FILE=/config.yaml
- GITEA_INSTANCE_URL=[redacted]
- GITEA_RUNNER_REGISTRATION_TOKEN=[redacted]
- GITEA_RUNNER_NAME=default
```

其中 runner_config.yaml 是用于处理 cache 的,其内容类似于
```yaml
cache:
enabled: true
# dir: ""
# Use the LAN IP obtained in step 1
host: "10.10.10.12"
# Use the port number obtained in step 2
port: 8088
```

如果遇到问题可以参考 https://docs.gitea.com/zh-cn/usage/actions/overview 这里
另外有时候默认的标签会有问题,可以考虑修改./runner_data/.runner 里面的 labels 为
```json
"labels": [
"ubuntu-latest:docker://catthehacker/ubuntu:act-latest",
"ubuntu-22.04:docker://catthehacker/ubuntu:act-22.04",
"ubuntu-20.04:docker://catthehacker/ubuntu:act-20.04",
"ubuntu-18.04:docker://catthehacker/ubuntu:act-20.04"
]
```
KagurazakaNyaa
2024-11-02 18:12:08 +08:00
@Livid 站长可以考虑给评论区加上 markdown 支持吗,或者至少加个不会破坏缩进的代码块语法支持?
Ipsum
2024-11-02 18:24:18 +08:00
我都是 makefile 一把梭,本地构建然后 push 过去部署
yveJohn
2024-11-02 18:47:29 +08:00
gitea+drone 轻量又丝滑
bbchannails
2024-11-02 18:54:32 +08:00
idea 同步代码, sync to remote 就行. 特别适合解释型的语言, java 也可以, 但是要解开容器不要用 fat jar
FlytoSirius
2024-11-02 19:18:37 +08:00
别 Jenkins 了, 你会费心死的, 还是直接用 GitLab 吧
james122333
2024-11-02 19:23:22 +08:00
git hook scripts + shell
最迷你没有之一
https://githooks.com
gongquanlin
2024-11-02 19:28:39 +08:00
直接写 shell ;
```shell
#!/bin/bash

# 指定目标 IP 和用户
TARGET_IP="127.0.0.1" # 替换为目标服务器的 IP 地址
USER="root" # 替换为你的 SSH 用户名
PASSWORD="aasdf" # SSH 密码

# 本地文件路径
LOCAL_FILE="./dist/linux/main" # 本地文件路径
REMOTE_FILE="/home/opt/helloworld" # 远程文件路径

sshpass -p "${PASSWORD}" scp -O ${LOCAL_FILE} ${USER}@${TARGET_IP}:${REMOTE_FILE}
echo "upload ${TARGET_IP} success"
# 使用 sshpass 连接到指定 IP
sshpass -p "${PASSWORD}" ssh ${USER}@${TARGET_IP} << EOF
# 进入指定目录
cd /home/opt/

# 停止 Docker 容器
docker compose down

# 替换文件
cp ${REMOTE_FILE} main

# 启动 Docker 容器
docker compose up -d
EOF

echo "deploy ${TARGET_IP} success"
```
james122333
2024-11-02 19:29:36 +08:00
懂这个差不多就可以自己做一个类似 gitlab jenkins 的出来了
james122333
2024-11-02 19:47:49 +08:00
当有人讲 gitlab jenkins 等东西有多屌
你就可以跟他说 "少年 你对力量 一无所知"
hb0730
2024-11-02 19:50:59 +08:00
drone 还不错
SethShi
2024-11-02 20:01:00 +08:00
试试免费的 coding, 每个月好像有免费的机器给你构建, 基本都够我用.
像我的博客用 hugo, 在 coding 构建好 HTML, 直接部署

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://ex.noerr.eu.org/t/1086033

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX