Skip to content

Commit

Permalink
Merge pull request #94 from ch3nnn/v2
Browse files Browse the repository at this point in the history
feat: v2.0.0
  • Loading branch information
ch3nnn authored Nov 14, 2024
2 parents 0887753 + 50050ff commit d9d3801
Show file tree
Hide file tree
Showing 578 changed files with 24,274 additions and 40,806 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.git
.idea
14 changes: 14 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
* text=auto

# Force the following filetypes to have unix eols, so Windows does not break them
*.* text eol=lf

# Windows forced line-endings
/.idea/* text eol=crlf

#
## These files are binary and should be left untouched
#

# (binary is a macro for -text -diff)
*.png binary
File renamed without changes
Binary file added .github/image/category.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/image/index.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
108 changes: 6 additions & 102 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,102 +1,6 @@
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# AWS User-specific
.idea/**/aws.xml

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# SonarLint plugin
.idea/sonarlint/

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### Go template
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work

bin/
storage/logs
.idea
*.log
deploy/docker-compose/conf
deploy/docker-compose/data
47 changes: 22 additions & 25 deletions Dockerfile
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
# FROM 基于 golang:1.20-alpine
FROM golang:1.20-alpine AS builder
FROM golang:1.22-alpine AS builder
RUN set -eux && sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories

# ENV 设置环境变量
ENV GO111MODULE=on
ENV GOPROXY=https://goproxy.io,direct
ARG APP_RELATIVE_PATH

# COPY 源路径 目标路径
COPY . /go/src/github.com/ch3nnn/webstack-go
COPY . /data/app
WORKDIR /data/app

# RUN 执行 go build .
RUN cd /go/src/github.com/ch3nnn/webstack-go && go build .
RUN rm -rf /data/app/bin/
RUN export GOPROXY=https://goproxy.cn,direct && go mod tidy && go build -ldflags="-s -w" -o ./bin/server ${APP_RELATIVE_PATH}
RUN mv config /data/app/bin/

# FROM 基于 alpine:latest
FROM alpine:latest

# RUN 设置代理镜像
RUN echo -e http://mirrors.ustc.edu.cn/alpine/v3.13/main/ > /etc/apk/repositories
FROM alpine:3.14
RUN set -eux && sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories

# RUN 设置 Asia/Shanghai 时区
RUN apk --no-cache add tzdata && \
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo "Asia/Shanghai" > /etc/timezone

# COPY 源路径 目标路径 从镜像中 COPY
COPY --from=builder /go/src/github.com/ch3nnn/webstack-go/webstack-go /opt/
RUN apk add tzdata && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone \
&& apk del tzdata

# EXPOSE 设置端口映射
EXPOSE 9999/tcp

# WORKDIR 设置工作目录
WORKDIR /opt
ARG APP_ENV
ENV APP_ENV=${APP_ENV}

# CMD 设置启动命令
CMD ["./webstack-go", "-env", "docker"]
WORKDIR /data/app
COPY --from=builder /data/app/bin /data/app
COPY --from=builder /data/app/web/upload /data/app/web/upload/
RUN mkdir -p /data/app/storage/

EXPOSE 8000
ENTRYPOINT [ "./server" ]
30 changes: 30 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.PHONY: init
init:
go install github.com/google/wire/cmd/wire@latest
go install github.com/swaggo/swag/cmd/swag@latest
go install github.com/incu6us/goimports-reviser/v3@latest
go install mvdan.cc/gofumpt@latest

.PHONY: build
build:
go build -ldflags="-s -w" -o ./bin/server ./cmd/server

.PHONY: docker
docker:
docker build -t webstack-go:v2 --build-arg APP_CONF=config/prod.yml --build-arg APP_RELATIVE_PATH=./cmd/server .
docker run -itd -p 8000:8000 --name webstack-go webstack-go:v2

.PHONY: swag
swag:
swag init -g cmd/server/main.go -o ./docs --parseDependency

