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

Fixing unit testing and path issue #11

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM alpine

COPY ukiyo .
COPY dbs .
RUN chmod 777 ./ukiyo

EXPOSE 8080

CMD ["./ukiyo"]
99 changes: 99 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

- Container manager
- Push manager (webhooks configuration)
- Scheduler
- OPTIONAL - Pull based update implementation

## Execution modes
Expand All @@ -28,3 +29,101 @@ Two modes of execution
### Go style guide

- https://github.com/rajikaimal/go-styleguide

## Dev Setup Guide

Setup docker
```sh
$ go mod init ukiyo
$ go mod tidy
```

Create docker binary file
```sh
$ set GOARCH=amd64
$ set GOOS=linux
$ go build -ldflags="-s -w" -o ukiyo main.go
```

Docker build command
```sh
$ docker build -f Dockerfile -t agentukiyo/ukiyo:tag .
$ docker push agentukiyo/ukiyo:tag
```

Run ukiyo agent
```sh
$ docker run -p 8080:8080 \
-- name ukiyo \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /home/reinventor/dbs:/dbs \
agentukiyo/ukiyo:01
```

Add webhook to your dockerhub repository
```
http:{serverIP}:8080/ukiyo-web-hook
```

Add your own docker registy details
```
http:{serverIP}:8080/save-container-access-keys
{
"username":"docker registry name"
"desc":"docker registry description"
"accessToken":"docker registry accesstoken"
"email":"your email"
"serverAddress":"http://docker.io/v1"
}

http:{serverIP}:8080/edit-container-access-keys
{
"username":"docker registry name"
"desc":"edited description"
"accessToken":"new docker registry accesstoken"
"email":"new email"
"serverAddress":"http://docker.io/v1"
}

http://{serverIP}:8080/delete-container-access-keys/{registryname}
```

Add your deployment details
```
http://{serverIP}:8080/save-repository-scheduled-time
{
"name": "repository name",
"bindingPort":
[{
"exportPort": "8180",
"internalPort": "80"
},
{
"exportPort": "443",
"internalPort": "443"
}],
"scheduledAt": "1555438658",
"scheduledDowntime": false
}

http://{serverIP}:8080/edit-repository-scheduled-time
{
"name": "repository name",
"bindingPort":
[{
"exportPort": "8180",
"internalPort": "80"
}],
"scheduledAt": "1555438658",
"scheduledDowntime": false
}

http://{serverIP}:8080/remove-repository-scheduled-time/{repositoryname}
```

List your deployment details
```
http://{serverIP}:8080/get-container-history/1

http://{serverIP}:8080/get-container-history-by-name/{repositoryname}
```
26 changes: 26 additions & 0 deletions api/historyapilayer/historyapilayer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package historyapilayer

import (
"github.com/gin-gonic/gin"
"log"
"net/http"
"ukiyo/internal/containerhistory"
)

func GetAllContainerHistory(r *gin.Engine) {
r.GET("/get-container-history/:pageNo", func(c *gin.Context) {
pageNo := c.Param("pageNo")
response := containerhistory.QueryAllHistoryRecodeInDB(pageNo)
log.Println("Container History details by pageNo=" + pageNo)
c.JSON(http.StatusOK, response)
})
}

func GetAllContainerHistoryByName(r *gin.Engine) {
r.GET("/get-container-history-by-name/:name", func(c *gin.Context) {
var response containerhistory.HistoryResponse
name := c.Param("name")
log.Println("Container History details by name=" + name)
c.JSON(http.StatusOK, response)
})
}
61 changes: 61 additions & 0 deletions api/registryapilayer/registryapilayer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package registryapilayer

import (
"github.com/gin-gonic/gin"
"log"
"net/http"
"ukiyo/internal/containeraccess"
"ukiyo/pkg/jencoder"
)

func SaveContainerAccessKeys(r *gin.Engine) {
r.POST("/save-container-access-keys", func(c *gin.Context) {
var containerKey containeraccess.ContainerKeys
var responseObj containeraccess.ResponseObj
c.ShouldBindJSON(&containerKey)
log.Println("Container keys save details" + jencoder.PrintJson(containerKey))

if len(containerKey.UserName) > 0 && len(containerKey.AccessToken) > 0 && len(containerKey.ServerAddress) > 0 {
res := containeraccess.InsertDockerRegData(containerKey)
responseObj = res
} else {
responseObj.ResponseCode = 1
responseObj.ResponseDesc = "Invalid Parameter"
}
c.JSON(http.StatusOK, responseObj)
})
}

