Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions .github/workflows/build-docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Build Docker image

on:
push:
branches:
- main
workflow_dispatch:
inputs:
tag:
default: latest
description: 镜像的Tag, 默认额外添加latest
required: true
type: string

permissions:
contents: read
packages: write
id-token: write
attestations: write

env:
ARCHITECTURES: linux/amd64,linux/arm64
IMAGE_NAME: telegraph-image
IMAGE_DESCRIPTION: Built by GitHub Actions, the associated workflow is https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
LICENSES: MIT

jobs:
publish-image:
name: Build and publish
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
submodules: recursive

- name: Set env
env:
IMAGE_TAG: ${{ inputs.tag }}
run: |
owner=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')
echo "OWNER=$owner" >> "$GITHUB_ENV"
echo "IMAGE_FULL_NAME=ghcr.io/$owner/${{ env.IMAGE_NAME }}" >> $GITHUB_ENV
echo "DATE_TAG=$(date +'%Y.%m.%d')" >> $GITHUB_ENV
echo "IMAGE_TAG=${IMAGE_TAG:-latest}" >> $GITHUB_ENV

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ env.OWNER }}
password: ${{ github.token }}

- name: Extract metadata (tags, labels) for image registry
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_FULL_NAME }}
annotations: |
org.opencontainers.image.description=${{ env.IMAGE_DESCRIPTION }}
org.opencontainers.image.licenses=${{ env.LICENSES }}
org.opencontainers.image.title=${{ env.IMAGE_NAME }}
org.opencontainers.image.version=${{ env.IMAGE_TAG }}
labels: |
org.opencontainers.image.description=${{ env.IMAGE_DESCRIPTION }}
org.opencontainers.image.licenses=${{ env.LICENSES }}
org.opencontainers.image.title=${{ env.IMAGE_NAME }}
org.opencontainers.image.version=${{ env.IMAGE_TAG }}
env:
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build
uses: docker/build-push-action@v6
with:
context: .
file: docker/Dockerfile
push: true
tags: |
${{ env.IMAGE_FULL_NAME }}:${{ env.IMAGE_TAG }}
${{ env.IMAGE_FULL_NAME }}:${{ env.DATE_TAG }}
${{ github.event.inputs.image_tag != 'latest' && format('{0}:latest', env.IMAGE_FULL_NAME) || '' }}
annotations: ${{ steps.meta.outputs.annotations }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: ${{ env.ARCHITECTURES }}
26 changes: 22 additions & 4 deletions README-EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,31 @@ If you don't have a Telegram account yet, please create one first. Then, follow

## Deployment

### Preparation

The only thing you need to prepare in advance is a Cloudflare account
### Deployment to server (containerized deployment)

Download [docker-compose.example.yml](https://github.com/cf-pages/Telegraph-Image/blob/main/docker/docker-compose.example.yml), rename it to `docker-compose.yml`, and modify the configuration file as needed, using `docker compose up -d` to start the container.

```yaml
services:
telegraph-image:
image: ghcr.io/cf-pages/telegraph-image:latest
container_name: telegraph-image
ports:
- 8080:8080
volumes:
- ./data:/app/data
environment:
- BASIC_USER= # Dashboard Username, required
- BASIC_PASS= # Dashboard Password, required
- TG_Chat_ID= # Chat_ID, required
- TG_Bot_Token= # Bot_Token, required
- WhiteList_Mode=true # Whitelist mode, optional
- ModerateContentApiKey= # Image review API key, optional
```

### Step by Step Instruction

3 simple steps to deploy this project and have your own image hosting
0.Sign up for Cloudflare.

1.Fork this repository (Note: In order to make this work. You have to using Git or Wrangler CLI to deploy this project. [Document](https://developers.cloudflare.com/pages/functions/get-started/#deploy-your-function))

Expand Down
33 changes: 26 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,32 @@

## 如何部署

### 提前准备

你唯一需要提前准备的就是一个 Cloudflare 账户 (如果需要在自己的服务器上部署,不依赖 Cloudflare,可参考[#46](https://github.com/cf-pages/Telegraph-Image/issues/46) )

### 手把手教程

简单 3 步,即可部署本项目,拥有自己的图床
### 部署到服务器 (容器化部署)

下载 [docker-compose.example.yml](https://github.com/cf-pages/Telegraph-Image/blob/main/docker/docker-compose.example.yml),将其重命名为 `docker-compose.yml`,并根据需要修改配置文件,使用 `
docker compose up -d` 启动容器。

```yaml
services:
telegraph-image:
image: ghcr.io/cf-pages/telegraph-image:latest
container_name: telegraph-image
ports:
- 8080:8080
volumes:
- ./data:/app/data
environment:
- BASIC_USER= # Dashboard 用户名,必填
- BASIC_PASS= # Dashboard 密码,必填
- TG_Chat_ID= # Chat_ID,必填
- TG_Bot_Token= # Bot_Token,必填
- WhiteList_Mode=true # 是否开启白名单模式,选填
- ModerateContentApiKey= # 图片审查 API key,选填
```

### 部署到 Cloudflare Pages

0.注册 Cloudflare

1.Fork 本仓库 (注意:必须使用 Git 或者 Wrangler 命令行工具部署后才能正常使用,[文档](https://developers.cloudflare.com/pages/functions/get-started/#deploy-your-function))

Expand Down
9 changes: 9 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM node:24-bookworm-slim
WORKDIR /app
COPY . .
RUN mv ./docker/entrypoint.sh . \
&& apt-get update \
&& apt-get install -y ca-certificates \
&& rm -rf /var/lib/apt/lists/* \
&& npm install -g wrangler
ENTRYPOINT [ "bash", "./entrypoint.sh" ]
15 changes: 15 additions & 0 deletions docker/docker-compose.example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
services:
telegraph-image:
image: ghcr.io/cf-pages/telegraph-image:latest
container_name: telegraph-image
ports:
- 8080:8080
volumes:
- ./data:/app/data
environment:
- BASIC_USER=
- BASIC_PASS=
- TG_Chat_ID=
- TG_Bot_Token=
- WhiteList_Mode=true
- ModerateContentApiKey=
12 changes: 12 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
if [ -z "${BASIC_USER}" ] || [ -z "${BASIC_PASS}" ] || [ -z "${TG_Chat_ID}" ] || [ -z "${TG_Bot_Token}" ]; then
echo 缺少必要的参数
exit 1
fi

wrangler pages dev ./ --kv "img_url" --ip 0.0.0.0 --port 8080 --persist-to ./data \
--binding "BASIC_USER=$BASIC_USER" \
--binding "BASIC_PASS=$BASIC_PASS" \
--binding "TG_Chat_ID=$TG_Chat_ID" \
--binding "TG_Bot_Token=$TG_Bot_Token" \
${ModerateContentApiKey:+--binding "ModerateContentApiKey=$ModerateContentApiKey"} \
${WhiteList_Mode:+--binding "WhiteList_Mode=$WhiteList_Mode"}