私有化编译alist并构建docker镜像到云端
涉及的工具及网站
GitHub code space
GitHub codespace 默认配置好了一些开发环境,使用起来简单方便(alist 运行依赖环境:git nodejs pnpm gcc golang 1.20+)
云服务器一台
这里我使用的是阿里云esc alibaba cloud 3.2+
1panel 管理面板
凭借容器化部署和可视化界面深得我心
镜像仓库
我使用的是阿里云提供的免费镜像仓库
在codespace 中创建项目
打开Build software better, together创建一个空白模板

初始化项目
快捷键ctrl+~打开终端
使用git分别拉取
前端项目alist-web
后端项目alist
1 2
| git clone https://github.com/alist-org/alist.git git clone --recurse-submodules https://github.com/alist-org/alist-web.git
|
使用npm安装pnpm
由于最新代码版本不附带中文包,下载语言文件并且初始化
1 2 3 4 5
| cd alist-web wget https://crowdin.com/backend/download/project/alist/zh-CN.zip unzip zh-CN.zip node ./scripts/i18n.mjs rm zh-CN.zip
|

这里我执行解压报错,问题暂不深究,将zip下载到本地然后将zh-CN文件夹上传到 项目路径/alist-web/src/lang/
再执行
魔改alist
由于地区网安要求,博客备案域名下不允许出现登录、游客字样仅作为私人管理使用,遂将配置文字修改

其他魔改请参考
https://anwen-anyi.github.io/index/03-code.html
无需重新编译美化-https://blog.imoeq.com/alist-v3-ui-modify/
编译前端
安装前端所需依赖
1
| pnpm install && pnpm run build
|
将编译好的前端文件复制到后端public目录下
1
| cp -r /workspaces/codespaces-blank/alist-web/dist /workspaces/codespaces-blank/alist/public/
|
编译后端
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| cd ./alist appName="alist" builtAt="$(date +'%F %T %z')" goVersion=$(go version | sed 's/go version //') gitAuthor=$(git show -s --format='format:%aN <%ae>' HEAD) gitCommit=$(git log --pretty=format:"%h" -1) version=$(git describe --long --tags --dirty --always) webVersion=$(wget -qO- -t1 -T2 "https://api.github.com/repos/alist-org/alist-web/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g') ldflags="\ -w -s \ -X 'github.com/alist-org/alist/v3/internal/conf.BuiltAt=$builtAt' \ -X 'github.com/alist-org/alist/v3/internal/conf.GoVersion=$goVersion' \ -X 'github.com/alist-org/alist/v3/internal/conf.GitAuthor=$gitAuthor' \ -X 'github.com/alist-org/alist/v3/internal/conf.GitCommit=$gitCommit' \ -X 'github.com/alist-org/alist/v3/internal/conf.Version=$version' \ -X 'github.com/alist-org/alist/v3/internal/conf.WebVersion=$webVersion' \ " go build -ldflags="$ldflags" .
|
首次编译较慢大概需要两分钟多,请耐心等待
运行测试
编译结束后会生成文件名为alist的二进制文件在alist项目根目录下
先授权
输入指令获取随机生成的管理员密码
启动alist服务
右下角会弹出在浏览器中打开,点击打开后即可看到正常的alist界面
构建doker镜像
由于官方配置会默认拉取最新release代码,需要修改配置
将build.sh文件内FetchWebRelease函数内处理删除,我将函数体变为空后执行构建一直在报错,问题暂不深究,将函数体改为脱裤子放屁模式~
1 2 3 4
| FetchWebRelease() { curl -L https://github.com/alist-org/alist-web/releases/latest/download/dist.tar.gz -o dist.tar.gz rm -rf dist.tar.gz }
|
执行命令构建镜像(注意:不要忘记命令末尾的那个.)
1
| docker build -t 你要构建的镜像名字 -f Dockerfile .
|
查看镜像imageid
执行命令将镜像推送到阿里仓库,在阿里云容器镜像服务/实例列表/镜像仓库/基本信息 页面中有将镜像推送到Registry的指南
1 2 3
| docker login --username=你的阿里云用户名 registry.cn-hangzhou.aliyuncs.com docker tag [ImageId] registry.cn-hangzhou.aliyuncs.com/命名空间/仓库名称:[镜像版本号] docker push registry.cn-hangzhou.aliyuncs.com/命名空间/仓库名称:[镜像版本号]
|
验证一下阿里云仓库地址内有没有刚才推送的镜像版本
部署到云服务器
在云服务器终端执行命令从Registry中拉取镜像
1
| docker pull registry.cn-hangzhou.aliyuncs.com/命名空间/仓库名称:[镜像版本号]
|
在1panel面板 容器管理页面创建容器,并配置暴露端口(alist官方默认编译后的端口是5244)

将容器内数据文件挂载到外部
/opt/1panel/apps/alist/alist/data/data /opt/alist/data
/opt/1panel/apps/alist/alist/data/mnt /mnt/data

填写command、标签、环境变量(不知道有什么用,参照1panel应用alist1配置来的)
command:‘/entrypoint.sh’

标签内容
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| com.docker.compose.depends_on= org.opencontainers.image.revision=d4e3355f5692a690a8aa02298b0052e4340a3e55 org.opencontainers.image.url=https://github.com/alist-org/alist org.opencontainers.image.version=v3.36.0 com.docker.compose.config-hash=3868afa4655e032df82c0ae42c186a9b33e03b3d6559d096d36e1eb888bd7be6 com.docker.compose.project=alist com.docker.compose.service=alist createdBy=Apps org.opencontainers.image.description=🗂️A file list/WebDAV program that supports multiple storages, powered by Gin and Solidjs. / 一个支持多存储的文件列表/WebDAV程序,使用 Gin 和 Solidjs。 org.opencontainers.image.licenses=AGPL-3.0 MAINTAINER=i@nn.ci com.docker.compose.replace=100820f7405ba85e968546182f6ef21fe9e39d0c2460208dda0ace7251901ab8 com.docker.compose.version=2.26.1 org.opencontainers.image.created=2024-07-21T13:20:54.553Z org.opencontainers.image.source=https://github.com/alist-org/alist org.opencontainers.image.title=alist com.docker.compose.oneoff=False com.docker.compose.image=sha256:572986ca753db18a6be3a4dec9f75eaf580a639f9d6ff90ff4de94d537526c4f com.docker.compose.project.config_files=/opt/1panel/apps/alist/alist/docker-compose.yml com.docker.compose.project.working_dir=/opt/1panel/apps/alist/alist com.docker.compose.container-number=1
|
环境变量
1 2 3 4
| PUID=0 PGID=0 UMASK=022 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
最后,启动容器通过ip:5244即可访问服务
附录
本文参考博客
https://anwen-anyi.github.io/index/build/linux.html
遇到问题
1.页面报错
System error: TypeError: Failed to fetch dynamically imported module: https://domain.cn/assets/Folder.442462a1.js
奇怪的是过一会又自己好了


问题待解决