.PHONY: fmt
fmt:
goimports-reviser -rm-unused -set-alias -format ./...
find . -name '*.go' -not -name "*.pb.go" -not -name "*.gen.go" | xargs gofumpt -w -extra

.PHONY: run
run:
go mod tidy
go build -ldflags="-s -w" -o ./bin/server ./cmd/server
./bin/server -conf=config/prod.yml
97 changes: 18 additions & 79 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,23 @@

基于 Golang 开源的网址导航网站项目,具备完整的前后台,您可以拿来制作自己平日收藏的网址导航。

- 图标库: [lineicons](https://lineicons.com/icons/)
- 前端模板: [WebStackPage](https://github.com/WebStackPage/WebStackPage.github.io)
- 后端 Gin 框架: 基于 [go-gin-api ](https://github.com/xinliangnote/go-gin-api)项目二次开发
- 前端模板: [WebStackPage](https://github.com/WebStackPage/WebStackPage.github.io)[go-gin-api ](https://github.com/xinliangnote/go-gin-api)
- 后端框架: 基于 [go-nunu](https://github.com/go-nunu/nunu) 脚手架搭建

原有后端项目基础上新增功能
功能
- [x] 新增 webstack - 导航首页
- [x] 新增 系统管理员 - 网站分类
- [x] 新增 系统管理员 - 网站列表
- [x] 网站新增支持自动获取标题、Logo、网站描述、一键同步
- [x] 新增 `docker-compose.yml` 一键安装各组件
- [x] 批量添加网址
- [x] 优化: 由 [gorm-gen](https://github.com/go-gorm/gen) 代码生成提供支持的友好且更安全的 GORM
- [x] 新增 网站新增支持自动获取标题、Logo、网站描述、一键同步
- [x] 新增 批量添加网址
- [x] 新增 由 [gorm-gen](https://github.com/go-gorm/gen) 代码生成提供支持的友好且更安全的 GORM

## 快速开始

### 一、运行环境

> 安装 Golang、Mysql、Redis
- Golang 1.16+ 因为使用了 //go:embed 特性;
- MySQL
- 连接地址,例如:127.0.0.1:3306;
- 数据库名,例如:webstack,会在此数据库下初始化数据表;
- 用户名,不可为空;
- 密码,不可为空;
- Redis
- 连接地址,例如:127.0.0.1:6379;
- 密码,可为空;
- 连接DB,默认是 0 ;
- Golang 1.22
- SQLite

### 二、启动服务

Expand All @@ -39,61 +27,19 @@
**一、源码运行服务**

1. 目录下执行 `go mod tidy` 拉取项目依赖库
2. 安装完依赖执行 `go run main.go` 首次启动程序之后,会在浏览器中自动打开安装界面,链接地址:http://127.0.0.1:9999/install
3. 点击 `初始化项目` 会看到如下图所示, 如果提示重新运行服务说明项目初始化完成, 只需重新运行服务就 OK 了!
2. 执行 `go build -o ./bin/server ./cmd/server` 编译项目,生成可执行文件 server
3. 编译完执行 `./bin/server -conf=config/prod.yml` 首次启动程序之后,会生成 SQLite 数据库,并自动创建表结构

<img src="assets/bootstrap/images/init_project.png" width="600"/>

**二、Docker运行服务**
> 包含两部分 1. 基础服务(Mysql、Redis、Service) 2. 监控服务(Prometheus、Grafana)

**一、基础服务**

1. 目录下执行 `docker-compose -f docker-compose.yml up -d` 等待基础组件启动 (Mysql、Redis、Service)
```shell
$ docker-compose -f docker-compose.yml up -d
[+] Running 4/4
✔ Network webstack-go Created 0.1s
✔ Container webstack-go-mysql Healthy 12.9s
✔ Container webstack-go-redis Healthy 13.4s
✔ Container webstack-go-service Started
```

2. 执行`docker-compose -f docker-compose.yml ps `服务正常运行如下
1. 目录下执行 `make docker` 等待启动
```shell
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
webstack-go-mysql mysql/mysql-server:5.7 "/entrypoint.sh mysq…" webstack-go-mysql 2 minutes ago Up 2 minutes (healthy) 0.0.0.0:3306->3306/tcp, 33060/tcp
webstack-go-redis redis:6.2.4 "docker-entrypoint.s…" webstack-go-redis 2 minutes ago Up 2 minutes (healthy) 0.0.0.0:6379->6379/tcp
webstack-go-service webstack-go-webstack-go-service "./webstack-go -env …" webstack-go-service 2 minutes ago Up 2 minutes (healthy) 0.0.0.0:9999->9999/tcp
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5cb641ff3950 webstack-go:v2 "./server" 5 seconds ago Up 5 seconds 0.0.0.0:8000->8000/tcp webstack-go
```
3. docker container 正常运行后, 在浏览器中打开安装界面,链接地址:http://127.0.0.1:9999/install
4. 点击 `初始化项目` 会看到如下图所示, 如果提示重新运行服务说明项目初始化完成, 只需重新运行 `webstack-go-service` 容器服务就 OK 了!

<img src="assets/bootstrap/images/init_project.png" width="600"/>

**二、prometheus、grafana监控服务**
> 注: 监控服务看自己是否需要, 不运行也不影响正常使用
1. 目录下执行 `docker-compose -f docker-compose-prometheus.yml up -d` 等待监控组件启动 (Prometheus、Grafana)
```shell
[+] Running 4/4
✔ Container webstack-go-prometheus Started 4.0s
✔ Container webstack-go-loki Started 3.6s
✔ Container webstack-go-grafana Started 4.3s
✔ Container webstack-go-promtail Started
```
2. 执行`docker-compose -f docker-compose-prometheus.yml ps `服务正常运行如下
```shell
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
webstack-go-grafana grafana/grafana-enterprise:9.4.3 "/run.sh" webstack-go-grafana 2 minutes ago Up 2 minutes 0.0.0.0:3000->3000/tcp
webstack-go-loki grafana/loki:2.7.3 "/usr/bin/loki -conf…" webstack-go-loki 2 minutes ago Up 2 minutes 0.0.0.0:3100->3100/tcp
webstack-go-mysql mysql/mysql-server:5.7 "/entrypoint.sh mysq…" webstack-go-mysql 3 minutes ago Up 3 minutes (healthy) 0.0.0.0:3306->3306/tcp, 33060/tcp
webstack-go-prometheus prom/prometheus:latest "/bin/prometheus --c…" webstack-go-prometheus 2 minutes ago Up 2 minutes 0.0.0.0:9090->9090/tcp
webstack-go-promtail grafana/promtail:2.7.3 "/usr/bin/promtail -…" webstack-go-promtail 2 minutes ago Up 2 minutes
webstack-go-redis redis:6.2.4 "docker-entrypoint.s…" webstack-go-redis 3 minutes ago Up 3 minutes (healthy) 0.0.0.0:6379->6379/tcp
webstack-go-service webstack-go-webstack-go-service "./webstack-go -env …" webstack-go-service 3 minutes ago Up 3 minutes (healthy) 0.0.0.0:9999->9999/tcp
```
2. docker container 正常运行后, 在浏览器中打开界面,链接地址:http://127.0.0.1:8000

## Star History

Expand All @@ -103,23 +49,16 @@

> **首页**
![](assets/bootstrap/images/index.png)
![](.github/image/index.png)

> **网站分类**
![](assets/bootstrap/images/category.png)
![](.github/image/category.png)

> **新增网站**
![](assets/bootstrap/images/add_site.png)
![](.github/image/add_site.png)

> **网站信息**
![](assets/bootstrap/images/site.png)

> **监控组件**

![grafana.png](assets/bootstrap/images/grafana.png)![]()



![](.github/image/site.png)
Loading

0 comments on commit d9d3801

Please sign in to comment.