2022-09-27 17:59:05 +08:00
# How to build and install
2022-09-29 11:49:16 +08:00
2022-09-29 16:23:13 +08:00
Before installing Answer, you need to install the base environment first.
- database
- [MySQL ](http://dev.mysql.com ) Version >= 5.7
2022-09-29 11:49:16 +08:00
2022-09-29 16:23:13 +08:00
You can then install Answer in several ways:
2022-09-29 11:49:16 +08:00
2022-09-29 16:23:13 +08:00
- Deploy with Docker
- binary installation
- Source installation
2022-09-29 11:49:16 +08:00
## Docker for Answer
Visit Docker Hub or GitHub Container registry to see all available images and tags.
### Usage
To keep your data out of Docker container, we do a volume (/var/data -> /data) here, and you can change it based on your situation.
```
# Pull image from Docker Hub.
$ docker pull answer/answer
# Create local directory for volume.
$ mkdir -p /var/data
2022-09-29 16:23:13 +08:00
# Run the image first
2022-09-29 11:49:16 +08:00
$ docker run --name=answer -p 9080:80 -v /var/data:/data answer/answer
2022-09-29 16:23:13 +08:00
# After the first startup, a configuration file will be generated in the /var/data directory
2022-09-29 11:49:16 +08:00
# /var/data/config.yaml
2022-09-29 16:23:13 +08:00
# Need to modify the Mysql database address in the configuration file
2022-09-29 11:49:16 +08:00
vim /var/data/config.yaml
2022-09-29 16:23:13 +08:00
# Modify database connection
# connection: [username]:[password]@tcp([host]:[port])/[DbName]
2022-09-29 11:49:16 +08:00
...
2022-09-29 16:23:13 +08:00
# After configuring the configuration file, you can start the mirror again to start the service
2022-09-29 11:49:16 +08:00
$ docker start answer
2022-09-29 16:23:13 +08:00
2022-09-29 11:49:16 +08:00
```
## Binary for Answer
2022-09-29 16:23:13 +08:00
## Install Answer using binary
2022-09-29 11:49:16 +08:00
2022-09-29 16:23:13 +08:00
1. Unzip the compressed package.
2. Use the command cd to enter the directory you just created.
3. Execute the command ./answer init.
4. Answer will generate a ./data directory in the current directory
5. Enter the data directory and modify the config.yaml file
6. Modify the database connection address to your database connection address
2022-09-29 11:49:16 +08:00
connection: [username]:[password]@tcp([host]:[port])/[DbName]
2022-09-29 16:23:13 +08:00
7. Exit the data directory and execute ./answer run -c ./data/config.yaml
2022-09-29 11:49:16 +08:00
2022-09-29 16:23:13 +08:00
## config.yaml Description
2022-09-29 11:49:16 +08:00
```
server:
http:
2022-09-29 16:23:13 +08:00
addr: 0.0.0.0:80 #Project access port number
2022-09-29 11:49:16 +08:00
data:
database:
2022-09-29 16:23:13 +08:00
connection: root:root@tcp(127.0.0.1:3306)/answer #MySQL database connection address
2022-09-29 11:49:16 +08:00
cache:
2022-09-29 16:23:13 +08:00
file_path: "/tmp/cache/cache.db" #Cache file storage path
2022-09-29 11:49:16 +08:00
i18n:
2022-09-29 16:23:13 +08:00
bundle_dir: "/data/i18n" #Internationalized file storage directory
2022-09-29 11:49:16 +08:00
swaggerui:
2022-09-29 16:23:13 +08:00
show: true #Whether to display the swaggerapi documentation, address /swagger/index.html
protocol: http #swagger protocol header
host: 127.0.0.1 #An accessible IP address or domain name
address: ':80' #accessible port number
2022-09-29 11:49:16 +08:00
service_config:
2022-09-29 16:23:13 +08:00
secret_key: "answer" #encryption key
web_host: "http://127.0.0.1" #Page access using domain name address
upload_path: "./upfiles" #upload directory
2022-09-29 11:49:16 +08:00
```
2022-09-29 16:23:13 +08:00
## Compile the image
If you have modified the source files and want to repackage the image, you can use the following statement to repackage the image
```
docker build -t answer:v1.0.0 .
```
## common problem
1. The project cannot be started, answer the main program startup depends on the configuration file config.yaml, the internationalization translation directory/i18n, the upload file storage directory/upfiles, you need to ensure that the configuration file is loaded when the project starts, answer run -c config.yaml and the correct config.yaml The configuration items that specify the i18n and upfiles directories