/
step_store.go
68 lines (61 loc) · 2.54 KB
/
step_store.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright (c) 2021 Terminus, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package actionagent
import (
"path/filepath"
"strings"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/erda-project/erda/modules/actionagent/agenttool"
"github.com/erda-project/erda/modules/pipeline/pipengine/pvolumes"
"github.com/erda-project/erda/modules/pipeline/spec"
"github.com/erda-project/erda/pkg/filehelper"
)
func (agent *Agent) store() {
for _, out := range agent.Arg.Context.OutStorages {
switch out.Type {
case string(spec.StoreTypeNFS):
tarFile := strings.TrimPrefix(out.Value, spec.StoreTypeNFSProto)
tarDir := filepath.Join(agent.EasyUse.ContainerContext, out.Name)
err := agenttool.Tar(tarFile, tarDir)
if err != nil {
agent.AppendError(err)
}
case string(spec.StoreTypeDiceVolumeLocal), string(spec.StoreTypeDiceVolumeFake):
// nothing
case string(spec.StoreTypeOSS):
agent.AppendError(errors.New("[store] not implemented now for OSS storage"))
// dice-nfs-volume 类型,store 时将对应 containerContext 下的 task namespace 整个压缩为 volume.path 下的 data (.tar)
case string(spec.StoreTypeDiceVolumeNFS):
tarFile := filepath.Join(out.Value, "data")
tarDir := filepath.Join(agent.EasyUse.ContainerContext, out.Name)
err := agenttool.Tar(tarFile, tarDir)
if err != nil {
agent.AppendError(err)
}
case string(spec.StoreTypeDiceCacheNFS):
tarFile := out.Value + "/" + out.Labels[pvolumes.TaskCacheHashName] + pvolumes.TaskCacheCompressionSuffix
if filehelper.CheckExist(out.Labels[pvolumes.TaskCachePath], true) != nil {
logrus.Printf("upload action cache error: %s is not dir", out.Labels[pvolumes.TaskCachePath])
continue
}
if err := agenttool.Tar(tarFile, out.Labels[pvolumes.TaskCachePath]); err != nil {
logrus.Printf("StoreTypeDiceCacheNFS tar error: %v", err)
}
logrus.Printf("upload action cache %s success", out.Labels[pvolumes.TaskCachePath])
default:
agent.AppendError(errors.Errorf("[store] unsupported store type: %s", out.Type))
}
}
}