-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8e6c49a
Showing
461 changed files
with
64,888 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# http://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.go] | ||
indent_style = tab | ||
indent_size = 2 | ||
|
||
[{Makefile, Dockerfile}] | ||
indent_style = tab | ||
indent_size = 4 | ||
|
||
[{*.yml, *.json}] | ||
indent_style = space | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
*.exe | ||
*.orig | ||
*.rej | ||
*.so | ||
*~ | ||
.DS_Store | ||
._* | ||
/.idea | ||
/.vscode/*.log | ||
/cmd/answer/*.sh | ||
/cmd/logs | ||
/configs/* | ||
/go.work* | ||
/logs | ||
/ui/build | ||
/ui/node_modules | ||
/vendor | ||
Thumbs*.db | ||
tmp | ||
vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
include: | ||
- project: "segmentfault/devops/templates" | ||
file: ".docker-build-push.yml" | ||
- project: "segmentfault/devops/templates" | ||
file: ".deploy-helm.yml" | ||
|
||
stages: | ||
- compile-html | ||
- compile-golang | ||
- push | ||
- deploy-dev | ||
|
||
"compile the html and other static files": | ||
image: node:16 | ||
stage: compile-html | ||
tags: | ||
- runner-nanjing | ||
before_script: | ||
- npm config set registry https://repo.huaweicloud.com/repository/npm/ | ||
- make install-ui-packages | ||
script: | ||
- make ui | ||
artifacts: | ||
paths: | ||
- ./build | ||
|
||
"compile the golang project": | ||
image: golang:1.18 | ||
stage: compile-golang | ||
before_script: | ||
- export GOPROXY="https://goproxy.cn" | ||
- export GOPRIVATE=git.backyard.segmentfault.com | ||
- sh ./script/prebuild.sh | ||
script: | ||
- make build | ||
artifacts: | ||
paths: | ||
- ./answer | ||
|
||
"build docker images and push": | ||
stage: push | ||
extends: .docker-build-push | ||
only: | ||
- dev | ||
- master | ||
- main | ||
variables: | ||
DockerNamespace: sf_app | ||
DockerImage: answer | ||
DockerTag: "$CI_COMMIT_SHORT_SHA latest" | ||
DockerfilePath: . | ||
PushPolicy: qingcloud | ||
|
||
"deploy-to-local-develop-environment": | ||
stage: deploy-dev | ||
extends: .deploy-helm | ||
only: | ||
- main | ||
variables: | ||
LoadBalancerIP: 10.0.10.98 | ||
KubernetesCluster: dev | ||
KubernetesNamespace: "sf-web" | ||
InstallArgs: --set service.loadBalancerIP=${LoadBalancerIP} --set image.tag=$CI_COMMIT_SHORT_SHA --set replicaCount=1 --set serivce.targetPort=80 | ||
ChartName: answer | ||
InstallPolicy: replace | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
FROM node:16 AS node-builder | ||
|
||
LABEL maintainer="mingcheng<[email protected]>" | ||
|
||
COPY . /answer | ||
WORKDIR /answer | ||
|
||
RUN make install-ui-packages ui | ||
RUN mv ui/build /tmp | ||
CMD ls -al /tmp | ||
RUN du -sh /tmp/build | ||
|
||
|
||
FROM golang:1.18 AS golang-builder | ||
LABEL maintainer="aichy" | ||
|
||
ENV GOPATH /go | ||
ENV GOROOT /usr/local/go | ||
ENV PACKAGE github.com/segmentfault/answer | ||
ENV GOPROXY https://goproxy.cn,direct | ||
ENV BUILD_DIR ${GOPATH}/src/${PACKAGE} | ||
ENV GOPRIVATE git.backyard.segmentfault.com | ||
# Build | ||
COPY . ${BUILD_DIR} | ||
WORKDIR ${BUILD_DIR} | ||
COPY --from=node-builder /tmp/build ${BUILD_DIR}/web/html | ||
CMD ls -al ${BUILD_DIR}/web/html | ||
RUN make clean build && \ | ||
cp answer /usr/bin/answer && \ | ||
cp configs/config.yaml /etc/config.yaml && \ | ||
mkdir -p /tmp/cache && chmod 777 /tmp/cache && \ | ||
mkdir -p /data/upfiles && chmod 777 /data/upfiles && cp -r i18n /data | ||
|
||
FROM debian:bullseye | ||
|
||
ENV TZ "Asia/Shanghai" | ||
RUN sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list \ | ||
&& sed -i 's/security.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list \ | ||
&& echo "Asia/Shanghai" > /etc/timezone \ | ||
&& apt -y update \ | ||
&& apt -y upgrade \ | ||
&& apt -y install ca-certificates openssl tzdata curl netcat dumb-init \ | ||
&& apt -y autoremove | ||
|
||
COPY --from=golang-builder /data /data | ||
VOLUME /data | ||
|
||
COPY --from=golang-builder /etc/config.yaml /etc/answer.yaml | ||
COPY --from=golang-builder /usr/bin/answer /usr/bin/answer | ||
|
||
EXPOSE 80 | ||
|
||
ENTRYPOINT ["dumb-init", "/usr/bin/answer", "-c", "/etc/answer.yaml"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# How to build and install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Answer 安装指引 | ||
|
||
## 前端安装 | ||
|
||
## 后端安装 | ||
|
||
## 编译镜像 | ||
|
||
## 常见问题 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) since 2022 The Segmentfault Development Team. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
.PHONY: build clean ui | ||
|
||
VERSION=0.0.1 | ||
BIN=answer | ||
DIR_SRC=./cmd/answer | ||
DOCKER_CMD=docker | ||
|
||
GO_ENV=CGO_ENABLED=0 | ||
GO_FLAGS=-ldflags="-X main.Version=$(VERSION) -X 'main.Time=`date`' -extldflags -static" | ||
GO=$(GO_ENV) $(shell which go) | ||
|
||
build: | ||
@$(GO_ENV) $(GO) build $(GO_FLAGS) -o $(BIN) $(DIR_SRC) | ||
|
||
test: | ||
@$(GO) test ./... | ||
|
||
# clean all build result | ||
clean: | ||
@$(GO) clean ./... | ||
@rm -f $(BIN) | ||
|
||
install-ui-packages: | ||
@corepack enable | ||
@corepack prepare [email protected] --activate | ||
|
||
ui: | ||
@npm config set registry https://repo.huaweicloud.com/repository/npm/ | ||
@cd ui && pnpm install && pnpm build && cd - | ||
|
||
all: clean build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# answer | ||
|
||
问答社区主项目代码 | ||
|
||
# Dependence | ||
github.com/segmentfault/pacman | ||
* config-file `viper` https://github.com/spf13/viper | ||
* web `gin` https://gin-gonic.com/zh-cn/ | ||
* log `zap` https://github.com/uber-go/zap | ||
* orm `xorm` https://xorm.io/zh/ | ||
* redis `go-redis` https://github.com/go-redis/redis | ||
|
||
# module | ||
- email github.com/jordan-wright/email | ||
- session github.com/gin-contrib/sessions | ||
- Captcha github.com/mojocn/base64Captcha | ||
|
||
# Run | ||
``` | ||
cd cmd | ||
export GOPRIVATE=git.backyard.segmentfault.com | ||
go mod tidy | ||
./dev.sh | ||
``` | ||
|
||
# pprof | ||
|
||
``` | ||
# Installation dependency | ||
go get -u github.com/google/pprof | ||
brew install graphviz | ||
``` | ||
``` | ||
pprof -http :8082 http://XXX/debug/pprof/profile\?seconds\=10 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Answer 问答社区 | ||
|
||
## 功能说明 | ||
|
||
## 安装 | ||
|
||
## 配置 | ||
|
||
## 常见问题 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# /build | ||
Packaging and Continuous Integration. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
apiVersion: v2 | ||
name: answer | ||
description: a simple answer deployments for kubernetes | ||
type: application | ||
version: 0.1.0 | ||
appVersion: "0.1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Helm Charts for Answer project | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{{/* | ||
Expand the name of the chart. | ||
*/}} | ||
{{- define "answer.name" -}} | ||
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} | ||
{{- end }} | ||
|
||
{{/* | ||
Create a default fully qualified app name. | ||
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). | ||
If release name contains chart name it will be used as a full name. | ||
*/}} | ||
{{- define "answer.fullname" -}} | ||
{{- if .Values.fullnameOverride }} | ||
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} | ||
{{- else }} | ||
{{- $name := default .Chart.Name .Values.nameOverride }} | ||
{{- if contains $name .Release.Name }} | ||
{{- .Release.Name | trunc 63 | trimSuffix "-" }} | ||
{{- else }} | ||
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} | ||
{{- end }} | ||
{{- end }} | ||
{{- end }} | ||
|
||
{{/* | ||
Create chart name and version as used by the chart label. | ||
*/}} | ||
{{- define "answer.chart" -}} | ||
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} | ||
{{- end }} | ||
|
||
{{/* | ||
Common labels | ||
*/}} | ||
{{- define "answer.labels" -}} | ||
helm.sh/chart: {{ .Release.Name }} | ||
{{ include "answer.selectorLabels" . }} | ||
{{- if .Chart.AppVersion }} | ||
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} | ||
{{- end }} | ||
app.kubernetes.io/managed-by: {{ .Release.Service }} | ||
{{- end }} | ||
|
||
{{/* | ||
Selector labels | ||
*/}} | ||
{{- define "answer.selectorLabels" -}} | ||
app.kubernetes.io/name: answer | ||
app.kubernetes.io/instance: {{ .Release.Name }} | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: answer-config | ||
namespace: {{ .Values.namespace | default "default" | quote }} | ||
data: | ||
default.yaml: |- | ||
# |
Oops, something went wrong.