Skip to content

Commit

Permalink
init project
Browse files Browse the repository at this point in the history
  • Loading branch information
smh2274 committed Feb 5, 2021
1 parent 8c42e8c commit a1697aa
Show file tree
Hide file tree
Showing 21 changed files with 1,099 additions and 19 deletions.
34 changes: 26 additions & 8 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
name: felstorm integration test on push
name: felstorm integration test
# This workflow is triggered on pushes to the repository.
on: [push]
on:
push:
branches: [ develop, main, master ]
pull_request:
branches: [ main, develop, master ]

workflow_dispatch:

jobs:
build:
# Job name is Greeting
name: felstorm integration test
# This job runs on Linux
golangci:
name: check code
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.15

- name: Lint Go Code
run: |
export PATH=$PATH:$(go env GOPATH)/bin
go get -u golang.org/x/lint/golint
golint -set_exit_status ./...
- name: Get Spend Time
run: echo 'The time was ${{ steps.hello.outputs.time }}.'
- name: run tests
run: |
go run cmd/felstorm.go
go test -v github.com/smh2274/Felstorm/internal/test/... > test.json
45 changes: 45 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# --- 构建编译环境 --
FROM golang:1.15 AS builder

# 设置环境变量
ENV GOPROXY https://goproxy.cn,direct
ENV GOPRIVATE github.com/smh2274/

WORKDIR /go/src/github.com/smh2274/Felstorm

# 拷贝需要编译的文件
COPY . /go/src/github.com/smh2274/Felstorm

# 设置git的url,使其可以访问smh2274的私有仓库
RUN git config --global url."https://058b9a7bee77a0e72d4d10dd270c21f03ba4d5ae:[email protected]/".insteadOf "https://github.com/"

# 编译
RUN GO111MODULE=on CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GOROOT_FINAL=$(pwd) go build -a -ldflags '-w -extldflags "-static"' -gcflags=-trimpath=$(pwd) -asmflags=-trimpath=$(pwd) cmd/felstorm.go

# --- 构建运行环境 ---
FROM envoyproxy/envoy-alpine:v1.17.0 AS prod

RUN mkdir -p /Azeroth/Felstorm/config \
&& mkdir -p /Azeroth/Felstorm/ssl \
&& mkdir -p /Azeroth/Felstorm/log \
&& touch /Azeroth/Felstorm/log/envoy_access.log \
&& chmod 777 /Azeroth/Felstorm/log/envoy_access.log

