Skip to content

Commit 9f05ab1

Browse files
authored
Merge pull request #913 from Vafilor/feat/add.deep.learning.desktop
feat: added deep learning desktop workspace
2 parents 1b2d562 + 81de77d commit 9f05ab1

File tree

4 files changed

+171
-0
lines changed

4 files changed

+171
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package migration
2+
3+
import (
4+
"database/sql"
5+
"github.com/pressly/goose"
6+
"path/filepath"
7+
)
8+
9+
var deepLearningDesktopTemplateName = "Deep Learning Desktop"
10+
11+
func initialize20210414165510() {
12+
if _, ok := initializedMigrations[20210414165510]; !ok {
13+
goose.AddMigration(Up20210414165510, Down20210414165510)
14+
initializedMigrations[20210414165510] = true
15+
}
16+
}
17+
18+
// Up20210414165510 creates the Deep Learning Desktop Workspace Template
19+
func Up20210414165510(tx *sql.Tx) error {
20+
// This code is executed when the migration is applied.
21+
return createWorkspaceTemplate(
22+
filepath.Join("workspaces", "vnc", "20210414165510.yaml"),
23+
deepLearningDesktopTemplateName,
24+
"Deep learning desktop with VNC")
25+
}
26+
27+
// Down20210414165510 removes the Deep Learning Desktop Workspace Template
28+
func Down20210414165510(tx *sql.Tx) error {
29+
// This code is executed when the migration is rolled back.
30+
return archiveWorkspaceTemplate(deepLearningDesktopTemplateName)
31+
}

db/go/db.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ func Initialize() {
9494
initialize20210323175655()
9595
initialize20210329171739()
9696
initialize20210329194731()
97+
initialize20210414165510()
9798

9899
if err := client.DB.Close(); err != nil {
99100
log.Printf("[error] closing db %v", err)

db/go/util.go

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,92 @@
11
package migration
22

33
import (
4+
"fmt"
45
v1 "github.com/onepanelio/core/pkg"
56
uid2 "github.com/onepanelio/core/pkg/util/uid"
67
)
78

9+
// createWorkspaceTemplate will create the workspace template given by {{templateName}} with the contents
10+
// given by {{filename}}
11+
// It will do so for all namespaces.
12+
func createWorkspaceTemplate(filename, templateName, description string) error {
13+
client, err := getClient()
14+
if err != nil {
15+
return err
16+
}
17+
defer client.DB.Close()
18+
19+
namespaces, err := client.ListOnepanelEnabledNamespaces()
20+
if err != nil {
21+
return err
22+
}
23+
24+
newManifest, err := readDataFile(filename)
25+
if err != nil {
26+
return err
27+
}
28+
29+
uid, err := uid2.GenerateUID(templateName, 30)
30+
if err != nil {
31+
return err
32+
}
33+
34+
for _, namespace := range namespaces {
35+
workspaceTemplate := &v1.WorkspaceTemplate{
36+
UID: uid,
37+
Name: templateName,
38+
Manifest: newManifest,
39+
Description: description,
40+
}
41+
42+
err = ReplaceArtifactRepositoryType(client, namespace, nil, workspaceTemplate)
43+
if err != nil {
44+
return err
45+
}
46+
47+
if _, err := client.CreateWorkspaceTemplate(namespace.Name, workspaceTemplate); err != nil {
48+
return err
49+
}
50+
}
51+
52+
return nil
53+
}
54+
55+
func archiveWorkspaceTemplate(templateName string) error {
56+
client, err := getClient()
57+
if err != nil {
58+
return err
59+
}
60+
defer client.DB.Close()
61+
62+
namespaces, err := client.ListOnepanelEnabledNamespaces()
63+
if err != nil {
64+
return err
65+
}
66+
67+
uid, err := uid2.GenerateUID(templateName, 30)
68+
if err != nil {
69+
return err
70+
}
71+
72+
for _, namespace := range namespaces {
73+
hasRunning, err := client.WorkspaceTemplateHasRunningWorkspaces(namespace.Name, uid)
74+
if err != nil {
75+
return fmt.Errorf("Unable to get check running workspaces")
76+
}
77+
if hasRunning {
78+
return fmt.Errorf("unable to archive workspace template. There are running workspaces that use it")
79+
}
80+
81+
_, err = client.ArchiveWorkspaceTemplate(namespace.Name, uid)
82+
if err != nil {
83+
return err
84+
}
85+
}
86+
87+
return nil
88+
}
89+
890
// updateWorkspaceTemplateManifest will update the workspace template given by {{templateName}} with the contents
991
// given by {{filename}}
1092
// It will do so for all namespaces.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
arguments:
2+
parameters:
3+
# parameter screen-resolution allows users to select screen resolution
4+
- name: screen-resolution
5+
value: 1680x1050
6+
type: select.select
7+
displayName: Screen Resolution
8+
options:
9+
- name: 1280x1024
10+
value: 1280x1024
11+
- name: 1680x1050
12+
value: 1680x1050
13+
- name: 2880x1800
14+
value: 2880x1800
15+
containers:
16+
- name: ubuntu
17+
image: onepanel/vnc:dl-vnc
18+
env:
19+
- name: VNC_PASSWORDLESS
20+
value: true
21+
- name: VNC_RESOLUTION
22+
value: '{{workflow.parameters.screen-resolution}}'
23+
ports:
24+
- containerPort: 6901
25+
name: vnc
26+
volumeMounts:
27+
- name: data
28+
mountPath: /data
29+
ports:
30+
- name: vnc
31+
port: 80
32+
protocol: TCP
33+
targetPort: 6901
34+
routes:
35+
- match:
36+
- uri:
37+
prefix: /
38+
route:
39+
- destination:
40+
port:
41+
number: 80
42+
# DAG Workflow to be executed once a Workspace action completes (optional)
43+
#postExecutionWorkflow:
44+
# entrypoint: main
45+
# templates:
46+
# - name: main
47+
# dag:
48+
# tasks:
49+
# - name: slack-notify
50+
# template: slack-notify
51+
# - name: slack-notify
52+
# container:
53+
# image: technosophos/slack-notify
54+
# args:
55+
# - 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
56+
# command:
57+
# - sh

0 commit comments

Comments
 (0)