Skip to content

Commit

Permalink
Merge pull request #46 from go-atomci/feat-project-layout
Browse files Browse the repository at this point in the history
Feat project layout
  • Loading branch information
sampsonye committed Jan 11, 2022
2 parents 3af9f1e + a4fa943 commit 1a5e632
Show file tree
Hide file tree
Showing 113 changed files with 555 additions and 613 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ export PROJECT_ROOT := $(CURDIR)

## linux-amd64: Compile linux-amd64 package
linux-amd64:
@env GOOS=linux GOARCH=amd64 go build -o deploy/binary/$(NAME)-linux-amd64
@env GOOS=linux GOARCH=amd64 go build -o deploy/binary/$(NAME)-linux-amd64 cmd/atomci/main.go

## linux-arm64: Compile linux-amd64 package
linux-arm64:
@env GOOS=linux GOARCH=arm64 go build -o deploy/binary/$(NAME)-linux-arm64
@env GOOS=linux GOARCH=arm64 go build -o deploy/binary/$(NAME)-linux-arm64 cmd/atomci/main.go

.PHONY: build
## build: Compile the packages.
build:
@go build -o $(NAME)
@go build -o $(NAME) cmd/atomci/main.go

.PHONY: run
## run: Build and Run in local mode.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ url = root:root@tcp(127.0.0.1:3306)/atomci?charset=utf8mb4
$ make run