func EditContainerAccessKeys(r *gin.Engine) {
r.POST("/edit-container-access-keys", func(c *gin.Context) {
var containerKey containeraccess.ContainerKeys
var responseObj containeraccess.ResponseObj
c.ShouldBindJSON(&containerKey)
log.Println("Container keys Update details" + jencoder.PrintJson(containerKey))

if len(containerKey.UserName) > 0 && len(containerKey.AccessToken) > 0 {
res := containeraccess.UpdateDockerRegData(containerKey)
responseObj = res
} else {
responseObj.ResponseCode = 1
responseObj.ResponseDesc = "Invalid Parameter"
}
c.JSON(http.StatusOK, responseObj)
})
}

func DeleteContainerAccessKeys(r *gin.Engine) {
r.DELETE("/delete-container-access-keys/:userName", func(c *gin.Context) {
var responseObj containeraccess.ResponseObj
name := c.Param("userName")
log.Println("Container keys Delete details userName=" + name)
if len(name) > 0 {
res := containeraccess.DeleteDockerRegData(name)
responseObj = res
} else {
responseObj.ResponseCode = 1
responseObj.ResponseDesc = "Invalid Parameter"
}
c.JSON(http.StatusOK, responseObj)
})
}
62 changes: 62 additions & 0 deletions api/schedulerapilayer/schedulerapilayer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package schedulerapilayer

import (
"github.com/gin-gonic/gin"
"log"
"net/http"
"ukiyo/internal/containerscheduler"
"ukiyo/internal/util"
"ukiyo/pkg/jencoder"
)

func SaveRepositoryScheduledTime(r *gin.Engine) {
r.POST("/save-repository-scheduled-time", func(c *gin.Context) {
var podsDetails containerscheduler.PodsDetails
var responseObj containerscheduler.ResponseObj
c.ShouldBindJSON(&podsDetails)
log.Println("Pods save details" + jencoder.PrintJson(podsDetails))

if len(podsDetails.Name) > 0 && util.BindPortValidator(podsDetails.BindingPort) {
res := containerscheduler.InsertPodsData(podsDetails)
responseObj = res
} else {
responseObj.ResponseCode = 1
responseObj.ResponseDesc = "Invalid Parameter"
}
c.JSON(http.StatusOK, responseObj)
})
}

func EditRepositoryScheduledTime(r *gin.Engine) {
r.POST("/edit-repository-scheduled-time", func(c *gin.Context) {
var podsDetails containerscheduler.PodsDetails
var responseObj containerscheduler.ResponseObj
c.ShouldBindJSON(&podsDetails)
log.Println("Pods Update details" + jencoder.PrintJson(podsDetails))

if len(podsDetails.Name) > 0 && util.BindPortValidator(podsDetails.BindingPort) {
res := containerscheduler.UpdatePodsData(podsDetails)
responseObj = res
} else {
responseObj.ResponseCode = 1
responseObj.ResponseDesc = "Invalid Parameter"
}
c.JSON(http.StatusOK, responseObj)
})
}

func DeleteRepositoryScheduledTime(r *gin.Engine) {
r.DELETE("/remove-repository-scheduled-time/:name", func(c *gin.Context) {
var responseObj containerscheduler.ResponseObj
name := c.Param("name")
log.Println("Pod Delete details name=" + name)
if len(name) > 0 {
res := containerscheduler.DeleteDockerRegData(name)
responseObj = res
} else {
responseObj.ResponseCode = 1
responseObj.ResponseDesc = "Invalid Parameter"
}
c.JSON(http.StatusOK, responseObj)
})
}
Binary file added cmd/ukiyo/main
Binary file not shown.
File renamed without changes.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module ukiyo
go 1.14

require (
github.com/fsouza/go-dockerclient v1.6.5
github.com/gin-gonic/gin v1.6.3
github.com/stretchr/testify v1.4.0
github.com/sonyarouje/simdb v0.0.0-20181202125413-c2488dfc374a
)
Loading