Skip to content

Commit 38780c2

Browse files
authored
Merge pull request #675 from Vafilor/feat/cvat.upgrade
feat: upgrade cvat to v14
2 parents 6e1a08f + e1f8ee8 commit 38780c2

File tree

5 files changed

+240
-1
lines changed

5 files changed

+240
-1
lines changed

db/data/cvat_20201016170415.yaml

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
# Workspace arguments
2+
arguments:
3+
parameters:
4+
- name: sync-directory
5+
displayName: Directory to sync raw input and training output
6+
value: workflow-data
7+
hint: Location to sync raw input, models and checkpoints from default object storage. Note that this will be relative to the current namespace.
8+
containers:
9+
- name: cvat-db
10+
image: postgres:10-alpine
11+
env:
12+
- name: POSTGRES_USER
13+
value: root
14+
- name: POSTGRES_DB
15+
value: cvat
16+
- name: POSTGRES_HOST_AUTH_METHOD
17+
value: trust
18+
- name: PGDATA
19+
value: /var/lib/psql/data
20+
ports:
21+
- containerPort: 5432
22+
name: tcp
23+
volumeMounts:
24+
- name: db
25+
mountPath: /var/lib/psql
26+
- name: cvat-redis
27+
image: redis:4.0-alpine
28+
ports:
29+
- containerPort: 6379
30+
name: tcp
31+
- name: cvat
32+
image: onepanel/cvat:0.14.0_cvat.1.0.0
33+
env:
34+
- name: DJANGO_MODWSGI_EXTRA_ARGS
35+
value: ""
36+
- name: ALLOWED_HOSTS
37+
value: '*'
38+
- name: CVAT_REDIS_HOST
39+
value: localhost
40+
- name: CVAT_POSTGRES_HOST
41+
value: localhost
42+
- name: CVAT_SHARE_URL
43+
value: /home/django/data
44+
- name: ONEPANEL_SYNC_DIRECTORY
45+
value: '{{workspace.parameters.sync-directory}}'
46+
- name: NVIDIA_VISIBLE_DEVICES
47+
value: all
48+
- name: NVIDIA_DRIVER_CAPABILITIES
49+
value: compute,utility
50+
- name: NVIDIA_REQUIRE_CUDA
51+
value: "cuda>=10.0 brand=tesla,driver>=384,driver<385 brand=tesla,driver>=410,driver<411"
52+
ports:
53+
- containerPort: 8080
54+
name: http
55+
volumeMounts:
56+
- name: data
57+
mountPath: /home/django/data
58+
- name: keys
59+
mountPath: /home/django/keys
60+
- name: logs
61+
mountPath: /home/django/logs
62+
- name: models
63+
mountPath: /home/django/models
64+
- name: share
65+
mountPath: /home/django/share
66+
- name: sys-namespace-config
67+
mountPath: /etc/onepanel
68+
readOnly: true
69+
- name: cvat-ui
70+
image: onepanel/cvat-ui:0.14.0_cvat.1.0.0
71+
ports:
72+
- containerPort: 80
73+
name: http
74+
# You can add multiple FileSyncer sidecar containers if needed
75+
- name: filesyncer
76+
image: onepanel/filesyncer:s3
77+
imagePullPolicy: Always
78+
args:
79+
- download
80+
- -server-prefix=/sys/filesyncer
81+
env:
82+
- name: FS_PATH
83+
value: /mnt/share
84+
- name: FS_PREFIX
85+
value: '{{workflow.namespace}}/{{workspace.parameters.sync-directory}}'
86+
volumeMounts:
87+
- name: share
88+
mountPath: /mnt/share
89+
- name: sys-namespace-config
90+
mountPath: /etc/onepanel
91+
readOnly: true
92+
ports:
93+
- name: cvat-ui
94+
port: 80
95+
protocol: TCP
96+
targetPort: 80
97+
- name: cvat
98+
port: 8080
99+
protocol: TCP
100+
targetPort: 8080
101+
- name: fs
102+
port: 8888
103+
protocol: TCP
104+
targetPort: 8888
105+
routes:
106+
- match:
107+
- uri:
108+
prefix: /sys/filesyncer
109+
route:
110+
- destination:
111+
port:
112+
number: 8888
113+
- match:
114+
- uri:
115+
regex: /api/.*|/git/.*|/tensorflow/.*|/onepanelio/.*|/tracking/.*|/auto_annotation/.*|/analytics/.*|/static/.*|/admin/.*|/documentation/.*|/dextr/.*|/reid/.*
116+
- queryParams:
117+
id:
118+
regex: \d+.*
119+
route:
120+
- destination:
121+
port:
122+
number: 8080
123+
- match:
124+
- uri:
125+
prefix: /
126+
route:
127+
- destination:
128+
port:
129+
number: 80
130+
# DAG Workflow to be executed once a Workspace action completes (optional)
131+
# Uncomment the lines below if you want to send Slack notifications
132+
#postExecutionWorkflow:
133+
# entrypoint: main
134+
# templates:
135+
# - name: main
136+
# dag:
137+
# tasks:
138+
# - name: slack-notify
139+
# template: slack-notify
140+
# - name: slack-notify
141+
# container:
142+
# image: technosophos/slack-notify
143+
# args:
144+
# - 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
145+
# command:
146+
# - sh
147+
# - -c
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package migration
2+
3+
import (
4+
"database/sql"
5+
"github.com/pressly/goose"
6+
)
7+
8+
func initialize20201016170415() {
9+
if _, ok := initializedMigrations[20201016170415]; !ok {
10+
goose.AddMigration(Up20201016170415, Down20201016170415)
11+
initializedMigrations[20201016170415] = true
12+
}
13+
}
14+
15+
// Up20201016170415 updates cvat to a new version
16+
func Up20201016170415(tx *sql.Tx) error {
17+
// This code is executed when the migration is applied.
18+
return updateWorkspaceTemplateManifest("cvat_20201016170415.yaml", cvatTemplateName)
19+
}
20+
21+
// Down20201016170415 does nothing
22+
func Down20201016170415(tx *sql.Tx) error {
23+
// This code is executed when the migration is rolled back.
24+
return nil
25+
}

