Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyang0 committed Jun 29, 2024
0 parents commit 06712f4
Show file tree
Hide file tree
Showing 115 changed files with 16,594 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/binary.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: dev binary

on:
push:
branches:
- master

jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: "Setup go"
uses: actions/setup-go@v4

- name: "Build binary"
run: |
make
- uses: actions/upload-artifact@v3
with:
name: vmihub-ubuntu
path: bin/vmihub
31 changes: 31 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: golangci-lint
on:
push:
tags:
- '!v*'
branches:
- '*'
pull_request:

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'

- name: golangci-lint
uses: golangci/golangci-lint-action@v6
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: 'true'
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: latest
# Optional: show only new issues if it's a pull request. The default value is `false`.
only-new-issues: true
32 changes: 32 additions & 0 deletions .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: goreleaser

on:
push:
tags:
- v*

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up environment variables
run: |
echo "VERSION=$(git describe --tags $(git rev-list --tags --max-count=1))" >> $GITHUB_ENV
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20 changes: 20 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: test

on:
push:
tags:
- '!v*'
branches:
- '*'
pull_request:

jobs:
unittests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
- name: unit tests
run: make test
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/bin
cscope.*
tmp/
bk/
vendor/
dist/
.idea/
.DS_Store
.air.toml
config-dev.toml
config-prod.toml
/.vscode
config/vmihub.toml
102 changes: 102 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
run:
timeout: 5m
tests: false
modules-download-mode: readonly

issues:
exclude-dirs:
- vendor
- tools
- 3rdmocks
- e2e
- webconsole
- fs
- mocks
linters-settings:
nakedret:
max-func-lines: 59
misspell:
locale: US
ignore-words:
- hicloud
gofmt:
simplify: false
rewrite-rules:
- pattern: 'interface{}'
replacement: 'any'
- pattern: 'a[b:len(a)]'
replacement: 'a[b:]'
prealloc:
simple: false
range-loops: true
for-loops: true
errcheck:
check-type-assertions: true
gocritic:
disabled-checks:
- captLocal
nilnil:
checked-types:
- ptr
- func
- iface
- map
- chan
asasalint:
exclude:
- Append
- \.Wrapf
use-builtin-exclusions: false
ignore-test: true
usestdlibvars:
http-method: true
http-status-code: true
time-weekday: true
time-month: true
time-layout: true
crypto-hash: true
default-rpc-path: true
os-dev-null: true
sql-isolation-level: true
tls-signature-scheme: true
constant-kind: true
syslog-priority: true

linters:
disable-all: true
enable:
- usestdlibvars
- asasalint
- bodyclose
- nolintlint
- nosprintfhostport
- prealloc
- durationcheck
- errname
- goconst
- gocyclo
- gocognit
- interfacebloat
- makezero
- nilerr
- nilnil
- gofmt
- goimports
- revive
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- misspell
- nakedret
- exportloopref
- staticcheck
- typecheck
- unconvert
- unparam
- unused
- asciicheck
- nestif
- errcheck
- gocritic
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM golang:bookworm as gobuilder

WORKDIR /app
COPY . .

ENV GOPROXY https://goproxy.cn,direct
RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list.d/debian.sources
RUN apt-get update
RUN apt-get install -y libcephfs-dev librbd-dev librados-dev build-essential
RUN make deps CN=1
RUN make build CN=1
RUN ./bin/vmihub --version

FROM debian:bookworm

RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list.d/debian.sources && \
apt-get update && \
apt-get install -y libcephfs-dev librbd-dev librados-dev genisoimage qemu-utils
WORKDIR /app

COPY --from=gobuilder /app/bin/vmihub .

ENTRYPOINT [ "vmihub" ]
CMD ["--config", "config.toml", "server"]
28 changes: 28 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
The MIT License (MIT)

Original Work
Copyright (c) 2016 Matthias Kadenbach
https://github.com/mattes/migrate

Modified Work
Copyright (c) 2018 Dale Hui
https://github.com/golang-migrate/migrate


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.
93 changes: 93 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
ifeq ($(CN), 1)
ENV := GOPROXY=https://goproxy.cn,direct
endif

SOURCE_FILES = $(shell go list -f '{{range .GoFiles}}{{$$.Dir}}/{{.}}\
{{end}}' ./...)

NS := github.com/projecteru2/vmihub
REVISION := $(shell git rev-parse HEAD || unknown)
BUILTAT := $(shell date +%Y-%m-%dT%H:%M:%S)
VERSION := $(shell git describe --tags $(shell git rev-list --tags --max-count=1))
GO_LDFLAGS ?= -X $(NS)/internal/version.REVISION=$(REVISION) \
-X $(NS)/internal/version.BUILTAT=$(BUILTAT) \
-X $(NS)/internal/version.VERSION=$(VERSION)
ifneq ($(KEEP_SYMBOL), 1)
GO_LDFLAGS += -s
endif

BUILD := go build -race
TEST := go test -count=1 -race -cover -gcflags=all=-l

PKGS := $$(go list ./... | grep -v -P '$(NS)/3rd|vendor/|mocks|e2e|fs|webconsole|ovn')

.PHONY: all test e2e

default: build

build: bin/vmihub

bin/vmihub: $(SOURCE_FILES)
$(BUILD) -ldflags '$(GO_LDFLAGS)' -o "$@" ./cmd/vmihub

lint:
golangci-lint run

format: vet
gofmt -s -w $$(find . -iname '*.go' | grep -v -P '\./3rd|\./vendor/|mocks')

vet:
go vet $(PKGS)

deps:
$(ENV) go mod tidy
$(ENV) go mod vendor

mock: deps
mockery --dir internal/storage --output internal/storage/mocks --name Storage
mockery --dir client/image --output client/image/mocks --all

clean:
rm -fr bin/*

setup: setup-lint
$(ENV) go install github.com/vektra/mockery/v2@latest
$(ENV) go install github.com/swaggo/swag/cmd/swag@latest
$(ENV) go install -tags 'mysql' github.com/golang-migrate/migrate/v4/cmd/migrate@latest

setup-lint:
$(ENV) go install github.com/golangci/golangci-lint/cmd/[email protected]

swag:
swag init -g cmd/vmihub/main.go -o cmd/vmihub/docs

test:
ifdef RUN
$(TEST) -v -run='${RUN}' $(PKGS)
else
$(TEST) $(PKGS)
endif

e2e:
ifdef DIR
cp -f e2e/config.toml e2e/${DIR}/config.toml
cd e2e/${DIR} && ginkgo -r -p -- --config=`pwd`/config.toml
else
cd e2e && ginkgo -r -p -- --config=`pwd`/config.toml
endif

db-migrate-setup:
curl -L https://github.com/golang-migrate/migrate/releases/download/v4.17.1/migrate.linux-amd64.tar.gz | tar xvz
mv migrate /usr/local/bin/

db-migrate-create:
migrate create -ext sql -dir internal/models/migration ${table}

db-migrate-up:
migrate -database '${uri}' -path internal/models/migration up

db-migrate-down:
migrate -database '${uri}' -path internal/models/migration down ${N}

db-migrate-setver:
migrate -database '${uri}' -path internal/models/migration force ${ver}
Loading

0 comments on commit 06712f4

Please sign in to comment.