AI 摘要
编译部署开源 JSON 工具 json4u,因数据敏感弃用公网服务,替换默认 CDN 后 fork 仓库,配置 Docker Hub 密钥并编写 GitHub Actions 构建镜像,再用 docker-compose 启动及设置反向代理。

一、引子

很早就看到过这个开源项目,不过一直没用到,今天正好有个处理 JSON 的需求,并且因为数据比较敏感,不能使用公网的在线服务,所以只好自己部署一个。顺带编译成 docker 镜像。

二、编译

优化,默认使用有投毒黑历史的CDN,顺带替换掉。cdn.bootcdn.net

  1. fork 仓库
  2. 绑定仓库密钥用于上传 docker 镜像
    • DOCKERHUB_USERNAME
    • DOCKERHUB_TOKEN
  3. 编写构建文件 .github/workflows/docker-publish.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
name: Build and Push Docker Image

on:
push:
branches: [main]
tags: ["v*.*.*"]
workflow_dispatch:

env:
IMAGE_NAME: qiankong/json4u

jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Patch unsafe CDN (bootcdn -> cdnjs)
run: |
files=$(grep -rIl "bootcdn.net" --exclude-dir=.git . || true)
if [ -n "$files" ]; then
echo "Patching bootcdn.net references in:"
echo "$files"
echo "$files" | xargs sed -i 's/cdn\.bootcdn\.net/cdnjs.cloudflare.com/g'
else
echo "No bootcdn.net references found, nothing to patch."
fi

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Extract metadata (tags, labels)
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=semver,pattern={{version}}
type=sha,prefix=,format=short

- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
APP_URL=https://json4u.bravexist.cn
no-cache: true

三、部署

  1. 编写 docker-compose.yaml
1
2
3
4
5
6
7
services:
json4u:
image: qiankong/json4u:latest
container_name: json4u
ports:
- "65003:3000"
restart: unless-stopped
  1. 启动
1
docker compose up -d
  1. 设置反向代理

四、效果

https://json4u.bravexist.cn/

效果图