Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 5a8157f

Browse files
committed
Initial commit
1 parent 3583630 commit 5a8157f

File tree

11 files changed

+1356
-0
lines changed

11 files changed

+1356
-0
lines changed

.env.template

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
PORT=3000
2+
API_KEYS=sk-key1,sk-key2
3+
DEBUG_MODE=false
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
name: Update Version & Docker Build And Push
2+
on:
3+
push:
4+
tags:
5+
- 'v*'
6+
branches:
7+
- 'beta'
8+
9+
env:
10+
REGISTRY: ghcr.io
11+
IMAGE_NAME: ${{ github.repository }}
12+
13+
jobs:
14+
update-version:
15+
if: startsWith(github.ref, 'refs/tags/v')
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: write
19+
outputs:
20+
commit_sha: ${{ steps.get_sha.outputs.sha }}
21+
steps:
22+
- uses: actions/checkout@v3
23+
with:
24+
fetch-depth: 0
25+
token: ${{ secrets.PAT_TOKEN }}
26+
27+
- name: Update Version
28+
run: |
29+
VERSION=${GITHUB_REF#refs/tags/v}
30+
sed -i "s/const VERSION = '.*'/const VERSION = '$VERSION'/" index.js
31+
32+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
33+
git config --local user.name "github-actions[bot]"
34+
git add index.js
35+
git commit -m "chore: update version to $VERSION"
36+
git push origin HEAD:main
37+
38+
- name: Get commit SHA
39+
id: get_sha
40+
run: echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
41+
42+
build-and-push:
43+
needs: [update-version]
44+
if: |
45+
always() &&
46+
(needs.update-version.result == 'success' || needs.update-version.result == 'skipped')
47+
runs-on: ubuntu-latest
48+
49+
permissions:
50+
contents: read
51+
packages: write
52+
id-token: write
53+
54+
steps:
55+
- name: Determine ref
56+
id: determine_ref
57+
run: |
58+
if [[ "${{ needs.update-version.result }}" == "skipped" ]]; then
59+
echo "ref=beta" >> $GITHUB_OUTPUT
60+
else
61+
echo "ref=${{ needs.update-version.outputs.commit_sha }}" >> $GITHUB_OUTPUT
62+
fi
63+
64+
- name: Checkout repository
65+
uses: actions/checkout@v4
66+
with:
67+
ref: ${{ steps.determine_ref.outputs.ref }}
68+
fetch-depth: 0
69+
70+
- name: Set up QEMU
71+
uses: docker/setup-qemu-action@v3
72+
with:
73+
platforms: 'arm64,amd64'
74+
75+
- name: Set up Docker Buildx
76+
uses: docker/setup-buildx-action@v3
77+
with:
78+
platforms: linux/amd64,linux/arm64
79+
80+
- name: Log in to the Container registry
81+
uses: docker/login-action@v3
82+
with:
83+
registry: ${{ env.REGISTRY }}
84+
username: ${{ github.actor }}
85+
password: ${{ secrets.PAT_TOKEN }}
86+
87+
- name: Extract metadata for Docker
88+
id: meta
89+
uses: docker/metadata-action@v5
90+
with:
91+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
92+
tags: |
93+
type=raw,value=beta,enable=${{ github.ref == 'refs/heads/beta' }}
94+
type=ref,event=branch
95+
type=ref,event=pr
96+
type=semver,pattern={{version}}
97+
type=semver,pattern={{major}}.{{minor}}
98+
type=sha
99+
100+
- name: Build and push Docker image
101+
uses: docker/build-push-action@v5
102+
with:
103+
context: .
104+
push: true
105+
tags: ${{ steps.meta.outputs.tags }}
106+
labels: ${{ steps.meta.outputs.labels }}
107+
cache-from: type=gha
108+
cache-to: type=gha,mode=max
109+
platforms: linux/amd64,linux/arm64
110+
provenance: false
111+
sbom: false
112+
build-args: |
113+
BUILDKIT_STEP_LOG_MAX_SIZE=10485760
114+
BUILDKIT_STEP_LOG_MAX_SPEED=10485760
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Build & Deploy Worker
2+
on:
3+
push:
4+
branches:
5+
- cf
6+
repository_dispatch:
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
timeout-minutes: 60
12+
steps:
13+
- uses: actions/checkout@v3
14+
with:
15+
ref: cf
16+
- name: Build & Deploy Worker
17+
uses: cloudflare/wrangler-action@v3
18+
with:
19+
apiToken: ${{ secrets.CF_API_TOKEN }}
20+
accountId: ${{ secrets.CF_ACCOUNT_ID }}
21+
command: deploy

.gitignore

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
.idea
2+
.vscode
3+
4+
### Node template
5+
# Logs
6+
logs
7+
*.log
8+
npm-debug.log*
9+
yarn-debug.log*
10+
yarn-error.log*
11+
lerna-debug.log*
12+
.pnpm-debug.log*
13+
14+
# Diagnostic reports (https://nodejs.org/api/report.html)
15+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
16+
17+
# Runtime data
18+
pids
19+
*.pid
20+
*.seed
21+
*.pid.lock
22+
23+
# Directory for instrumented libs generated by jscoverage/JSCover
24+
lib-cov
25+
26+
# Coverage directory used by tools like istanbul
27+
coverage
28+
*.lcov
29+
30+
# nyc test coverage
31+
.nyc_output
32+
33+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
34+
.grunt
35+
36+
# Bower dependency directory (https://bower.io/)
37+
bower_components
38+
39+
# node-waf configuration
40+
.lock-wscript
41+
42+
# Compiled binary addons (https://nodejs.org/api/addons.html)
43+
build/Release
44+
45+
# Dependency directories
46+
node_modules/
47+
jspm_packages/
48+
49+
# Snowpack dependency directory (https://snowpack.dev/)
50+
web_modules/
51+
52+
# TypeScript cache
53+
*.tsbuildinfo
54+
55+
# Optional npm cache directory
56+
.npm
57+
58+
# Optional eslint cache
59+
.eslintcache
60+
61+
# Optional stylelint cache
62+
.stylelintcache
63+
64+
# Microbundle cache
65+
.rpt2_cache/
66+
.rts2_cache_cjs/
67+
.rts2_cache_es/
68+
.rts2_cache_umd/
69+
70+
# Optional REPL history
71+
.node_repl_history
72+
73+
# Output of 'npm pack'
74+
*.tgz
75+
76+
# Yarn Integrity file
77+
.yarn-integrity
78+
79+
# dotenv environment variable files
80+
.env
81+
.env.development.local
82+
.env.test.local
83+
.env.production.local
84+
.env.local
85+
86+
# parcel-bundler cache (https://parceljs.org/)
87+
.cache
88+
.parcel-cache
89+
90+
# Next.js build output
91+
.next
92+
out
93+
94+
# Nuxt.js build / generate output
95+
.nuxt
96+
dist
97+
98+
# Gatsby files
99+
.cache/
100+
# Comment in the public line in if your project uses Gatsby and not Next.js
101+
# https://nextjs.org/blog/next-9-1#public-directory-support
102+
# public
103+
104+
# vuepress build output
105+
.vuepress/dist
106+
107+
# vuepress v2.x temp and cache directory
108+
.temp
109+
110+
111+
# Docusaurus cache and generated files
112+
.docusaurus
113+
114+
# Serverless directories
115+
.serverless/
116+
117+
# FuseBox cache
118+
.fusebox/
119+
120+
# DynamoDB Local files
121+
.dynamodb/
122+
123+
# TernJS port file
124+
.tern-port
125+
126+
# Stores VSCode versions used for testing VSCode extensions
127+
.vscode-test
128+
129+
# yarn v2
130+
.yarn/cache
131+
.yarn/unplugged
132+
.yarn/build-state.yml
133+
.yarn/install-state.gz
134+
.pnp.*
135+

Dockerfile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# 构建阶段
2+
FROM node:18-alpine AS builder
3+
4+
# 安装 pnpm
5+
RUN corepack enable && corepack prepare pnpm@latest --activate
6+
7+
WORKDIR /app
8+
9+
# 只复制依赖相关文件
10+
COPY package*.json pnpm-lock.yaml ./
11+
12+
# 安装依赖,添加 --prod 来排除开发依赖
13+
RUN pnpm install --prod --frozen-lockfile
14+
15+
# 运行阶段 - 使用更小的基础镜像
16+
FROM alpine:3.19
17+
18+
# 安装 Node.js 运行环境
19+
RUN apk add --no-cache nodejs
20+
21+
# 设置工作目录
22+
WORKDIR /app
23+
24+
# 创建非 root 用户
25+
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
26+
27+
# 从构建阶段复制依赖
28+
COPY --from=builder /app/node_modules ./node_modules
29+
30+
# 只复制必要的应用代码
31+
COPY index.js ./
32+
COPY package.json ./
33+
34+
# 切换到非 root 用户
35+
USER appuser
36+
37+
# 暴露端口
38+
EXPOSE 3000
39+
40+
# 启动命令
41+
CMD ["node", "index.js"]

README.md.lnk

768 Bytes
Binary file not shown.

docker-compose.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
services:
2+
ddg2api:
3+
image: ghcr.io/meethuhu/ddg2api:latest
4+
container_name: ddg2api
5+
ports:
6+
- '3000:3000'
7+
environment:
8+
- API_KEYS=your_api_key # 替换为你的API密钥
9+
- TZ=Asia/Shanghai
10+
restart: always

0 commit comments

Comments
 (0)