Skip to content

Commit

Permalink
Merge pull request #913 from Vafilor/feat/add.deep.learning.desktop
Browse files Browse the repository at this point in the history
feat: added deep learning desktop workspace
  • Loading branch information
Vafilor authored Apr 14, 2021
2 parents 1b2d562 + 81de77d commit 9f05ab1
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 0 deletions.
31 changes: 31 additions & 0 deletions db/go/20210414165510_add_deep_learning_desktop_workspace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package migration

import (
"database/sql"
"github.com/pressly/goose"
"path/filepath"
)

var deepLearningDesktopTemplateName = "Deep Learning Desktop"

func initialize20210414165510() {
if _, ok := initializedMigrations[20210414165510]; !ok {
goose.AddMigration(Up20210414165510, Down20210414165510)
initializedMigrations[20210414165510] = true
}
}

// Up20210414165510 creates the Deep Learning Desktop Workspace Template
func Up20210414165510(tx *sql.Tx) error {
// This code is executed when the migration is applied.
return createWorkspaceTemplate(
filepath.Join("workspaces", "vnc", "20210414165510.yaml"),
deepLearningDesktopTemplateName,
"Deep learning desktop with VNC")
}

// Down20210414165510 removes the Deep Learning Desktop Workspace Template
func Down20210414165510(tx *sql.Tx) error {
// This code is executed when the migration is rolled back.
return archiveWorkspaceTemplate(deepLearningDesktopTemplateName)
}
1 change: 1 addition & 0 deletions db/go/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func Initialize() {
initialize20210323175655()
initialize20210329171739()
initialize20210329194731()
initialize20210414165510()

if err := client.DB.Close(); err != nil {
log.Printf("[error] closing db %v", err)
Expand Down
82 changes: 82 additions & 0 deletions db/go/util.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,92 @@
package migration

import (
"fmt"
v1 "github.com/onepanelio/core/pkg"
uid2 "github.com/onepanelio/core/pkg/util/uid"
)

// createWorkspaceTemplate will create the workspace template given by {{templateName}} with the contents
// given by {{filename}}
// It will do so for all namespaces.
func createWorkspaceTemplate(filename, templateName, description string) error {
client, err := getClient()
if err != nil {
return err
}
defer client.DB.Close()

namespaces, err := client.ListOnepanelEnabledNamespaces()
if err != nil {
return err
}

newManifest, err := readDataFile(filename)
if err != nil {
return err
}

uid, err := uid2.GenerateUID(templateName, 30)
if err != nil {
return err
}

for _, namespace := range namespaces {
workspaceTemplate := &v1.WorkspaceTemplate{
UID: uid,
Name: templateName,
Manifest: newManifest,
Description: description,
}

err = ReplaceArtifactRepositoryType(client, namespace, nil, workspaceTemplate)
if err != nil {
return err
}

if _, err := client.CreateWorkspaceTemplate(namespace.Name, workspaceTemplate); err != nil {
return err
}
}

return nil
}

func archiveWorkspaceTemplate(templateName string) error {
client, err := getClient()
if err != nil {
return err
}
defer client.DB.Close()

namespaces, err := client.ListOnepanelEnabledNamespaces()
if err != nil {
return err
}

uid, err := uid2.GenerateUID(templateName, 30)
if err != nil {
return err
}

for _, namespace := range namespaces {
hasRunning, err := client.WorkspaceTemplateHasRunningWorkspaces(namespace.Name, uid)
if err != nil {
return fmt.Errorf("Unable to get check running workspaces")
}
if hasRunning {
return fmt.Errorf("unable to archive workspace template. There are running workspaces that use it")
}

_, err = client.ArchiveWorkspaceTemplate(namespace.Name, uid)
if err != nil {
return err
}
}

return nil
}

// updateWorkspaceTemplateManifest will update the workspace template given by {{templateName}} with the contents
// given by {{filename}}
// It will do so for all namespaces.
Expand Down
57 changes: 57 additions & 0 deletions db/yaml/workspaces/vnc/20210414165510.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
arguments:
parameters:
# parameter screen-resolution allows users to select screen resolution
- name: screen-resolution
value: 1680x1050
type: select.select
displayName: Screen Resolution
options:
- name: 1280x1024
value: 1280x1024
- name: 1680x1050
value: 1680x1050
- name: 2880x1800
value: 2880x1800
containers:
- name: ubuntu
image: onepanel/vnc:dl-vnc
env:
- name: VNC_PASSWORDLESS
value: true
- name: VNC_RESOLUTION
value: '{{workflow.parameters.screen-resolution}}'
ports:
- containerPort: 6901
name: vnc
volumeMounts:
- name: data
mountPath: /data
ports:
- name: vnc
port: 80
protocol: TCP
targetPort: 6901
routes:
- match:
- uri:
prefix: /
route:
- destination:
port:
number: 80
# DAG Workflow to be executed once a Workspace action completes (optional)
#postExecutionWorkflow:
# entrypoint: main
# templates:
# - name: main
# dag:
# tasks:
# - name: slack-notify
# template: slack-notify
# - name: slack-notify
# container:
# image: technosophos/slack-notify
# args:
# - SLACK_USERNAME=onepanel SLACK_TITLE="Your workspace is ready" SLACK_ICON=https://www.gravatar.com/avatar/5c4478592fe00878f62f0027be59c1bd SLACK_MESSAGE="Your workspace is now running" ./slack-notify
# command:
# - sh

0 comments on commit 9f05ab1

Please sign in to comment.