Skip to content

Commit

Permalink
feat: 添加自动部署
Browse files Browse the repository at this point in the history
  • Loading branch information
Lansongxx committed Jan 7, 2024
1 parent 1614d94 commit dee6909
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 40 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/buidl.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Build

# 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:
# Use docker.io for Docker Hub if empty
REGISTRY: docker.io
USERNAME: lansongxx
# github.repository as <account>/<repo>
IMAGE_NAME: CloudStriver/cloudmind-content

jobs:
build:

runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

# 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 != 'pull_request'
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.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 != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
3 changes: 1 addition & 2 deletions biz/application/service/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ func (s *UserServiceImpl) SearchUser(ctx context.Context, req *gencontent.Search
for _, u := range user {
resp.Users = append(resp.Users, convertor.UserMapperToUser(u))
}

return resp, nil
}

Expand Down Expand Up @@ -102,7 +101,7 @@ func (s *UserServiceImpl) CreateUser(ctx context.Context, req *gencontent.Create
if _, err = s.UserMongoMapper.Insert(ctx, &usermapper.User{
ID: ID,
Name: req.UserInfo.Name,
Sex: int32(req.UserInfo.Sex),
Sex: req.UserInfo.Sex,
Description: consts.DefaultDescription,
Url: consts.DefaultAvatarUrl,
}); err != nil {
Expand Down
4 changes: 3 additions & 1 deletion biz/infrastructure/convertor/convertor.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package convertor

import (
"fmt"
usermapper "github.com/CloudStriver/cloudmind-content/biz/infrastructure/mapper/user"
gencontent "github.com/CloudStriver/service-idl-gen-go/kitex_gen/cloudmind/content"
"go.mongodb.org/mongo-driver/bson/primitive"
Expand All @@ -21,11 +22,12 @@ func UserMapperToUserDetail(in *usermapper.User) *gencontent.UserDetail {
}

func UserDetailToUserMapper(in *gencontent.UserDetailInfo) *usermapper.User {
fmt.Println(in)
ID, _ := primitive.ObjectIDFromHex(in.UserId)
return &usermapper.User{
ID: ID,
Name: in.Name,
Sex: int32(in.GetSex()),
Sex: in.GetSex(),
FullName: in.FullName,
IdCard: in.IdCard,
Description: in.Description,
Expand Down
2 changes: 2 additions & 0 deletions biz/infrastructure/mapper/user/es.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/CloudStriver/cloudmind-content/biz/infrastructure/consts"
"github.com/CloudStriver/go-pkg/utils/pagination"
"github.com/CloudStriver/go-pkg/utils/pagination/esp"
"github.com/CloudStriver/go-pkg/utils/util/log"
"github.com/bytedance/sonic"
"github.com/elastic/go-elasticsearch/v8"
"github.com/elastic/go-elasticsearch/v8/typedapi/core/search"
Expand All @@ -33,6 +34,7 @@ func (e *EsMapper) Search(ctx context.Context, keyword string, popts *pagination
p := esp.NewEsPaginator(pagination.NewRawStore(sorter), popts)
s, sa, err := p.MakeSortOptions(ctx)
if err != nil {
log.CtxError(ctx, "创建索引异常[%v]\n", err)
return nil, 0, err
}
res, err := e.es.Search().Index(e.IndexName).Request(&search.Request{
Expand Down
4 changes: 2 additions & 2 deletions biz/infrastructure/mapper/user/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ func (m *MongoMapper) StartClient() *mongo.Client {
func (m *MongoMapper) Insert(ctx context.Context, data *User) (string, error) {
if data.ID.IsZero() {
data.ID = primitive.NewObjectID()
data.CreateAt = time.Now()
data.UpdateAt = time.Now()
}
data.CreateAt = time.Now()
data.UpdateAt = time.Now()

key := PrefixUserCacheKey + data.ID.Hex()
ID, err := m.conn.InsertOne(ctx, key, data)
Expand Down
25 changes: 0 additions & 25 deletions etc/config.toml

This file was deleted.

22 changes: 12 additions & 10 deletions etc/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ ListenOn: 0.0.0.0:2002
Mode: dev
Elasticsearch:
Addresses:
- http://localhost:9200
- http://118.89.172.143:9200
Username: elastic
Password:
Password: 5201314LS
##Monitoring
Prometheus:
Host: 0.0.0.0
Expand All @@ -15,7 +15,7 @@ Prometheus:
##Link Tracking
Telemetry:
Name: content
Endpoint: http://localhost:14268/api/traces
Endpoint: http://118.89.172.143:14268/api/traces
Sampler: 1.0
Batcher: jaeger

Expand All @@ -26,19 +26,21 @@ Log:
Encoding: plain

Redis:
Host: localhost:36379
Host: 118.89.172.143:6379
Type: node
Pass: admin
Pass: 5201314LS
Key: ""

Mongo:
Url: mongodb://localhost:27017/?connect=direct
Url: mongodb://root:[email protected]:27017,192.144.226.115:27017,134.175.180.149:27017/?replSet=rs0
DB: cloudmind_content

Cache:
- Host: localhost:36379
Pass: admin

- host: 118.89.172.143:6379
type: node
pass: 5201314LS
EtcdConf:
Hosts:
- localhost:2379
- 118.89.172.143:2379
- 192.144.226.115:2379
- 134.175.180.149:2379

0 comments on commit dee6909

Please sign in to comment.