Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
CMGS committed Jul 2, 2024
1 parent eeb69f6 commit ea85dfa
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 39 deletions.
11 changes: 4 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@ 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 apt update -y \
apt 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
RUN apt update -y && \
apt install -y libcephfs-dev librbd-dev librados-dev genisoimage qemu-utils
WORKDIR /app

COPY --from=gobuilder /app/bin/vmihub .
Expand Down
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
vmihub
VMIhub
====
![](https://github.com/projecteru2/vmihub/workflows/test/badge.svg)
![](https://github.com/projecteru2/vmihub/workflows/golangci-lint/badge.svg)

virtual machine image hub for ERU

# swagger
### Swagger
generate swagger
```shell
make swag
```

### Mac 下安装swagger
#### Install swagger on MacOS
https://github.com/swaggo/swag/blob/v1.16.1/README_zh-CN.md

generate swagger
Generate swagger
```shell
swag init -g cmd/vmihub/main.go -o cmd/vmihub/docs
```
# 准备redis
常规准备就好

# 准备数据库
不管是第一次初始化数据库还是后续数据库schema的修改请都参考 [这里](internal/models/migration/README.md)
# 准备s3
用于存储镜像文件
### Redis
Require Redis

### DB
[ReadME](internal/models/migration/README.md)

# 编译
### S3
Local can use minio

### Build
```shell
make
```

# 项目启动
### Start
```shell
bin/vmihub --config=config/config.example.toml server
```
5 changes: 3 additions & 2 deletions cmd/vmihub/docs/docs.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Code generated by swaggo/swag. DO NOT EDIT.

// Package docs Code generated by swaggo/swag. DO NOT EDIT
package docs

import "github.com/swaggo/swag"
Expand Down Expand Up @@ -1522,6 +1521,8 @@ var SwaggerInfo = &swag.Spec{
Description: "this is vmihub server.",
InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate,
LeftDelim: "{{",
RightDelim: "}}",
}

func init() {
Expand Down
8 changes: 8 additions & 0 deletions pkg/terrors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ var (
ErrConfict = errors.New("conflict")
ErrInvalidUserKey = errors.New("invalid username or key")
ErrInvalidState = errors.New("guest state is invalid")
ErrInvalidUserName = errors.New("invalid username")
ErrInvalidPassword = errors.New("invalid password")

ErrIPAMNoAvailableIP = errors.New("no available IP")
ErrIPAMNotReserved = errors.New("IP is not reserved")
Expand All @@ -32,6 +34,12 @@ var (

ErrPublicPortNotReserved = errors.New("Public port is not reserved")
ErrPublicPortAlreadyAllocated = errors.New("Public port is already allocated")

ErrInvalidSha1 = errors.New("invalid digest, only accept sha256")
ErrInvalidOS = errors.New("os type is empty")
ErrInvalidDistrib = errors.New("os distrib is empty")
ErrInvalidArch = errors.New("os arch is empty")
ErrInvalidFormat = errors.New("format is empty")
)

type ErrHTTPResp struct { //nolint
Expand Down
12 changes: 6 additions & 6 deletions pkg/types/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"
"time"

"github.com/pkg/errors"
"github.com/projecteru2/vmihub/pkg/terrors"
)

type JSONResult struct {
Expand Down Expand Up @@ -48,20 +48,20 @@ type ImageCreateRequest struct {

func (req *ImageCreateRequest) Check() error {
if req.URL == "" && len(req.Digest) != 64 {
return errors.New("invalid digest, only accept sha256")
return terrors.ErrInvalidSha1
}
if req.OS.Type == "" {
return errors.New("os type is empty")
return terrors.ErrInvalidOS
}
req.OS.Type = strings.ToLower(req.OS.Type)
if req.OS.Type == "linux" && req.OS.Distrib == "" {
return errors.New("os distrib is empty")
return terrors.ErrInvalidOS
}
if req.OS.Arch == "" {
return errors.New("os arch is empty")
return terrors.ErrInvalidArch
}
if req.Format == "" {
return errors.New("format is empty")
return terrors.ErrInvalidFormat
}
return nil
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/types/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package types
import (
"time"

"github.com/cockroachdb/errors"
"github.com/projecteru2/vmihub/pkg/terrors"
)

// RegisterRequest 定义用户登录结构体
Expand Down Expand Up @@ -36,7 +36,7 @@ type ResetUserPwdRequest struct {

func (req *ResetUserPwdRequest) Check() error {
if req.Password != req.Password1 {
return errors.New("password not match")
return terrors.ErrInvalidUserPass
}
return nil
}
Expand All @@ -49,10 +49,10 @@ type LoginRequest struct {

func (req *LoginRequest) Check() error {
if req.Password == "" {
return errors.New("password should not both be empty")
return terrors.ErrInvalidPassword
}
if req.Username == "" {
return errors.New("username should not be empty")
return terrors.ErrInvalidUserName
}
return nil
}
Expand Down
5 changes: 1 addition & 4 deletions pkg/utils/digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"os"
"strings"

"github.com/pkg/errors"
"github.com/projecteru2/vmihub/client/terrors"
)

Expand All @@ -29,11 +28,9 @@ func CalcDigestOfFile(fname string) (string, error) {
if err != nil {
return "", err
}

defer f.Close()

h := sha256.New()

if _, err = io.Copy(h, f); err != nil {
return "", err
}
Expand Down Expand Up @@ -95,7 +92,7 @@ func ParseImageName(imgName string) (user, name, tag string, err error) {
user = "_"
}
if strings.Contains(tag, ":") {
err = errors.Wrapf(terrors.ErrInvalidImageName, "invlaid tag %s", tag)
err = fmt.Errorf("%w invalid tag %s", terrors.ErrInvalidImageName, tag)
}
return
}
4 changes: 0 additions & 4 deletions spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ builds:
version: "HEAD"
dir: /go/src/github.com/projecteru2/vmihub
commands:
- 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
- make deps CN=1
Expand All @@ -43,10 +42,7 @@ builds:
version: latest
app: vmihub
app_entry: vmihub_main
# envs:
# AGENT_IN_DOCKER: 1
commands:
- 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 ca-certificates libcephfs-dev librbd-dev librados-dev genisoimage qemu-utils
- update-ca-certificates
Expand Down

0 comments on commit ea85dfa

Please sign in to comment.