Browse Source

Integrating Primereact into the frontend prototype

Fixed: Container destroy did not remove zone files
Changed: golang-114 is current
Added some debug messages
Added simple pod list command
layerset
Till Wegmueller 3 years ago
parent
commit
a8390aae07
  1. 4
      cmd/buildhelper.go
  2. 27
      cmd/podadm/list.go
  3. 4
      frontend/package.json
  4. 90
      frontend/src/components/Sidebar.tsx
  5. 4
      frontend/src/index.tsx
  6. 37
      frontend/yarn.lock
  7. 1
      host/build.go
  8. 20
      image/oci/tar_writer.go
  9. 21
      pod/container.go
  10. 2
      supportfiles/volume.hcl

4
cmd/buildhelper.go

@ -30,11 +30,11 @@ func main() {
if err := json.NewDecoder(os.Stdin).Decode(&imageConfig); err != nil {
panic(err)
}
logrus.Info("installing sources in zone")
if err := build.InstallSourcesInsideZone(imageConfig); err != nil {
panic(err)
}
logrus.Info("performing actions")
if err := build.PerformActions(imageConfig); err != nil {
panic(err)
}

27
cmd/podadm/list.go

@ -0,0 +1,27 @@
package podadm
import (
"os"
"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
)
var listCmd = &cobra.Command{
Use: "list",
Short: "List all containers",
Long: `List all containers on this host`,
Run: func(cmd *cobra.Command, args []string) {
containers := h.Containers()
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"UUID", "Name", "Status"})
for _, container := range containers {
table.Append([]string{container.UUID.String(), container.Name, container.Status().String()})
}
table.Render()
},
}
func init() {
RootCmd.AddCommand(listCmd)
}

4
frontend/package.json

@ -11,9 +11,13 @@
"@types/react": "^16.9.0",
"@types/react-dom": "^16.9.0",
"@types/styled-components": "^5.0.1",
"classnames": "^2.2.6",
"primeicons": "^2.0.0",
"primereact": "^4.1.0",
"react": "^16.13.0",
"react-dom": "^16.13.0",
"react-scripts": "3.4.0",
"react-transition-group": "^4.3.0",
"styled-components": "^5.0.1",
"typescript": "~3.7.2"
},

90
frontend/src/components/Sidebar.tsx