# windowns环境,或是没有make命令
$ go build -o atomci ; ./atomci
$ go build -o atomci cmd/atomci/main.go; ./atomci
```

### 启动前端
Expand Down
11 changes: 6 additions & 5 deletions cmd/atomci/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,22 @@ import (
"github.com/astaxie/beego"
_ "github.com/go-sql-driver/mysql" // import your used driver

_ "github.com/go-atomci/atomci/initialize"
_ "github.com/go-atomci/atomci/models"
_ "github.com/go-atomci/atomci/internal/initialize"
_ "github.com/go-atomci/atomci/internal/models"
"github.com/go-atomci/atomci/pkg/kube"
_ "github.com/go-atomci/atomci/routers"
"github.com/go-atomci/atomci/servers"
"github.com/go-atomci/atomci/internal/routers"
"github.com/go-atomci/atomci/internal/cronjob"
)

func init() {
kube.Init()
}

func main() {
servers.RunPublishJobServer()
cronjob.RunPublishJobServer()
beego.Info("Beego version:", beego.VERSION)

routers.RegisterRoutes()
beego.Info("Golang version:", runtime.Version())
beego.Run()
}
87 changes: 0 additions & 87 deletions common/common.go

This file was deleted.

90 changes: 90 additions & 0 deletions conf/rbac_policy.csv
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,94 @@ p, developer, /atomci/api/v1/repos, GET
p, developer, /atomci/api/v1/repos/:repo_id/projects, POST
p, developer, /atomci/api/v1/integrate/compile_envs, GET
p, developer, /atomci/api/v1/projects/:project_id/apps/create, POST
p, devManager, /atomci/api/v1/clusters/:cluster/namespaces/:namespace/apps/:app/restart, POST
p, devManager, /atomci/api/v1/clusters/:cluster/namespaces/:namespace/apps/:app/scale, POST
p, devManager, /atomci/api/v1/clusters/:cluster/namespaces/:namespace/pods/:podname/containernames/:containername, GET
p, devManager, /publishctl/api/v1/projects/:project_id/pipelines, PUT
p, devManager, /publishctl/api/v1/projects/:project_id/apps/branches, POST
p, devManager, /publishctl/api/v1/projects/create, POST
p, devManager, /publishctl/api/v1/projects/:project_id/apps/create, POST
p, devManager, /atomci/api/v1/projects/:project_id/envs/create, POST
p, devManager, /atomci/api/v1/clusters/:cluster/namespaces/:namespace/apps/:app, DELETE
p, devManager, /publishctl/api/v1/projects/:project_id/pipelines/:id, DELETE
p, devManager, /publishctl/api/v1/projects/:project_id, DELETE
p, devManager, /publishctl/api/v1/projects/:project_id/apps/:project_app_id, DELETE
p, devManager, /publishctl/api/v1/projects/:project_id/members/:id, DELETE
p, devManager, /atomci/api/v1/pipelines/flow/steps, GET
p, devManager, /publishctl/api/v1/projects/:project_id/apps/:app_id/branches, POST
p, devManager, /publishctl/api/v1/projects/:project_id/apps, POST
p, devManager, /atomci/api/v1/clusters/:cluster/namespaces/:namespace/apps/:app/event, GET
p, devManager, /atomci/api/v1/clusters/:cluster/namespaces/:namespace/apps/:app, GET
p, devManager, /atomci/api/v1/clusters/:cluster/namespaces/:namespace/apps/:app/log, GET
p, devManager, /publishctl/api/v1/projects/:project_id/apps/:app_id/:arrange_env/arrange, GET
p, devManager, /publishctl/api/v1/projects/:project_id/arrange_env/:arrange_env/bizclusters, GET
p, devManager, /atomci/api/v1/pipelines/stages/:stage_id/jenkins-config, GET
p, devManager, /publishctl/api/v1/projects/:project_id/arrange_env/:arrange_env/namespaces, GET
p, devManager, /publishctl/api/v1/projects/:project_id/arrange_env/:arrange_env/nodes, GET
p, devManager, /publishctl/api/v1/projects/:project_id, GET
p, devManager, /publishctl/api/v1/projects/:project_id/apps/:project_app_id, GET
p, devManager, /publishctl/api/v1/projects/:project_id/apps, GET
p, devManager, /atomci/api/v1/projects/:project_id/clusters/:cluster/apps, POST
p, devManager, /atomci/api/v1/projects/:project_id/envs, GET
p, devManager, /atomci/api/v1/projects/:project_id/envs, POST
p, devManager, /publishctl/api/v1/projects/:project_id/members, GET
p, devManager, /publishctl/api/v1/projects/:project_id/pipelines, GET
p, devManager, /atomci/api/v1/projects/:project_id/pipelines, POST
p, devManager, /atomci/api/v1/arrange/yaml/parser, POST
p, devManager, /atomci/api/v1/projects/:project_id/pipelines/create, POST
p, devManager, /atomci/api/v1/projects/:project_id/pipelines/:id, DELETE
p, devManager, /atomci/api/v1/projects/:project_id/pipelines/:id, PUT
p, devManager, /caas/api/v1/projects/:project_id/apps/stats, GET
p, devManager, /publishctl/api/v1/projects, POST
p, devManager, /publishctl/api/v1/projects/:project_id/pipelines/:id, GET
p, devManager, /publishctl/api/v1/projects/:project_id/publish/stats, POST
p, devManager, /publishctl/api/v1/projects/:project_id/apps/:app_id/:arrange_env/arrange, POST
p, devManager, /publishctl/api/v1/projects/:project_id/apps/:project_app_id, PATCH
p, devManager, /publishctl/api/v1/projects/:project_id/apps/:app_id/syncBranches, POST
p, devManager, /publishctl/api/v1/projects/:project_id, PUT
p, devManager, /publishctl/api/v1/projects/:project_id/apps/:project_app_id, PUT
p, devManager, /atomci/api/v1/projects/:project_id/envs/:env_id, PUT
p, devManager, /publishctl/api/v1/projects/:project_id/members, PUT
p, devManager, /publishctl/api/v1/projects/:project_id/publishes/:publish_id/apps/create, POST
p, devManager, /publishctl/api/v1/projects/:project_id/publishes/:publish_id, PUT
p, devManager, /publishctl/api/v1/projects/:project_id/publishes/create, POST
p, devManager, /publishctl/api/v1/projects/:project_id/publishes/:publish_id, DELETE
p, devManager, /publishctl/api/v1/projects/:project_id/publishes/:publish_id/apps/:publish_app_id, DELETE
p, devManager, /publishctl/api/v1/projects/:project_id/publishes/:publish_id/stages/:stage_id/back-to, GET
p, devManager, /publishctl/api/v1/projects/:project_id/publishes/:publish_id/apps/can_added, GET
p, devManager, /publishctl/api/v1/pipelines/stages/:stage_id/jenkins-config, GET
p, devManager, /publishctl/api/v1/projects/:project_id/publishes/:publish_id/stages/:stage_id/next-stage, GET
p, devManager, /publishctl/api/v1/projects/:project_id/publishes/:publish_id/audits, POST
p, devManager, /publishctl/api/v1/projects/:project_id/publishes/:publish_id, GET
p, devManager, /publishctl/api/v1/publish/setup, GET
p, devManager, /publishctl/api/v1/pipelines/:project_id/publishes/:publish_id/stages/:stage_id/steps/:step_name, GET
p, devManager, /publishctl/api/v1/projects/:project_id/publishes, POST
p, devManager, /publishctl/api/v1/pipelines/:project_id/publishes/:publish_id/stages/:stage_id/steps/:step_name, POST
p, devManager, /publishctl/api/v1/pipelines/:project_id/publishes/:publish_id/stages/:stage_id/steps/:step_name/callback, POST
p, devManager, /publishctl/api/v1/projects/:project_id/publishes/:publish_id/stages/:stage_id/back-to, POST
p, devManager, /publishctl/api/v1/projects/:project_id/publishes/:publish_id/stages/:stage_id/next-stage, POST
p, devManager, /publishctl/api/v1/publish/setup, POST
p, devManager, /publishctl/api/v1/getCurrentUser, GET
p, devManager, /publishctl/api/v1/login, POST
p, devManager, /publishctl/api/v1/logout, GET
p, devManager, /publishctl/api/v1/pipelines/flow/components, GET
p, devManager, /publishctl/api/v1/pipelines/flow/stages/create, POST
p, devManager, /publishctl/api/v1/pipelines/flow/stages/:stage_id, DELETE
p, devManager, /publishctl/api/v1/pipelines/flow/stages, GET
p, devManager, /publishctl/api/v1/pipelines/flow/stages, POST
p, devManager, /publishctl/api/v1/pipelines/flow/stages/:stage_id, PUT
p, devManager, /publishctl/api/v1/pipelines/flow/steps/create, POST
p, devManager, /publishctl/api/v1/pipelines/flow/steps/:step_id, DELETE
p, devManager, /publishctl/api/v1/pipelines/flow/steps, GET
p, devManager, /publishctl/api/v1/pipelines/flow/steps, POST
p, devManager, /publishctl/api/v1/pipelines/flow/steps/:step_id, PUT
p, devManager, /publishctl/api/v1/pipelines/clusters, GET
p, devManager, /publishctl/api/v1/pipelines/:pipeline_id/setup, GET
p, devManager, /publishctl/api/v1/pipelines/create, POST
p, devManager, /publishctl/api/v1/pipelines/:pipeline_id, DELETE
p, devManager, /publishctl/api/v1/pipelines, GET
p, devManager, /publishctl/api/v1/pipelines, POST
p, devManager, /publishctl/api/v1/pipelines/:pipeline_id, PUT
p, devManager, /publishctl/api/v1/pipelines/reset, POST
p, devManager, /publishctl/api/v1/pipelines/:pipeline_id/setup, PUT
g, admin, developer
8 changes: 4 additions & 4 deletions controllers/app.go → internal/api/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package controllers
package api

import (
"github.com/go-atomci/atomci/core/apps"
"github.com/go-atomci/atomci/core/kuberes"
"github.com/go-atomci/atomci/middleware/log"
"github.com/go-atomci/atomci/internal/core/apps"
"github.com/go-atomci/atomci/internal/core/kuberes"
"github.com/go-atomci/atomci/internal/middleware/log"
"github.com/go-atomci/atomci/utils/errors"
)

Expand Down
6 changes: 3 additions & 3 deletions controllers/audit.go → internal/api/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package controllers
package api

import (
"github.com/go-atomci/atomci/dao"
"github.com/go-atomci/atomci/middleware/log"
"github.com/go-atomci/atomci/internal/dao"
"github.com/go-atomci/atomci/internal/middleware/log"
)

type AuditController struct {
Expand Down
18 changes: 9 additions & 9 deletions controllers/auth.go → internal/api/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package controllers
package api

import (
"encoding/json"
Expand All @@ -24,17 +24,17 @@ import (
"github.com/astaxie/beego"

"github.com/go-atomci/atomci/constant"
"github.com/go-atomci/atomci/dao"
"github.com/go-atomci/atomci/middleware"
"github.com/go-atomci/atomci/models"
"github.com/go-atomci/atomci/internal/dao"
"github.com/go-atomci/atomci/internal/middleware"
"github.com/go-atomci/atomci/internal/models"
"github.com/go-atomci/atomci/utils"

mycasbin "github.com/go-atomci/atomci/middleware/casbin"
"github.com/go-atomci/atomci/middleware/log"
mycasbin "github.com/go-atomci/atomci/internal/middleware/casbin"
"github.com/go-atomci/atomci/internal/middleware/log"

"github.com/go-atomci/atomci/core/auth"
"github.com/go-atomci/atomci/core/auth/ldap"
"github.com/go-atomci/atomci/core/auth/local"
"github.com/go-atomci/atomci/internal/core/auth"
"github.com/go-atomci/atomci/internal/core/auth/ldap"
"github.com/go-atomci/atomci/internal/core/auth/local"
)

// AuthController .operations about login/logout
Expand Down
24 changes: 17 additions & 7 deletions controllers/base.go → internal/api/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package controllers
package api

import (
"encoding/json"
Expand All @@ -26,11 +26,10 @@ import (
"github.com/astaxie/beego"
"github.com/astaxie/beego/validation"

"github.com/go-atomci/atomci/common"
"github.com/go-atomci/atomci/dao"
"github.com/go-atomci/atomci/middleware"
"github.com/go-atomci/atomci/middleware/log"
"github.com/go-atomci/atomci/models"
"github.com/go-atomci/atomci/internal/dao"
"github.com/go-atomci/atomci/internal/middleware"
"github.com/go-atomci/atomci/internal/middleware/log"
"github.com/go-atomci/atomci/internal/models"
"github.com/go-atomci/atomci/utils"
"github.com/go-atomci/atomci/utils/errors"
"github.com/go-atomci/atomci/utils/query"
Expand Down Expand Up @@ -225,7 +224,7 @@ func (b *BaseController) getAuthHeader() string {
if token == "" {
urlPath := b.Controller.Ctx.Request.URL.Path
if strings.Contains(urlPath, "/containernames/") {
token, err := common.GetUserToken("admin")
token, err := GetUserToken("admin")
if err == nil {
return token
} else {
Expand All @@ -237,6 +236,17 @@ func (b *BaseController) getAuthHeader() string {
return token
}

// GetUserToken ..
func GetUserToken(user string) (string, error) {
urModel := dao.NewUserRolesModel()
userInfo, err := urModel.GetUserByName(user)
if err != nil {
log.Log.Error("when get %v token by name occur error: %s", user, err.Error())
return "", err
}
return userInfo.Token, nil
}

func (b *BaseController) getUserName() string {
token := b.getAuthHeader()

Expand Down
2 changes: 1 addition & 1 deletion controllers/error.go → internal/api/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package controllers
package api

import (
"github.com/go-atomci/atomci/utils/errors"
Expand Down
10 changes: 5 additions & 5 deletions controllers/group.go → internal/api/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package controllers
package api

import (
"fmt"

"github.com/go-atomci/atomci/dao"
mycasbin "github.com/go-atomci/atomci/middleware/casbin"
"github.com/go-atomci/atomci/middleware/log"
"github.com/go-atomci/atomci/models"
"github.com/go-atomci/atomci/internal/dao"
mycasbin "github.com/go-atomci/atomci/internal/middleware/casbin"
"github.com/go-atomci/atomci/internal/middleware/log"
"github.com/go-atomci/atomci/internal/models"
)

type GroupController struct {
Expand Down

0 comments on commit 1a5e632

Please sign in to comment.