MCPcopy Create free account
hub / github.com/Scalingo/cli / DeployWar

Function DeployWar

deployments/deploy_war.go:26–99  ·  view source on GitHub ↗
(ctx context.Context, appName, warPath, gitRef string, opts DeployOpts)

Source from the content-addressed store, hash-verified

24}
25
26func DeployWar(ctx context.Context, appName, warPath, gitRef string, opts DeployOpts) error {
27 var warReadStream io.ReadCloser
28
29 var warSize int64
30 var warFileName string
31
32 c, err := config.ScalingoClient(ctx)
33 if err != nil {
34 return errors.Wrapf(ctx, err, "fail to get Scalingo client")
35 }
36
37 if strings.HasPrefix(warPath, "http://") || strings.HasPrefix(warPath, "https://") {
38 warReadStream, warSize, err = getURLInfo(ctx, warPath)
39 if err != nil {
40 return errors.Wrapf(ctx, err, "get WAR URL info")
41 }
42 warFileName = appName + ".war"
43 } else {
44 warReadStream, warSize, warFileName, err = getFileInfo(ctx, warPath)
45 if err != nil {
46 return errors.Wrapf(ctx, err, "get WAR file info")
47 }
48 }
49 defer warReadStream.Close()
50 // Create the tar header
51 header := &tar.Header{
52 Name: fmt.Sprintf("%s/%s", appName, warFileName),
53 Typeflag: tar.TypeReg, // Is a regular file
54 Mode: 0640,
55 ModTime: time.Now(),
56 AccessTime: time.Now(),
57 ChangeTime: time.Now(),
58 }
59 if warSize != 0 {
60 header.Size = warSize
61 } else {
62 return errors.New(ctx, "unknown WAR size")
63 }
64
65 // Get the sources endpoints
66 sources, err := c.SourcesCreate(ctx)
67 if err != nil {
68 return errors.Wrapf(ctx, err, "create WAR deployment source")
69 }
70
71 archiveBuffer := new(bytes.Buffer)
72 gzWriter := gzip.NewWriter(archiveBuffer)
73 tarWriter := tar.NewWriter(gzWriter)
74
75 err = tarWriter.WriteHeader(header)
76 if err != nil {
77 return errors.Wrapf(ctx, err, "create tarball")
78 }
79
80 _, err = io.Copy(tarWriter, warReadStream)
81 if err != nil {
82 return errors.Wrapf(ctx, err, "copy war content")
83 }

Callers 1

deployments.goFile · 0.92

Calls 5

ScalingoClientFunction · 0.92
getURLInfoFunction · 0.85
getFileInfoFunction · 0.85
uploadArchiveFunction · 0.85
DeployFunction · 0.85

Tested by

no test coverage detected