Skip to content

Commit

Permalink
docs: runing with docker compose (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
jinganix authored Jan 28, 2024
1 parent ddfb828 commit b233839
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 31 deletions.
63 changes: 46 additions & 17 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,67 @@

# Guess

The source code of the 'Guess Who I Am' Wechat miniprogram
The source code of the 'Guess Who I Am' Wechat miniprogram.

## Run
- Frontend development using `TypeScript` with `webpack` for building and bundling
- Backend development using `Java` and `Spring` framework with `Gradle` for building and packaging

### Backend
## Running the Project

#### Linux or MacOS
To run the project, you need to first clone the source code and navigate to the project's root directory.

```shell
git clone git@github.com:jinganix/guess.git
cd guess/service/guess
./gradlew service:guess:bootRun --args='--core.weapp.app-id=? --core.weapp.app-secret=? --core.url.db-mysql=? --spring.datasource.username=? --spring.datasource.password=?'
cd guess
```

### Backend

#### Running with docker-compose

- Modify the [application-local.yml](service/guess/src/main/resources/application-local.yml) file to configure the backend service of the project

- core.weapp.app-id: The `app-id` of the WeChat mini-program
- core.weapp.app-secret: The `app-secret` of the WeChat mini-program

If you have `docker` and `docker-compose` installed, you can start the backend service using the following command:

```shell
docker-compose up
```

#### Windows
#### Running with Gradle

Replace `./gradlew` with `./gradlew.bat`
You need to install JDK with the corresponding version specified in [.tool-versions](.tool-versions) and start a MySQL database.

#### Description
Modify the application-local.yml file to configure the backend services of the project.

- core.weapp.app-id: `app-id` of the Wechat miniprogram
- core.weapp.app-secret: `app-secret` of the Wechat miniprogram
- core.url.db-mysql: Mysql connection url,e.g. `jdbc:mysql://127.0.0.1:3306/guess`
- spring.datasource.username: Mysql connection username
- spring.datasource.password: Mysql connection password
- core.weapp.app-id: The `app-id` of the WeChat mini-program
- core.weapp.app-secret: The `app-secret` of the WeChat mini-program
- core.url.db-mysql: The connection URL of the MySQL database, e.g., `jdbc:mysql://127.0.0.1:3306/guess`
- spring.datasource.username: The database username
- spring.datasource.password: The database password

The following command can be used to start the backend services on a Linux or macOS system:

```shell
./gradlew service:guess:bootRun'
```
The following command can be used to start the backend services on a Windows system:
```shell
./gradlew.bat service:guess:bootRun'
```

### Frontend

#### Execute commands
You need to install [node.js](https://nodejs.org/en) with the version specified in [.tool-versions](.tool-versions).

#### Running the Commands

```shell
git@github.com:jinganix/guess.git
git clone git@github.com:jinganix/guess.git
cd guess/frontend/weapp
npm install
npm start
Expand All @@ -45,7 +74,7 @@ npm start
1. Import`guess/frontend/weapp/dist` into Wechat devtools
2. Disable domain verification

<img src="docs/devtools.setting.png" alt="Image" width="381" height="576">
<img src="docs/devtools.setting.en.png" alt="Image" width="381" height="576">

## Scan to experience

Expand Down
49 changes: 38 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,69 @@
[![CI](https://github.com/jinganix/guess/actions/workflows/ci.yml/badge.svg)](https://github.com/jinganix/guess/actions/workflows/ci.yml)
[![License](http://img.shields.io/:license-apache-brightgreen.svg)](http://www.apache.org/licenses/LICENSE-2.0.html)

[English Doc](README.en.md)

# 猜我是谁

`猜我是谁`微信小程序源码

- 前端使用`Typescript`开发,用`webpack`构建打包
- 后端使用`Java``Spring`框架开发,用`gradle`构建打包

## 运行项目

你需要先拉取项目源码,然后切换到项目根目录

```shell
git clone git@github.com:jinganix/guess.git
cd guess
```

### 后端

#### Linux和MacOS
#### 通过docker-compose运行

修改[application-local.yml](service/guess/src/main/resources/application-local.yml)以运行项目后端服务

- core.weapp.app-id: 微信小程序的`app-id`
- core.weapp.app-secret: 微信小程序的`app-secret`

如果你已经安装`docker``docker-compose`,可以通过以下命令启动后端服务

```shell
git clone git@github.com:jinganix/guess.git
cd guess/service/guess
./gradlew service:guess:bootRun --args='--core.weapp.app-id=? --core.weapp.app-secret=? --core.url.db-mysql=? --spring.datasource.username=? --spring.datasource.password=?'
docker-compose up
```

#### Windows
#### 通过gradle运行

使用`./gradlew.bat`代替`./gradlew`
你需要安装jdk,对应的版本在[.tool-versions](.tool-versions),并启动mysql数据库

#### 参数说明
修改[application-local.yml](service/guess/src/main/resources/application-local.yml)以运行项目后端服务

- core.weapp.app-id: 微信小程序的`app-id`
- core.weapp.app-secret: 微信小程序的`app-secret`
- core.url.db-mysql: mysql数据库连接地址,如`jdbc:mysql://127.0.0.1:3306/guess`
- spring.datasource.username: 数据库用户名
- spring.datasource.password: 数据库密码

以下命令可以在`Linux``MacOd`系统中启动后端服务

```shell
./gradlew service:guess:bootRun'
```
以下命令可以在`Windows`系统中启动后端服务
```shell
./gradlew.bat service:guess:bootRun'
```

### 前端

你需要安装[node.js](https://nodejs.org/en),对应的版本在[.tool-versions](.tool-versions)

#### 运行命令

```shell
git@github.com:jinganix/guess.git
git clone git@github.com:jinganix/guess.git
cd guess/frontend/weapp
npm install
npm start
Expand All @@ -55,4 +82,4 @@ npm start

## 贡献

如果您有兴趣报告/修复问题并直接为代码库做出贡献,请查看 [CONTRIBUTING.md](CONTRIBUTING.md) 获取更多信息,了解我们期望的贡献内容以及如何开始。
如果你有兴趣报告/修复问题并直接为代码库做出贡献,请查看 [CONTRIBUTING.md](CONTRIBUTING.md) 获取更多信息,了解我们期望的贡献内容以及如何开始。
34 changes: 34 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
version: "3.1"
services:
guess-mysql:
build: docs/mysql
image: guess/mysql
command: --default-authentication-plugin=mysql_native_password
environment:
MYSQL_ROOT_PASSWORD: root
ports:
- "3316:3306"
volumes:
- data-mysql:/var/lib/mysql

guess-service:
build: service/guess
image: guess/service
depends_on:
guess-mysql:
condition: service_started
environment:
JAVA_OPTS: >
-Xss512k
-XX:MaxRAM=260m
-Dspring.profiles.active=local
-Dspring.datasource.password=root
-Dcore.url.db-mysql=jdbc:mysql://guess-mysql/guess?allowPublicKeyRetrieval=true&useSSL=false
ports:
- "8080:8080"
volumes:
- data-app:/app/guess

volumes:
data-app:
data-mysql:
Binary file added docs/devtools.setting.en.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions docs/mysql/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM mysql:8.2.0

COPY mysql.cnf /etc/mysql/mysql.conf.d/mysql.cnf
COPY init.sql /docker-entrypoint-initdb.d/init.sql
1 change: 1 addition & 0 deletions docs/mysql/init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE DATABASE IF NOT EXISTS `guess` COLLATE utf8mb4_unicode_ci;
17 changes: 17 additions & 0 deletions docs/mysql/mysql.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
#log-error = /var/log/mysql/error.log
# By default we only accept connections from localhost
#bind-address = 127.0.0.1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

#### These optimize the memory use of MySQL
#### http://www.tocker.ca/2014/03/10/configuring-mysql-to-use-minimal-memory.html
innodb_buffer_pool_size=32M
innodb_log_buffer_size=512K

#### from https://mariadb.com/de/node/579
performance_schema = off
2 changes: 1 addition & 1 deletion frontend/weapp/webpack/env/prod.env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { Environment } from "./env";

export const environment: Environment = {
env: "prod",
host: "http://192.168.3.46:8080",
host: "http://localhost:8080",
};
10 changes: 10 additions & 0 deletions service/guess/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM openjdk:21-jdk

RUN rm -f /etc/localtime && \
ln -sv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo "Asia/Shanghai" > /etc/timezone

ADD ./build/libs/guess-service.jar /opt/app/
CMD java $JAVA_OPTS -jar /opt/app/guess-service.jar

EXPOSE 8080
5 changes: 4 additions & 1 deletion service/guess/src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
core:
jwt-secret: test-jwt-secret
url:
db-mysql: jdbc:mysql://127.0.0.1:3306/guess
weapp:
app-id: fake-app-id
app-secret: fake-app-secret

spring:
datasource:
username: root
password: root
3 changes: 2 additions & 1 deletion service/guess/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ core:
config:
puzzle-daily-limit: 30
puzzle-limit-increase: 20
static-url: http://127.0.0.1:8080/static/
jwt-secret: test-jwt-secret
url:
db-mysql: jdbc:mysql://127.0.0.1:3306/guess
weapp:
app-id: fake-app-id
app-secret: fake-app-secret

server:
port: 8080
Expand Down

0 comments on commit b233839

Please sign in to comment.