Skip to content

Commit

Permalink
Merge pull request #22 from fordes123/dev
Browse files Browse the repository at this point in the history
ci: 👷 新增本地开发环境
  • Loading branch information
fordes123 authored Sep 5, 2024
2 parents 1e729af + b9b27eb commit 4bf7a04
Show file tree
Hide file tree
Showing 7 changed files with 395 additions and 2 deletions.
13 changes: 13 additions & 0 deletions .docker/caddy/Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
http://*:80 {
root * /var/www/html/typecho
encode gzip
@disallowed {
path_regexp forbidden_files "^/(\.user\.ini|\.htaccess|\.git|\.svn|\.project|LICENSE.*|README.*)$"
}
rewrite @disallowed /index.php

php_fastcgi php-fpm:9000
file_server {
index index.html
}
}
13 changes: 13 additions & 0 deletions .docker/caddy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM caddy/caddy:alpine

VOLUME [ "/var/www/typecho" ]
COPY config.inc.php /var/www/html/typecho/

RUN apk update \
&& apk add alpine-conf wget unzip --no-cache \
&& /sbin/setup-timezone -z Asia/Shanghai \
&& wget https://github.com/typecho/typecho/releases/latest/download/typecho.zip \
&& mkdir -p /var/www/html/typecho \
&& unzip typecho.zip -d /var/www/html/typecho \
&& rm typecho.zip \
&& apk del alpine-conf wget unzip
33 changes: 33 additions & 0 deletions .docker/caddy/config.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
// site root path
define('__TYPECHO_ROOT_DIR__', dirname(__FILE__));

// plugin directory (relative path)
define('__TYPECHO_PLUGIN_DIR__', '/usr/plugins');

// theme directory (relative path)
define('__TYPECHO_THEME_DIR__', '/usr/themes');

// admin directory (relative path)
define('__TYPECHO_ADMIN_DIR__', '/admin/');

// register autoload
require_once __TYPECHO_ROOT_DIR__ . '/var/Typecho/Common.php';

// init
\Typecho\Common::init();

// config db
$db = new \Typecho\Db('Pdo_Mysql', 'item_');
$db->addServer(array (
'host' => 'mysql',
'port' => 3306,
'user' => 'typecho',
'password' => '12345678',
'charset' => 'utf8mb4',
'database' => 'typecho',
'engine' => 'InnoDB',
'sslCa' => '',
'sslVerify' => false,
), \Typecho\Db::READ | \Typecho\Db::WRITE);
\Typecho\Db::set($db);
58 changes: 58 additions & 0 deletions .docker/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
networks:
default:
external: false
name: typecho-debug

volumes:
typecho:

services:
mysql:
image: mysql:8.0
container_name: mysql
restart: always
volumes:
- ./mysql:/docker-entrypoint-initdb.d/
environment:
TZ: Asia/Shanghai
MYSQL_DATABASE: typecho
MYSQL_USER: typecho
MYSQL_PASSWORD: 12345678
MYSQL_ROOT_PASSWORD: 12345678
command:
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_unicode_ci
networks:
- default

caddy:
build: ./caddy
container_name: caddy
restart: always
environment:
TZ: Asia/Shanghai
volumes:
- ./caddy/Caddyfile:/etc/caddy/Caddyfile
- ../:/var/www/html/typecho/usr/themes/ITEM
- typecho:/var/www/html/typecho:copy
ports:
- 80:80
depends_on:
- php-fpm
networks:
- default

php-fpm:
build: ./php-fpm
container_name: php-fpm
restart: always
environment:
TZ: Asia/Shanghai
volumes:
- ../:/var/www/html/typecho/usr/themes/ITEM
- typecho:/var/www/html/typecho:rw
networks:
- default
depends_on:
- mysql

258 changes: 258 additions & 0 deletions .docker/mysql/typecho.sql

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions .docker/php-fpm/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM php:8.1.13-fpm-alpine
RUN apk update \
&& apk add alpine-conf --no-cache \
&& /sbin/setup-timezone -z Asia/Shanghai \
&& apk del alpine-conf \
&& docker-php-ext-install pdo pdo_mysql calendar \
&& printf '[PHP]\ndate.timezone = Asia/Shanghai\n' >/usr/local/etc/php/conf.d/tzone.ini
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<h2 id='2'>🛠️ 快速开始</h2>

<a href="https://vercel.com/new/clone?project-name=ITEM-vercel&repository-name=ITEM-vercel&repository-url=https://github.com/fordes123/ITEM-vercel&from=templates&integration-ids=oac_coKBVWCXNjJnCEth1zzKoF1j"><img src="https://vercel.com/button"></a>
> 通过 Vercel 托管需要添加一个 MySQL 集成,如 [TiDB](https://tidbcloud.com/)[PlanetScale](https://planetscale.com/),参考: [Vercel 托管 Typecho](https://www.fordes.top/posts/tutorials/typecho-vercel/)
> 通过 Vercel 托管需要添加一个 MySQL 集成,如 [TiDB](https://tidbcloud.com/)[PlanetScale](https://planetscale.com/),参考: [Vercel 托管 Typecho](https://www.fordes.dev/posts/tutorials/typecho-vercel/)
### 本地部署

Expand All @@ -65,6 +65,17 @@
2. 将主题文件重名为 <code>ITEM</code> 并移动至 Typecho 根目录<code>usr/themes</code> 文件夹中
3. 在 Typecho 管理面板中选择更换外观并启用主题

### 本地开发

安装 Docker 以及 Docker Compose 后,在项目根目录下执行以下命令:
```shell
cd .docker
docker compose up -d
```
打开浏览器即可访问 `http://localhost:80`,账号: `dev`,密码: `12345678`

(该配置仅用于开发和测试,请勿直接用于生产环境)

---

### 配置说明
Expand Down Expand Up @@ -135,7 +146,7 @@

Issues - [https://github.com/fordes123/ITEM/issues](https://github.com/fordes123/ITEM/issues)

博客 - [https://fordes.top](https://fordes.top)
博客 - [https://fordes.dev](https://fordes.dev)

---

Expand Down

0 comments on commit 4bf7a04

Please sign in to comment.