Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
universero committed Aug 28, 2024
1 parent a962fea commit 39dacbd
Show file tree
Hide file tree
Showing 16 changed files with 997 additions and 0 deletions.
84 changes: 84 additions & 0 deletions .github/workflows/upgrade.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Upgrade

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

on:
push:
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env:
REGISTRY: docker.io
USERNAME: xhpolaris
IMAGE_NAME: platform-data

jobs:
build:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Bump Version
id: version
run: curl -s https://raw.githubusercontent.com/xh-polaris/chore/main/bump_version.sh | bash -s -- ${{ env.USERNAME }}/${{ env.IMAGE_NAME }}

# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name == 'push'
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
with:
registry: ${{ env.REGISTRY }}
username: ${{ env.USERNAME }}
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}

# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.USERNAME }}/${{ env.IMAGE_NAME }}

# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a
with:
context: .
push: ${{ github.event_name == 'push' }}
tags: ${{ env.REGISTRY }}/${{ env.USERNAME }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

deploy:
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'push'
steps:
- name: Setup Kubectl
uses: azure/setup-kubectl@v3
with:
version: ${{ vars.KUBE_VERSION }}

- name: Deploy
run: |
mkdir $HOME/.kube
echo "${{ secrets.KUBE_CONFIG }}" > $HOME/.kube/config
kubectl get deployment ${{ env.IMAGE_NAME }} -n ${{ vars.BASE_TEST_NAMESPACE }} -o yaml |\
sed 's/^\( - image: xhpolaris\/${{ env.IMAGE_NAME }}:\).*$/\1${{ needs.build.outputs.version }}/' |\
kubectl apply -f -
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/platform-data.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM golang:1.20-alpine AS builder

LABEL stage=gobuilder

ENV CGO_ENABLED 0
ENV GOPROXY https://goproxy.cn,direct
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories

RUN apk update --no-cache && apk add --no-cache tzdata

WORKDIR /build

ADD go.mod .
ADD go.sum .
RUN go mod download
COPY . .
RUN sh ./build.sh

FROM alpine

COPY --from=builder /usr/share/zoneinfo/Asia/Shanghai /usr/share/zoneinfo/Asia/Shanghai

ENV TZ Asia/Shanghai

WORKDIR /app
COPY --from=builder /build/output /app

CMD ["sh", "./bootstrap.sh"]
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.PHONY: start build wire clean

run:
sh ./output/bootstrap.sh
build:
sh ./build.sh
build_and_run:
sh ./build.sh && sh ./output/bootstrap.sh
wire:
wire ./provider
clean:
rm -r ./output
13 changes: 13 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
RUN_NAME="platform.data"

mkdir -p output/bin
cp script/* output/
chmod +x output/bootstrap.sh

if [ "$IS_SYSTEM_TEST_ENV" != "1" ]; then
go build -o output/bin/${RUN_NAME}
else
go test -c -covermode=set -o output/bin/${RUN_NAME} -coverpkg=./...
fi

43 changes: 43 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package config

import (
"fmt"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/core/service"
"os"
)

var config *Config

type Config struct {
service.ServiceConf
ListenOn string
ElasticSearch struct {
Username string
Password string
Addr []string
}
}

func Init() {
config = new(Config)
path := os.Getenv("CONFIG_PATH")
if path == "" {
path = "etc/config.yaml"
}
err := conf.Load(path, config)
if err != nil {
panic(err)
}
err = config.SetUp()
if err != nil {
panic(err)
}
}

func Get() *Config {
if config == nil {
fmt.Println("config is nil")
}
return config
}
55 changes: 55 additions & 0 deletions domain/es.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package domain

import (
"bytes"
"crypto/tls"
"errors"
"log"
"net/http"
"platform-data/config"
)
import "github.com/elastic/go-elasticsearch/v8"

type IEsMapper interface {
Insert(documents []byte) error
}

type EsMapper struct {
es *elasticsearch.Client
}

func NewEsMapper() IEsMapper {
aConfig := config.Get()
esClient, err := elasticsearch.NewClient(elasticsearch.Config{
Username: aConfig.ElasticSearch.Username,
Password: aConfig.ElasticSearch.Password,
Addresses: aConfig.ElasticSearch.Addr,
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
})

if err != nil {
log.Fatal(err)
}
return &EsMapper{
es: esClient,
}
}

func (mapper *EsMapper) Insert(documents []byte) error {

// 插入文档到指定的索引
res, err := mapper.es.Bulk(bytes.NewReader(documents))

if res != nil && res.IsError() {
log.Println(res.String())
return errors.New("elastic search 可能存在语法错误")
}

if err != nil {
log.Println(err)
}

return err
}
91 changes: 91 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
module platform-data

go 1.20

replace github.com/apache/thrift => github.com/apache/thrift v0.13.0

require (
github.com/cloudwego/kitex v0.10.3
github.com/elastic/go-elasticsearch/v8 v8.9.0
github.com/kitex-contrib/obs-opentelemetry v0.2.7
github.com/xh-polaris/gopkg v0.0.0-20240424152329-9162fdb0eef9
github.com/xh-polaris/service-idl-gen-go v0.0.0-20240827135430-e5dde83f5dc0
github.com/zeromicro/go-zero v1.7.0
)

require (
github.com/apache/thrift v0.16.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bufbuild/protocompile v0.10.0 // indirect
github.com/bytedance/gopkg v0.0.0-20240514070511-01b2cbcf35e1 // indirect
github.com/bytedance/sonic v1.12.2 // indirect
github.com/bytedance/sonic/loader v0.2.0 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/configmanager v0.2.2 // indirect
github.com/cloudwego/dynamicgo v0.2.9 // indirect
github.com/cloudwego/fastpb v0.0.4 // indirect
github.com/cloudwego/frugal v0.1.15 // indirect
github.com/cloudwego/hertz v0.8.1 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/cloudwego/localsession v0.0.2 // indirect
github.com/cloudwego/netpoll v0.6.3 // indirect
github.com/cloudwego/runtimex v0.1.0 // indirect
github.com/cloudwego/thriftgo v0.3.15 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/elastic/elastic-transport-go/v8 v8.0.0-20230329154755-1a3c63de0db6 // indirect
github.com/fatih/color v1.17.0 // indirect
github.com/fatih/structtag v1.2.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/pprof v0.0.0-20230509042627-b1315fad0c5a // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
github.com/iancoleman/strcase v0.2.0 // indirect
github.com/jhump/protoreflect v1.16.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/gls v0.0.0-20220109145502-612d0167dce5 // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/oleiade/lane v1.0.1 // indirect
github.com/openzipkin/zipkin-go v0.4.3 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/tidwall/gjson v1.14.4 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/exporters/jaeger v1.17.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.24.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.24.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.24.0 // indirect
go.opentelemetry.io/otel/exporters/zipkin v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/sdk v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
go.uber.org/automaxprocs v1.5.3 // indirect
golang.org/x/arch v0.2.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/text v0.17.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect
google.golang.org/grpc v1.65.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 39dacbd

Please sign in to comment.