Skip to content

Commit 8e6c49a

Browse files
committed
initial commit
0 parents  commit 8e6c49a

File tree

461 files changed

+64888
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

461 files changed

+64888
-0
lines changed

.editorconfig

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
end_of_line = lf
7+
insert_final_newline = true
8+
trim_trailing_whitespace = true
9+
10+
[*.go]
11+
indent_style = tab
12+
indent_size = 2
13+
14+
[{Makefile, Dockerfile}]
15+
indent_style = tab
16+
indent_size = 4
17+
18+
[{*.yml, *.json}]
19+
indent_style = space
20+
indent_size = 2

.gitignore

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
*.exe
2+
*.orig
3+
*.rej
4+
*.so
5+
*~
6+
.DS_Store
7+
._*
8+
/.idea
9+
/.vscode/*.log
10+
/cmd/answer/*.sh
11+
/cmd/logs
12+
/configs/*
13+
/go.work*
14+
/logs
15+
/ui/build
16+
/ui/node_modules
17+
/vendor
18+
Thumbs*.db
19+
tmp
20+
vendor/

.gitlab-ci.yml

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
include:
2+
- project: "segmentfault/devops/templates"
3+
file: ".docker-build-push.yml"
4+
- project: "segmentfault/devops/templates"
5+
file: ".deploy-helm.yml"
6+
7+
stages:
8+
- compile-html
9+
- compile-golang
10+
- push
11+
- deploy-dev
12+
13+
"compile the html and other static files":
14+
image: node:16
15+
stage: compile-html
16+
tags:
17+
- runner-nanjing
18+
before_script:
19+
- npm config set registry https://repo.huaweicloud.com/repository/npm/
20+
- make install-ui-packages
21+
script:
22+
- make ui
23+
artifacts:
24+
paths:
25+
- ./build
26+
27+
"compile the golang project":
28+
image: golang:1.18
29+
stage: compile-golang
30+
before_script:
31+
- export GOPROXY="https://goproxy.cn"
32+
- export GOPRIVATE=git.backyard.segmentfault.com
33+
- sh ./script/prebuild.sh
34+
script:
35+
- make build
36+
artifacts:
37+
paths:
38+
- ./answer
39+
40+
"build docker images and push":
41+
stage: push
42+
extends: .docker-build-push
43+
only:
44+
- dev
45+
- master
46+
- main
47+
variables:
48+
DockerNamespace: sf_app
49+
DockerImage: answer
50+
DockerTag: "$CI_COMMIT_SHORT_SHA latest"
51+
DockerfilePath: .
52+
PushPolicy: qingcloud
53+
54+
"deploy-to-local-develop-environment":
55+
stage: deploy-dev
56+
extends: .deploy-helm
57+
only:
58+
- main
59+
variables:
60+
LoadBalancerIP: 10.0.10.98
61+
KubernetesCluster: dev
62+
KubernetesNamespace: "sf-web"
63+
InstallArgs: --set service.loadBalancerIP=${LoadBalancerIP} --set image.tag=$CI_COMMIT_SHORT_SHA --set replicaCount=1 --set serivce.targetPort=80
64+
ChartName: answer
65+
InstallPolicy: replace
66+

Dockerfile

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
FROM node:16 AS node-builder
2+
3+
LABEL maintainer="mingcheng<[email protected]>"
4+
5+
COPY . /answer
6+
WORKDIR /answer
7+
8+
RUN make install-ui-packages ui
9+
RUN mv ui/build /tmp
10+
CMD ls -al /tmp
11+
RUN du -sh /tmp/build
12+
13+
14+
FROM golang:1.18 AS golang-builder
15+
LABEL maintainer="aichy"
16+
17+
ENV GOPATH /go
18+
ENV GOROOT /usr/local/go
19+
ENV PACKAGE github.com/segmentfault/answer
20+
ENV GOPROXY https://goproxy.cn,direct
21+
ENV BUILD_DIR ${GOPATH}/src/${PACKAGE}
22+
ENV GOPRIVATE git.backyard.segmentfault.com
23+
# Build
24+
COPY . ${BUILD_DIR}
25+
WORKDIR ${BUILD_DIR}
26+
COPY --from=node-builder /tmp/build ${BUILD_DIR}/web/html
27+
CMD ls -al ${BUILD_DIR}/web/html
28+
RUN make clean build && \
29+
cp answer /usr/bin/answer && \
30+
cp configs/config.yaml /etc/config.yaml && \
31+
mkdir -p /tmp/cache && chmod 777 /tmp/cache && \
32+
mkdir -p /data/upfiles && chmod 777 /data/upfiles && cp -r i18n /data
33+
34+
FROM debian:bullseye
35+
36+
ENV TZ "Asia/Shanghai"
37+
RUN sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list \
38+
&& sed -i 's/security.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list \
39+
&& echo "Asia/Shanghai" > /etc/timezone \
40+
&& apt -y update \
41+
&& apt -y upgrade \
42+
&& apt -y install ca-certificates openssl tzdata curl netcat dumb-init \
43+
&& apt -y autoremove
44+
45+
COPY --from=golang-builder /data /data
46+
VOLUME /data
47+
48+
COPY --from=golang-builder /etc/config.yaml /etc/answer.yaml
49+
COPY --from=golang-builder /usr/bin/answer /usr/bin/answer
50+
51+
EXPOSE 80
52+
53+
ENTRYPOINT ["dumb-init", "/usr/bin/answer", "-c", "/etc/answer.yaml"]

INSTALL.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# How to build and install

INSTALL_CN.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Answer 安装指引
2+
3+
## 前端安装
4+
5+
## 后端安装
6+
7+
## 编译镜像
8+
9+
## 常见问题

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) since 2022 The Segmentfault Development Team.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
.PHONY: build clean ui
2+
3+
VERSION=0.0.1
4+
BIN=answer
5+
DIR_SRC=./cmd/answer
6+
DOCKER_CMD=docker
7+
8+
GO_ENV=CGO_ENABLED=0
9+
GO_FLAGS=-ldflags="-X main.Version=$(VERSION) -X 'main.Time=`date`' -extldflags -static"
10+
GO=$(GO_ENV) $(shell which go)
11+
12+
build:
13+
@$(GO_ENV) $(GO) build $(GO_FLAGS) -o $(BIN) $(DIR_SRC)
14+
15+
test:
16+
@$(GO) test ./...
17+
18+
# clean all build result
19+
clean:
20+
@$(GO) clean ./...
21+
@rm -f $(BIN)
22+
23+
install-ui-packages:
24+
@corepack enable
25+
@corepack prepare [email protected] --activate
26+
27+
ui:
28+
@npm config set registry https://repo.huaweicloud.com/repository/npm/
29+
@cd ui && pnpm install && pnpm build && cd -
30+
31+
all: clean build

README.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# answer
2+
3+
问答社区主项目代码
4+
5+
# Dependence
6+
github.com/segmentfault/pacman
7+
* config-file `viper` https://github.com/spf13/viper
8+
* web `gin` https://gin-gonic.com/zh-cn/
9+
* log `zap` https://github.com/uber-go/zap
10+
* orm `xorm` https://xorm.io/zh/
11+
* redis `go-redis` https://github.com/go-redis/redis
12+
13+
# module
14+
- email github.com/jordan-wright/email
15+
- session github.com/gin-contrib/sessions
16+
- Captcha github.com/mojocn/base64Captcha
17+
18+
# Run
19+
```
20+
cd cmd
21+
export GOPRIVATE=git.backyard.segmentfault.com
22+
go mod tidy
23+
./dev.sh
24+
```
25+
26+
# pprof
27+
28+
```
29+
# Installation dependency
30+
go get -u github.com/google/pprof
31+
brew install graphviz
32+
```
33+
```
34+
pprof -http :8082 http://XXX/debug/pprof/profile\?seconds\=10
35+
```

README_CN.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Answer 问答社区
2+
3+
## 功能说明
4+
5+
## 安装
6+
7+
## 配置
8+
9+
## 常见问题

build/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# /build
2+
Packaging and Continuous Integration.

charts/.idea/.gitignore

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

charts/.idea/charts.iml

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

charts/.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

charts/.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

charts/Chart.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: v2
2+
name: answer
3+
description: a simple answer deployments for kubernetes
4+
type: application
5+
version: 0.1.0
6+
appVersion: "0.1.0"

charts/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Helm Charts for Answer project
2+

charts/templates/_helpers.tpl

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "answer.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11+
If release name contains chart name it will be used as a full name.
12+
*/}}
13+
{{- define "answer.fullname" -}}
14+
{{- if .Values.fullnameOverride }}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16+
{{- else }}
17+
{{- $name := default .Chart.Name .Values.nameOverride }}
18+
{{- if contains $name .Release.Name }}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20+
{{- else }}
21+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22+
{{- end }}
23+
{{- end }}
24+
{{- end }}
25+
26+
{{/*
27+
Create chart name and version as used by the chart label.
28+
*/}}
29+
{{- define "answer.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "answer.labels" -}}
37+
helm.sh/chart: {{ .Release.Name }}
38+
{{ include "answer.selectorLabels" . }}
39+
{{- if .Chart.AppVersion }}
40+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
41+
{{- end }}
42+
app.kubernetes.io/managed-by: {{ .Release.Service }}
43+
{{- end }}
44+
45+
{{/*
46+
Selector labels
47+
*/}}
48+
{{- define "answer.selectorLabels" -}}
49+
app.kubernetes.io/name: answer
50+
app.kubernetes.io/instance: {{ .Release.Name }}
51+
{{- end }}

charts/templates/config.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
apiVersion: v1
3+
kind: ConfigMap
4+
metadata:
5+
name: answer-config
6+
namespace: {{ .Values.namespace | default "default" | quote }}
7+
data:
8+
default.yaml: |-
9+
#

0 commit comments

Comments
 (0)