DodoApp: Implement commit status page
Render used volume, postgresql and ingress resource details.
Change-Id: I87f34fd19d0d0d31ec495d2798c9f5ce99c0fd43
diff --git a/core/installer/welcome/store.go b/core/installer/welcome/store.go
index 031cdff..06be06a 100644
--- a/core/installer/welcome/store.go
+++ b/core/installer/welcome/store.go
@@ -1,11 +1,14 @@
package welcome
import (
+ "bytes"
"database/sql"
+ "encoding/json"
"errors"
"github.com/ncruces/go-sqlite3"
+ "github.com/giolekva/pcloud/core/installer"
"github.com/giolekva/pcloud/core/installer/soft"
)
@@ -17,12 +20,18 @@
ErrorAlreadyExists = errors.New("already exists")
)
-type Commit struct {
- Hash string
+type CommitMeta struct {
Status string
+ Error string
+ Hash string
Message string
}
+type Commit struct {
+ CommitMeta
+ Resources installer.ReleaseResources
+}
+
type Store interface {
CreateUser(username string, password []byte, network string) error
GetUserPassword(username string) ([]byte, error)
@@ -31,8 +40,9 @@
GetUserApps(username string) ([]string, error)
CreateApp(name, username string) error
GetAppOwner(name string) (string, error)
- CreateCommit(name, hash, message, status string) error
- GetCommitHistory(name string) ([]Commit, error)
+ CreateCommit(name, hash, message, status, error string, resources []byte) error
+ GetCommitHistory(name string) ([]CommitMeta, error)
+ GetCommit(hash string) (Commit, error)
}
func NewStore(cf soft.RepoIO, db *sql.DB) (Store, error) {
@@ -63,7 +73,9 @@
app_name TEXT,
hash TEXT,
message TEXT,
- status TEXT
+ status TEXT,
+ error TEXT,
+ resources JSONB
);
`)
return err
@@ -174,26 +186,26 @@
return ret, nil
}
-func (s *storeImpl) CreateCommit(name, hash, message, status string) error {
- query := `INSERT INTO commits (app_name, hash, message, status) VALUES (?, ?, ?, ?)`
- _, err := s.db.Exec(query, name, hash, message, status)
+func (s *storeImpl) CreateCommit(name, hash, message, status, error string, resources []byte) error {
+ query := `INSERT INTO commits (app_name, hash, message, status, error, resources) VALUES (?, ?, ?, ?, ?, ?)`
+ _, err := s.db.Exec(query, name, hash, message, status, error, resources)
return err
}
-func (s *storeImpl) GetCommitHistory(name string) ([]Commit, error) {
- query := `SELECT hash, message, status FROM commits WHERE app_name = ?`
+func (s *storeImpl) GetCommitHistory(name string) ([]CommitMeta, error) {
+ query := `SELECT hash, message, status, error FROM commits WHERE app_name = ?`
rows, err := s.db.Query(query, name)
if err != nil {
return nil, err
}
defer rows.Close()
- ret := []Commit{}
+ ret := []CommitMeta{}
for rows.Next() {
if err := rows.Err(); err != nil {
return nil, err
}
- var c Commit
- if err := rows.Scan(&c.Hash, &c.Message, &c.Status); err != nil {
+ var c CommitMeta
+ if err := rows.Scan(&c.Hash, &c.Message, &c.Status, &c.Error); err != nil {
return nil, err
}
ret = append(ret, c)
@@ -201,3 +213,21 @@
}
return ret, nil
}
+
+func (s *storeImpl) GetCommit(hash string) (Commit, error) {
+ query := `SELECT hash, message, status, error, resources FROM commits WHERE hash = ?`
+ row := s.db.QueryRow(query, hash)
+ if err := row.Err(); err != nil {
+ return Commit{}, err
+ }
+ var ret Commit
+ var c Commit
+ var res []byte
+ if err := row.Scan(&c.Hash, &c.Message, &c.Status, &c.Error, &res); err != nil {
+ return Commit{}, err
+ }
+ if err := json.NewDecoder(bytes.NewBuffer(res)).Decode(&ret.Resources); err != nil {
+ return Commit{}, err
+ }
+ return ret, nil
+}