Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #245

Merged
merged 3 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.19
go-version: 1.20.0

- name: Set up Node
uses: actions/setup-node@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.19
go-version: 1.20.0

- name: Install linter
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.19
go-version: 1.20.0

- name: Set up Node
uses: actions/setup-node@v2
Expand Down
5 changes: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@ vendor/*
/smart-home
/conf/config.json
/conf/dbconfig.yml
/api/server/v1/docs/docs.go
/api/server/v1/docs/swagger/swagger.json
/api/server/v2/docs/docs.go
/api/server/v2/docs/swagger/swagger.json
.DS_Store
snapshots/*
!snapshots/.gitignore
bee.json
/api/server/golang-swaggerui-example/
/conf/notify.json
/cmd/pingmq/pingmq
._*
cli-*
Expand Down
45 changes: 5 additions & 40 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -131,52 +131,17 @@ build_public:

server:
@echo "Building http server"
cd ${ROOT}/api/protos/ && \
mkdir -p ${ROOT}/api/stub && \
protoc -I. \
-I${GOPATH}/src \
-I${GOPATH}/pkg/mod/github.com/grpc-ecosystem/[email protected]/third_party/googleapis \
-I${GOPATH}/pkg/mod/github.com/grpc-ecosystem/[email protected] \
--grpc-gateway_out=logtostderr=true:${ROOT}/api/stub \
*.proto

@echo "Building grpc server"
cd ${ROOT}/api/protos/ && \
mkdir -p ${ROOT}/api/stub && \
protoc -I. \
-I${GOPATH}/src \
-I${GOPATH}/pkg/mod/github.com/grpc-ecosystem/[email protected]/third_party/googleapis \
-I${GOPATH}/pkg/mod/github.com/grpc-ecosystem/[email protected] \
--go-grpc_out=require_unimplemented_servers=false:${ROOT}/api/stub \
*.proto

@echo "Building protobuf files"
cd ${ROOT}/api/protos/ && \
mkdir -p ${ROOT}/api/stub && \
protoc -I. \
-I${GOPATH}/src \
-I${GOPATH}/pkg/mod/github.com/grpc-ecosystem/[email protected]/third_party/googleapis \
-I${GOPATH}/pkg/mod/github.com/grpc-ecosystem/[email protected] \
--go_out=${ROOT}/api/stub \
*.proto

@echo "Building swagger.json"
cd ${ROOT}/api/protos/ && \
protoc -I. \
-I${GOPATH}/src \
-I${GOPATH}/pkg/mod/github.com/grpc-ecosystem/[email protected]/third_party/googleapis \
-I${GOPATH}/pkg/mod/github.com/grpc-ecosystem/grpc-gateway/[email protected]/protoc-gen-openapiv2 \
-I${GOPATH}/pkg/mod/github.com/grpc-ecosystem/[email protected] \
--openapiv2_out=allow_merge=true,merge_file_name=api,logtostderr=true:${ROOT}/api \
*.proto
oapi-codegen -generate server -package stub ${ROOT}/api/api.swagger3.yaml > ${ROOT}/api/stub/server.go && \
oapi-codegen -generate types -package stub ${ROOT}/api/api.swagger3.yaml > ${ROOT}/api/stub/types.go

build_structure:
@echo MARK: create app structure
mkdir -p ${SERVER_DIR}
mkdir -p ${SERVER_DIR}/snapshots
cd ${SERVER_DIR}
cp -r ${ROOT}/conf ${SERVER_DIR}
cp -r ${ROOT}/data ${SERVER_DIR}
cp -r ${ROOT}/snapshots ${SERVER_DIR}
cp ${ROOT}/LICENSE ${SERVER_DIR}
cp ${ROOT}/README* ${SERVER_DIR}
cp ${ROOT}/CONTRIBUTING.md ${SERVER_DIR}
Expand All @@ -197,10 +162,10 @@ build_structure:
build_common_structure:
@echo MARK: create common structure
mkdir -p ${COMMON_DIR}
mkdir -p ${COMMON_DIR}/snapshots
cd ${COMMON_DIR}
cp -r ${ROOT}/conf ${COMMON_DIR}
cp -r ${ROOT}/data ${COMMON_DIR}
cp -r ${ROOT}/snapshots ${COMMON_DIR}
cp ${ROOT}/LICENSE ${COMMON_DIR}
cp ${ROOT}/README* ${COMMON_DIR}
cp ${ROOT}/CONTRIBUTING.md ${COMMON_DIR}
Expand Down Expand Up @@ -276,4 +241,4 @@ clean:

front_client:
@echo MARK: generate front client lib
npx [email protected] --axios -p ./api/api.swagger.json -o ./static_source/admin/src/api -n stub_new.ts
npx [email protected] --axios -p ./api/api.swagger3.yaml -o ./static_source/admin/src/api -n stub_new.ts
226 changes: 226 additions & 0 deletions Makefile.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
.PHONY: get_deps fmt
.DEFAULT_GOAL := build
build: build_public build_server build_cli
tests: lint test
all: build build_structure build_common_structure build_archive docker_image
deploy: docker_image_upload

EXEC=server
CLI=cli
ROOT := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
SERVER_DIR = ${ROOT}/tmp/${EXEC}
COMMON_DIR = ${ROOT}/tmp/common
ARCHIVE=smart-home-common.tar.gz

PROJECT ?=github.com/e154/smart-home
TRAVIS_BUILD_NUMBER ?= local
HOME ?= ${ROOT}

REV_VALUE=$(shell git rev-parse HEAD 2> /dev/null || echo "???")
REV_URL_VALUE=https://${PROJECT}/commit/${REV_VALUE}
GENERATED_VALUE=$(shell date -u +'%Y-%m-%dT%H:%M:%S%z')
DEVELOPERS_VALUE=delta54<[email protected]>
BUILD_NUMBER_VALUE=$(shell echo ${TRAVIS_BUILD_NUMBER})
RELEASE_VERSION ?= v0.1.0

IMAGE=smart-home-${EXEC}
DOCKER_ACCOUNT ?= 192.168.43.127:5000
DOCKER_IMAGE_VER=${DOCKER_ACCOUNT}/${IMAGE}:${RELEASE_VERSION}
DOCKER_IMAGE_LATEST=${DOCKER_ACCOUNT}/${IMAGE}:latest

VERSION_VAR=${PROJECT}/version.VersionString
REV_VAR=${PROJECT}/version.RevisionString
REV_URL_VAR=${PROJECT}/version.RevisionURLString
GENERATED_VAR=${PROJECT}/version.GeneratedString
DEVELOPERS_VAR=${PROJECT}/version.DevelopersString
BUILD_NUMBER_VAR=${PROJECT}/version.BuildNumString
DOCKER_IMAGE_VAR=${PROJECT}/version.DockerImageString
GO_BUILD_LDFLAGS= -s -w -X ${VERSION_VAR}=${RELEASE_VERSION} -X ${REV_VAR}=${REV_VALUE} -X ${REV_URL_VAR}=${REV_URL_VALUE} -X ${GENERATED_VAR}=${GENERATED_VALUE} -X ${DEVELOPERS_VAR}=${DEVELOPERS_VALUE} -X ${BUILD_NUMBER_VAR}=${BUILD_NUMBER_VALUE} -X ${DOCKER_IMAGE_VAR}=${DOCKER_IMAGE_VER}
GO_BUILD_FLAGS= -a -installsuffix cgo -v --ldflags '${GO_BUILD_LDFLAGS}'
GO_BUILD_ENV= CGO_ENABLED=0
GO_BUILD_TAGS= -tags 'production'

test_system:
@echo MARK: system tests
cp ${ROOT}/conf/config.dev.json ${ROOT}/conf/config.json
go test -v ./tests/api
go test -v ./tests/models
go test -v ./tests/scripts
go test -v ./tests/system
go test -v ./tests/plugins/alexa
go test -v ./tests/plugins/area
go test -v ./tests/plugins/cgminer
go test -v ./tests/plugins/email
go test -v ./tests/plugins/messagebird
#go test -v ./tests/plugins/modbus_rtu
#go test -v ./tests/plugins/modbus_tcp
go test -v ./tests/plugins/moon
go test -v ./tests/plugins/node
go test -v ./tests/plugins/scene
go test -v ./tests/plugins/sensor
go test -v ./tests/plugins/sun
go test -v ./tests/plugins/telegram
go test -v ./tests/plugins/trigger_alexa
go test -v ./tests/plugins/trigger_empty
go test -v ./tests/plugins/trigger_state
go test -v ./tests/plugins/trigger_system
go test -v ./tests/plugins/trigger_time
go test -v ./tests/plugins/twilio
go test -v ./tests/plugins/weather_met
go test -v ./tests/plugins/weather_owm
go test -v ./tests/plugins/zigbee2mqtt

test:
@echo MARK: unit tests
go test $(go list ./... | grep -v /tests/)
go test -race $(go list ./... | grep -v /tests/)

install_linter:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin v1.45.0

lint-todo:
@echo MARK: make lint todo

lint:
golangci-lint run

get_deps:
go mod tidy

fmt:
@gofmt -l -w -s .
@goimports -w .

comments:
@echo MARK: update comments
@gocmt -i -d .

svgo:
DIR=${ROOT}/data/icons/*
cd ${ROOT} && svgo ${DIR} --enable=inlineStyles --config '{ "plugins": [ { "inlineStyles": { "onlyMatchedOnce": false } }] }' --pretty

build_server:
@echo MARK: build server
#${GO_BUILD_ENV} GOOS=linux GOARCH=amd64 go build ${GO_BUILD_FLAGS} ${GO_BUILD_TAGS} -o ${ROOT}/${EXEC}-linux-amd64
${GO_BUILD_ENV} GOOS=linux GOARCH=arm GOARM=7 go build ${GO_BUILD_FLAGS} ${GO_BUILD_TAGS} -o ${ROOT}/${EXEC}-linux-arm-7
#${GO_BUILD_ENV} GOOS=linux GOARCH=arm GOARM=6 go build ${GO_BUILD_FLAGS} ${GO_BUILD_TAGS} -o ${ROOT}/${EXEC}-linux-arm-6
#${GO_BUILD_ENV} GOOS=linux GOARCH=arm GOARM=5 go build ${GO_BUILD_FLAGS} ${GO_BUILD_TAGS} -o ${ROOT}/${EXEC}-linux-arm-5
#${GO_BUILD_ENV} GOOS=darwin GOARCH=amd64 go build ${GO_BUILD_FLAGS} ${GO_BUILD_TAGS} -o ${ROOT}/${EXEC}-darwin-10.6-amd64
#${GO_BUILD_ENV} GOOS=darwin GOARCH=arm64 go build ${GO_BUILD_FLAGS} ${GO_BUILD_TAGS} -o ${ROOT}/${EXEC}-darwin-10.6-arm64

build_cli:
@echo MARK: build cli
#cd ${ROOT}/cmd/cli && ${GO_BUILD_ENV} GOOS=linux GOARCH=amd64 go build ${GO_BUILD_FLAGS} ${GO_BUILD_TAGS} -o ${ROOT}/${CLI}-linux-amd64
#cd ${ROOT}/cmd/cli && ${GO_BUILD_ENV} GOOS=darwin GOARCH=amd64 go build ${GO_BUILD_FLAGS} ${GO_BUILD_TAGS} -o ${ROOT}/${CLI}-darwin-10.6-amd64
#cd ${ROOT}/cmd/cli && ${GO_BUILD_ENV} GOOS=darwin GOARCH=arm64 go build ${GO_BUILD_FLAGS} ${GO_BUILD_TAGS} -o ${ROOT}/${CLI}-darwin-10.6-arm64

build_public:
@echo MARK: build public
echo -e "node version.\n" && \
node -v && \
echo -e "npm version.\n" && \
npm -v && \
echo -e "pnpm version.\n" && \
pnpm -v && \
cd ${ROOT}/static_source/admin && \
pnpm run build:pro && \
rm -rf ${ROOT}/build/public && \
mkdir -p ${ROOT}/build && \
mv ${ROOT}/static_source/admin/dist-pro ${ROOT}/build/public

server:
@echo "Building http server"
mkdir -p ${ROOT}/api/stub && \
oapi-codegen -generate server -package stub ${ROOT}/api/api.swagger3.yaml > ${ROOT}/api/stub/server.go && \
oapi-codegen -generate types -package stub ${ROOT}/api/api.swagger3.yaml > ${ROOT}/api/stub/types.go

build_structure:
@echo MARK: create app structure
mkdir -p ${SERVER_DIR}
mkdir -p ${SERVER_DIR}/snapshots
cd ${SERVER_DIR}
cp -r ${ROOT}/conf ${SERVER_DIR}
cp -r ${ROOT}/data ${SERVER_DIR}
cp ${ROOT}/LICENSE ${SERVER_DIR}
cp ${ROOT}/README* ${SERVER_DIR}
cp ${ROOT}/CONTRIBUTING.md ${SERVER_DIR}
cp ${ROOT}/bin/docker/Dockerfile ${SERVER_DIR}
cp ${ROOT}/bin/server-installer.sh ${SERVER_DIR}
chmod +x ${SERVER_DIR}/data/scripts/ping.sh
cp ${ROOT}/${EXEC}-linux-arm-7 ${SERVER_DIR}
cp ${ROOT}/bin/server ${SERVER_DIR}

build_common_structure:
@echo MARK: create common structure
mkdir -p ${COMMON_DIR}
mkdir -p ${COMMON_DIR}/snapshots
cd ${COMMON_DIR}
cp -r ${ROOT}/conf ${COMMON_DIR}
cp -r ${ROOT}/data ${COMMON_DIR}
cp ${ROOT}/LICENSE ${COMMON_DIR}
cp ${ROOT}/README* ${COMMON_DIR}
cp ${ROOT}/CONTRIBUTING.md ${COMMON_DIR}
cp ${ROOT}/bin/docker/Dockerfile ${COMMON_DIR}
cp ${ROOT}/bin/server-installer.sh ${COMMON_DIR}
chmod +x ${COMMON_DIR}/data/scripts/ping.sh
cp ${ROOT}/bin/server ${COMMON_DIR}

build_archive:
@echo MARK: build app archive
cd ${COMMON_DIR} && ls -l && tar -zcf ${ROOT}/${ARCHIVE} .

build_docs:
@echo MARK: build doc
cd ${ROOT}/doc
npm install postcss-cli
hugo --gc --minify

docs_dev:
cd ${ROOT}/doc
hugo server --buildDrafts --verbose --source="${ROOT}/doc" --config="${ROOT}/doc/config.toml" --port=1377 --disableFastRender

docs_deploy:
@echo MARK: deploy doc
cd ${ROOT}/doc && \
echo -e "node version.\n" && \
node -v && \
echo -e "npm version.\n" && \
npm -v && \
npm install -f && \
echo -e "hugo version.\n" && \
hugo version && \
hugo --gc --minify

cd ${ROOT}/doc/public && \
git init && \
echo -e "Starting to documentation commit.\n" && \
git config --global user.email "[email protected]" && \
git config --global user.name "delta54" && \
git remote add upstream "https://${GITHUB_OAUTH_TOKEN}@github.com/e154/smart-home.git" && \
git fetch upstream && \
git reset upstream/gh-pages && \
rev=$(git rev-parse --short HEAD) && \
git add -A . && \
git commit -m "rebuild pages at ${rev}" && \
git push -q upstream HEAD:gh-pages
echo -e "Done documentation deploy.\n"

docker_image:
cd ${SERVER_DIR} && ls -ll && docker build -f ${ROOT}/bin/docker/Dockerfile -t ${DOCKER_ACCOUNT}/${IMAGE} .

docker_image_upload:
#echo ${DOCKER_PASSWORD} | docker login -u ${DOCKER_USERNAME} --password-stdin
docker tag ${DOCKER_ACCOUNT}/${IMAGE} ${DOCKER_IMAGE_VER}
echo -e "docker tag ${DOCKER_ACCOUNT}/${IMAGE} ${DOCKER_IMAGE_LATEST}"
docker tag ${DOCKER_ACCOUNT}/${IMAGE} ${DOCKER_IMAGE_LATEST}
docker push ${DOCKER_IMAGE_VER}
docker push ${DOCKER_IMAGE_LATEST}

clean:
@echo MARK: clean
rm -rf ${SERVER_DIR}
rm -f ${ROOT}/${EXEC}-linux-arm-7

front_client:
@echo MARK: generate front client lib
npx [email protected] --axios -p ./api/api.swagger3.yaml -o ./static_source/admin/src/api -n stub_new.ts
15 changes: 1 addition & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,20 +132,7 @@ Run these two commands in your terminal to add Homebrew to your PATH:
eval "$(/opt/homebrew/bin/brew shellenv)"
```

install protobuf v3
```bash
brew update && brew install protobuf@3
```

```bash
go install \
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway \
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2 \
google.golang.org/protobuf/cmd/protoc-gen-go \
google.golang.org/grpc/cmd/protoc-gen-go-grpc
```

download from https://github.com/grpc-ecosystem/grpc-gateway/releases/tag/v2.14.0
install github.com/deepmap/oapi-codegen version v1.13.0

generate api stub
```bash
Expand Down
Loading
Loading