@ -1,32 +1,98 @@
import React from 'react';
import styled from "styled-components";
import {Tree} from 'primereact/tree';
import TreeNode from "primereact/components/treenode/TreeNode";
type ItemProps = {
name: string;
}
const SidebarItemElem = styled.div`
const SidebarItem = styled.div`
`;
function SidebarItem(props: ItemProps){
return <SidebarItemElem>
{props.name}
</SidebarItemElem>
}
const SidebarGrid = styled.div`
display: grid;
grid-area: sidebar;
padding-left: 10px;
`;
const data: TreeNode[] = [
{
"key": "0",
"label": "Documents",
"data": "Documents Folder",
"icon": "pi pi-fw pi-inbox",
"children": [
{
"key": "0-0",
"label": "Work",
"data": "Work Folder",
"icon": "pi pi-fw pi-cog",
"children": [
{ "key": "0-0-0", "label": "Expenses.doc", "icon": "pi pi-fw pi-file", "data": "Expenses Document", children: [] },
{ "key": "0-0-1", "label": "Resume.doc", "icon": "pi pi-fw pi-file", "data": "Resume Document", children: [] }
]
},
{
"key": "0-1",
"label": "Home",
"data": "Home Folder",
"icon": "pi pi-fw pi-home",
"children": [
{ "key": "0-1-0", "label": "Invoices.txt", "icon": "pi pi-fw pi-file", "data": "Invoices for this month", children: [] }
]
}
]
},
{
"key": "1",
"label": "Events",
"data": "Events Folder",
"icon": "pi pi-fw pi-calendar",
"children": [
{ "key": "1-0", "label": "Meeting", "icon": "pi pi-fw pi-calendar-plus", "data": "Meeting", children: [] },
{ "key": "1-1", "label": "Product Launch", "icon": "pi pi-fw pi-calendar-plus", "data": "Product Launch", children: [] },
{ "key": "1-2", "label": "Report Review", "icon": "pi pi-fw pi-calendar-plus", "data": "Report Review", children: [] }
]
},
{
"key": "2",
"label": "Movies",
"data": "Movies Folder",
"icon": "pi pi-fw pi-star",
"children": [
{
"key": "2-0",
"icon": "pi pi-fw pi-star",
"label": "Al Pacino",
"data": "Pacino Movies",
"children": [
{ "key": "2-0-0", "label": "Scarface", "icon": "pi pi-fw pi-video", "data": "Scarface Movie", children: [] },
{ "key": "2-0-1", "label": "Serpico", "icon": "pi pi-fw pi-video", "data": "Serpico Movie", children: [] }
]
},
{
"key": "2-1",
"label": "Robert De Niro",
"icon": "pi pi-fw pi-star",
"data": "De Niro Movies",
"children": [
{ "key": "2-1-0", "label": "Goodfellas", "icon": "pi pi-fw pi-video", "data": "Goodfellas Movie", children: [] },
{ "key": "2-1-1", "label": "Untouchables", "icon": "pi pi-fw pi-video", "data": "Untouchables Movie", children: [] }
]
}
]
}
];
export default class Sidebar extends React.Component<any, any> {
render(){
return (
<SidebarGrid>
<SidebarItem name="Item1" />
<SidebarItem>
<Tree value={data} expandedKeys={{
"0": true,
"2": true,
}} />
</SidebarItem>
</SidebarGrid>
)
}

4
frontend/src/index.tsx

@ -3,6 +3,10 @@ import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';
import 'primereact/resources/themes/nova-dark/theme.css';
import 'primereact/resources/primereact.min.css';
import 'primeicons/primeicons.css';
ReactDOM.render(<App />, document.getElementById('root'));

37
frontend/yarn.lock

@ -871,7 +871,7 @@
dependencies:
regenerator-runtime "^0.13.2"
"@babel/runtime@^7.5.1", "@babel/runtime@^7.7.4", "@babel/runtime@^7.8.4":
"@babel/runtime@^7.5.1", "@babel/runtime@^7.5.5", "@babel/runtime@^7.7.4", "@babel/runtime@^7.8.4":
version "7.8.7"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.8.7.tgz#8fefce9802db54881ba59f90bb28719b4996324d"
integrity sha512-+AATMUFppJDw6aiR5NVPHqIQBlV/Pj8wY/EZH+lmvRdUo9xBaz/rF3alAwFJQavvKfeOlPE7oaaDHVbcySbCsg==
@ -2791,6 +2791,11 @@ class-utils@^0.3.5:
isobject "^3.0.0"
static-extend "^0.1.1"
classnames@^2.2.6:
version "2.2.6"
resolved "https://registry.yarnpkg.com/classnames/-/classnames-2.2.6.tgz#43935bffdd291f326dad0a205309b38d00f650ce"
integrity sha512-JR/iSQOSt+LQIWwrwEzJ9uk0xfN3mTVYMwt1Ir5mUcSN6pU+V4zQFFaJsclJbPuAUQH+yfWef6tm7l1quW3C8Q==
clean-css@^4.2.1:
version "4.2.3"
resolved "https://registry.yarnpkg.com/clean-css/-/clean-css-4.2.3.tgz#507b5de7d97b48ee53d84adb0160ff6216380f78"
@ -3419,7 +3424,7 @@ cssstyle@^1.0.0, cssstyle@^1.1.1:
dependencies:
cssom "0.3.x"
csstype@^2.2.0:
csstype@^2.2.0, csstype@^2.6.7:
version "2.6.9"
resolved "https://registry.yarnpkg.com/csstype/-/csstype-2.6.9.tgz#05141d0cd557a56b8891394c1911c40c8a98d098"
integrity sha512-xz39Sb4+OaTsULgUERcCk+TJj8ylkL4aSVDQiX/ksxbELSqwkgt4d4RD7fovIdgJGSuNYqwZEiVjYY5l0ask+Q==
@ -3673,6 +3678,14 @@ dom-converter@^0.2:
dependencies:
utila "~0.4"
dom-helpers@^5.0.1:
version "5.1.3"
resolved "https://registry.yarnpkg.com/dom-helpers/-/dom-helpers-5.1.3.tgz#7233248eb3a2d1f74aafca31e52c5299cc8ce821"
integrity sha512-nZD1OtwfWGRBWlpANxacBEZrEuLa16o1nh7YopFWeoF68Zt8GGEmzHu6Xv4F3XaFIC+YXtTLrzgqKxFgLEe4jw==
dependencies:
"@babel/runtime" "^7.6.3"
csstype "^2.6.7"
dom-serializer@0:
version "0.2.2"
resolved "https://registry.yarnpkg.com/dom-serializer/-/dom-serializer-0.2.2.tgz#1afb81f533717175d478655debc5e332d9f9bb51"
@ -8227,6 +8240,16 @@ pretty-format@^25.1.0:
ansi-styles "^4.0.0"
react-is "^16.12.0"
primeicons@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/primeicons/-/primeicons-2.0.0.tgz#ec3e5a8d4d04a09309225a5a57deb911e08dc0d3"
integrity sha512-GJTCeMSQU8UU1GqbsaDrg/IH+b/vSinJQl52NVpdJ7sShYLZA8Eq6jLF48Ye3N/dQloGrE07i7XsZvxQ9pNbqg==
primereact@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/primereact/-/primereact-4.1.0.tgz#2bcd5e4684f7940dc5d9c25739cadd17b4a1fc0e"
integrity sha512-ZfC7VB6HCqA4P43TpdglED0FgrjwD4eGyL29uXoP2l2oUfYmPaMb/IenpBqC+Rinv8JiEPBsdHaq1bfyN/Ca2Q==
private@^0.1.6:
version "0.1.8"
resolved "https://registry.yarnpkg.com/private/-/private-0.1.8.tgz#2381edb3689f7a53d653190060fcf822d2f368ff"
@ -8548,6 +8571,16 @@ react-scripts@3.4.0:
optionalDependencies:
fsevents "2.1.2"
react-transition-group@^4.3.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/react-transition-group/-/react-transition-group-4.3.0.tgz#fea832e386cf8796c58b61874a3319704f5ce683"
integrity sha512-1qRV1ZuVSdxPlPf4O8t7inxUGpdyO5zG9IoNfJxSO0ImU2A1YWkEQvFPuIPZmMLkg5hYs7vv5mMOyfgSkvAwvw==
dependencies:
"@babel/runtime" "^7.5.5"
dom-helpers "^5.0.1"
loose-envify "^1.4.0"
prop-types "^15.6.2"
react@^16.13.0:
version "16.13.0"
resolved "https://registry.yarnpkg.com/react/-/react-16.13.0.tgz#d046eabcdf64e457bbeed1e792e235e1b9934cf7"

1
host/build.go

@ -221,6 +221,7 @@ func (h *Host) ExportToImage(imageName reference.Reference, container *pod.Conta
var i *image.Image
//First load existing image with existing tags
if h.HasImage(imageName) {
logrus.Debugf("loading existing base image %s", imageName.String())
origImg, err := h.GetLocalImage(imageName)
if err != nil {
return nil, tracerr.Wrap(err)

20
image/oci/tar_writer.go

@ -12,11 +12,15 @@ import (
"time"
"github.com/dustin/go-humanize"
"github.com/sirupsen/logrus"
"github.com/ztrue/tracerr"
)
var whiteoutByte = []byte("WHITEOUT")
var whiteoutLen = int64(len(whiteoutByte))
var blacklist = []string{
"dev/zconsole",
}
type Devino struct {
Dev uint64
@ -76,10 +80,18 @@ func (tarWriter *TarWriter) AddEntry(realPath string, inImagePath string, info o
inImagePath = inImagePath[1:]
}
for _, blackListEntry := range blacklist {
// TODO fix this dirty hack.....
// Why do I need to jump zconsole now....
if inImagePath == blackListEntry {
return nil
}
}
var hdr *tar.Header
switch info.Mode() & os.ModeType {
case os.ModeSocket, os.ModeNamedPipe, os.ModeSticky, os.ModeExclusive:
return
return nil
case os.ModeDir:
hdr, err = tar.FileInfoHeader(info, "")
if err != nil {
@ -131,6 +143,7 @@ func (tarWriter *TarWriter) AddEntry(realPath string, inImagePath string, info o
fileObj, err := os.Open(realPath)
if err != nil {
fmt.Println(info.Mode() & os.ModeType)
return tracerr.Wrap(err)
}
defer fileObj.Close()
@ -178,9 +191,8 @@ func (tarWriter *TarWriter) AddEntry(realPath string, inImagePath string, info o
if hdr.Typeflag == tar.TypeReg {
if _, err := io.Copy(tarWriter.archiveWriter, fileObj); err != nil {
//TODO Logger with this info
fmt.Printf("file: %s (%s); length: %s\n", realPath, inImagePath, humanize.Bytes(uint64(info.Size())))
fmt.Printf("header: length: %s\n", humanize.Bytes(uint64(hdr.Size)))
logrus.Errorf("file: %s (%s); length: %s\n", realPath, inImagePath, humanize.Bytes(uint64(info.Size())))
logrus.Errorf("header: length: %s\n", humanize.Bytes(uint64(hdr.Size)))
return tracerr.Wrap(err)
}
}

21
pod/container.go

@ -467,16 +467,31 @@ func (c *Container) Destroy() error {
}
if err := c.lifecycleManager.Uninstall(true, nil); err != nil {
return err
return fmt.Errorf("can not uninstall zone %s: %w", c.UUID, err)
}
if err := c.dataset.Destroy(true); err != nil {
return err
return fmt.Errorf("cannot destroy pod dataset for %s: %w", c.UUID, err)
}
var lockFd *os.File
var err error
if lockFd, err = config.GrabZoneLockFile(*c.Zone); err != nil {
return tracerr.Wrap(err)
}
defer config.ReleaseZoneLockFile(lockFd)
if err := config.Unregister(c.Zone); err != nil {
return fmt.Errorf("cannot unregister zone of %s: %w", c.UUID, err)
}
if err := c.Zone.RemoveFile(); err != nil {
return fmt.Errorf("can not remove zone xml of %s: %w", c.UUID, err)
}
if err := os.Remove(c.Path()); err != nil {
if !os.IsNotExist(err) {
return tracerr.Wrap(err)
return fmt.Errorf("error during path cleanup of %s: %w", c.UUID, err)
}
}

2
supportfiles/volume.hcl

@ -30,6 +30,6 @@ image "openindiana/golang" {
PATH = "/usr/sbin:/sbin:/usr/bin"
}
action "Install Go Runtime" {
cmd = "pkg install -v golang-111"
cmd = "pkg install -v golang-114"
}
}

Loading…
Cancel
Save