db/go/db.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import (
55
sq "github.com/Masterminds/squirrel"
66
"github.com/jmoiron/sqlx"
77
v1 "github.com/onepanelio/core/pkg"
8+
"io/ioutil"
89
"log"
10+
"os"
11+
"path/filepath"
912
"strings"
1013
)
1114

@@ -60,6 +63,7 @@ func Initialize() {
6063
initialize20200929144301()
6164
initialize20200929153931()
6265
initialize20201001070806()
66+
initialize20201016170415()
6367

6468
if err := client.DB.Close(); err != nil {
6569
log.Printf("[error] closing db %v", err)
@@ -128,3 +132,17 @@ func ReplaceArtifactRepositoryType(client *v1.Client, namespace *v1.Namespace, w
128132

129133
return nil
130134
}
135+
136+
// readDataFile returns the contents of a file in the db/data/{name} directory
137+
func readDataFile(name string) (string, error) {
138+
curDir, err := os.Getwd()
139+
if err != nil {
140+
return "", err
141+
}
142+
data, err := ioutil.ReadFile(filepath.Join(curDir, "db", "data", name))
143+
if err != nil {
144+
return "", err
145+
}
146+
147+
return string(data), nil
148+
}

db/go/util.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package migration
2+
3+
import (
4+
v1 "github.com/onepanelio/core/pkg"
5+
uid2 "github.com/onepanelio/core/pkg/util/uid"
6+
)
7+
8+
// updateWorkspaceTemplateManifest will update the workspace template given by {{templateName}} with the contents
9+
// given by {{filename}}
10+
// It will do so for all namespaces.
11+
func updateWorkspaceTemplateManifest(filename, templateName string) error {
12+
client, err := getClient()
13+
if err != nil {
14+
return err
15+
}
16+
defer client.DB.Close()
17+
18+
namespaces, err := client.ListOnepanelEnabledNamespaces()
19+
if err != nil {
20+
return err
21+
}
22+
23+
newManifest, err := readDataFile(filename)
24+
if err != nil {
25+
return err
26+
}
27+
28+
uid, err := uid2.GenerateUID(templateName, 30)
29+
if err != nil {
30+
return err
31+
}
32+
33+
for _, namespace := range namespaces {
34+
workspaceTemplate := &v1.WorkspaceTemplate{
35+
UID: uid,
36+
Name: templateName,
37+
Manifest: newManifest,
38+
}
39+
err = ReplaceArtifactRepositoryType(client, namespace, nil, workspaceTemplate)
40+
if err != nil {
41+
return err
42+
}
43+
if _, err := client.UpdateWorkspaceTemplateManifest(namespace.Name, uid, workspaceTemplate.Manifest); err != nil {
44+
return err
45+
}
46+
}
47+
48+
return nil
49+
}

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"flag"
66
"fmt"
7+
migrations "github.com/onepanelio/core/db/go"
78
"google.golang.org/grpc/codes"
89
"google.golang.org/grpc/status"
910
corev1 "k8s.io/api/core/v1"
@@ -25,7 +26,6 @@ import (
2526
"github.com/grpc-ecosystem/grpc-gateway/runtime"
2627
"github.com/jmoiron/sqlx"
2728
"github.com/onepanelio/core/api"
28-
migrations "github.com/onepanelio/core/db/go"
2929
v1 "github.com/onepanelio/core/pkg"
3030
"github.com/onepanelio/core/pkg/util/env"
3131
"github.com/onepanelio/core/server"

0 commit comments

Comments
 (0)