# 拷贝编译环境的二进制文件
COPY --from=builder /go/src/github.com/smh2274/Felstorm/felstorm /Azeroth/Felstorm/felstorm
COPY docker_prepare/* /Azeroth/Felstorm/
COPY internal/ssl/* /Azeroth/Felstorm/

RUN mv /Azeroth/Felstorm/envoy.yaml /Azeroth/Felstorm/config/ \
&& mv /Azeroth/Felstorm/felstorm_conf.yaml /Azeroth/Felstorm/config/ \
&& mv /Azeroth/Felstorm/domain.* /Azeroth/Felstorm/ssl/

# 设置时区
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
&& apk add --no-cache tzdata \
&& echo "Asia/Shanghai" > /etc/timezone \
&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

EXPOSE 8800

CMD /Azeroth/Felstorm/run.sh
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
init:
go get github.com/golang/[email protected]
go get github.com/golang/protobuf/[email protected]
go get -u google.golang.org/[email protected]

gen-grpc:
protoc -I . $(file) --go_out=plugins=grpc:.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
# Felstorm
# Felstorm

![image](https://img.zcool.cn/community/0175a85549a6d20000019ae941d3a4.jpg@1280w_1l_2o_100sh.jpg)
![image](https://symbols.getvecta.com/stencil_79/59_envoy-proxy-icon.11007cd6fb.png)

this project used grpc frame
63 changes: 63 additions & 0 deletions cmd/felstorm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package main

import (
"fmt"
jwt "github.com/smh2274/Felstorm/internal/api"
"github.com/smh2274/Felstorm/internal/logger"
"github.com/smh2274/Felstorm/internal/services"
"github.com/smh2274/Felstorm/internal/util"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"log"
"net"
)

func main() {
// 捕获panic
defer func() {
if r := recover(); r != nil {
fmt.Println(r)
}
}()

viper, err := util.LoadConfig()
if err != nil {
log.Fatalf("load config fail: %v", err)
}

// init log
err = logger.InitLogger(viper)
if err != nil {
log.Fatalf("init log fail: %v", err)
}

address := viper.GetString("server.address")
port := viper.GetString("server.port")

lis, err := net.Listen("tcp", fmt.Sprintf("%s:%s", address, port))
if err != nil {
log.Fatalf("failed to listen: %v", err)
}

// tls
opts := make([]grpc.ServerOption, 0)

creds, err := credentials.NewServerTLSFromFile(
viper.GetString("ssl.cert"),
viper.GetString("ssl.key"))
opts = append(opts, grpc.Creds(creds))

server := grpc.NewServer(opts...)

tokenServ := &services.GRPCTokenServer{
V: viper,
}

jwt.RegisterTokenServer(server, tokenServ)

if err := server.Serve(lis); err != nil {
log.Fatalf("failed to start felstorm server: %v", err)
} else {
log.Printf("felstorm server start success: %s:%s", address, port)
}
}
1 change: 0 additions & 1 deletion cmd/felstorm_login.go

This file was deleted.

9 changes: 0 additions & 9 deletions docker/login/Dockerfile

This file was deleted.

82 changes: 82 additions & 0 deletions docker_prepare/envoy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#admin:
# access_log_path: /tmp/admin_access.log
# address:
# socket_address: { address: 0.0.0.0, port_value: 9901 }

static_resources:
listeners:
- name: listener_0
address:
socket_address: { address: 0.0.0.0, port_value: 8800 }
filter_chains:
- filters:
- name: envoy.filters.network.http_connection_manager
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
access_log:
- name: envoy.listener.accesslog
typed_config:
"@type": type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: /Azeroth/Felstorm/log/envoy_access.log
log_format:
text_format: "[%START_TIME%] \"%REQ(:METHOD)% %REQ(X-ENVOY-ORIGINAL-PATH?:PATH)% %PROTOCOL%\" %RESPONSE_CODE% %RESPONSE_FLAGS% %BYTES_RECEIVED% %BYTES_SENT% %DURATION% %RESP(X-ENVOY-UPSTREAM-SERVICE-TIME)% \"%REQ(X-FORWARDED-FOR)%\" \"%REQ(USER-AGENT)%\" \"%REQ(X-REQUEST-ID)%\" \"%REQ(:AUTHORITY)%\" \"%UPSTREAM_HOST%\"\n"
codec_type: auto
stat_prefix: ingress_http
route_config:
name: local_route
virtual_hosts:
- name: local_service
domains: ["*"]
routes:
- match:
prefix: "/"
grpc: {}
route:
cluster: felstorm_service
cors:
allow_origin_string_match:
- prefix: "*"
allow_methods: GET, PUT, DELETE, POST, OPTIONS
allow_headers: authorization,keep-alive,user-agent,cache-control,content-type,content-transfer-encoding,custom-header-1,x-accept-content-transfer-encoding,x-accept-response-streaming,x-user-agent,x-grpc-web,grpc-timeout
max_age: "1728000"
expose_headers: Authorization,grpc-status,grpc-message
http_filters:
- name: envoy.filters.http.grpc_web
- name: envoy.filters.http.cors
- name: envoy.filters.http.router
transport_socket:
name: envoy.transport_sockets.tls
typed_config:
"@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.DownstreamTlsContext
common_tls_context:
tls_certificates:
certificate_chain:
filename: /Azeroth/Felstorm/ssl/domain.crt
private_key:
filename: /Azeroth/Felstorm/ssl/domain.key

clusters:
- name: felstorm_service
connect_timeout: 5s
type: logical_dns
lb_policy: round_robin
http2_protocol_options: {}
upstream_connection_options:
tcp_keepalive:
keepalive_time: 300
load_assignment:
cluster_name: felstorm_service
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: 127.0.0.1
port_value: 8888
transport_socket:
name: envoy.transport_sockets.tls
typed_config:
"@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext



16 changes: 16 additions & 0 deletions docker_prepare/felstorm_conf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
server:
address: 127.0.0.1
port: 8888
jwt:
# aFlFR0prSXJiT1NYSHN3WXI1bDR2cHhhbWZlWGk4TkN4SlN4WVRtclVTNA==
key: hYEGJkIrbOSXHswYr5l4vpxamfeXi8NCxJSxYTmrUS4
issuer: Simon.Shi
ssl:
key: /Azeroth/Felstorm/ssl/domain.key
cert: /Azeroth/Felstorm/ssl/domain.crt
log:
file: /Azeroth/Felstorm/log/felstorm_err.log
level: error
maxSize: 128
maxAge: 7
maxBackups: 30
5 changes: 5 additions & 0 deletions docker_prepare/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/Azeroth/Felstorm/felstorm &

/usr/local/bin/envoy -c /Azeroth/Felstorm/config/envoy.yaml -l debug


16 changes: 16 additions & 0 deletions felstorm_conf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
server:
address: 127.0.0.1
port: 8800
jwt:
# aFlFR0prSXJiT1NYSHN3WXI1bDR2cHhhbWZlWGk4TkN4SlN4WVRtclVTNA==
key: hYEGJkIrbOSXHswYr5l4vpxamfeXi8NCxJSxYTmrUS4
issuer: Simon.Shi
ssl:
key: internal/ssl/domain.key
cert: internal/ssl/domain.crt
log:
file: felstorm_err.log
level: error
maxSize: 128
maxAge: 7
maxBackups: 30
15 changes: 15 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
module github.com/smh2274/Felstorm

go 1.13

require (
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/fsnotify/fsnotify v1.4.7
github.com/golang/protobuf v1.4.3
github.com/spf13/viper v1.7.1
github.com/stretchr/testify v1.6.1 // indirect
go.uber.org/zap v1.16.0
golang.org/x/net v0.0.0-20210119194325-5f4716e94777 // indirect
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c // indirect
golang.org/x/text v0.3.5 // indirect
google.golang.org/grpc v1.26.0
gopkg.in/natefinch/lumberjack.v2 v2.0.0
gopkg.in/yaml.v2 v2.4.0 // indirect
)
Loading

0 comments on commit a1697aa

Please sign in to comment.