This repository has been archived by the owner on Dec 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 133
/
edge.go
122 lines (102 loc) · 3.05 KB
/
edge.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package build
import (
"fmt"
"os"
"path/filepath"
)
const (
msedgeDriverBinary = "msedgedriver"
)
type Edge struct {
Requirements
}
func (c *Edge) Build() error {
pkgSrcPath, pkgVersion, err := c.BrowserSource.Prepare()
if err != nil {
return fmt.Errorf("invalid browser source: %v", err)
}
pkgTagVersion := extractVersion(pkgVersion)
// Build dev image
devDestDir, err := tmpDir()
if err != nil {
return fmt.Errorf("create dev temporary dir: %v", err)
}
srcDir := "edge/apt"
if pkgSrcPath != "" {
srcDir = "edge/local"
pkgDestDir := filepath.Join(devDestDir, srcDir)
err := os.MkdirAll(pkgDestDir, 0755)
if err != nil {
return fmt.Errorf("create %v temporary dir: %v", pkgDestDir, err)
}
pkgDestPath := filepath.Join(pkgDestDir, "microsoft-edge.deb")
err = os.Rename(pkgSrcPath, pkgDestPath)
if err != nil {
return fmt.Errorf("move package: %v", err)
}
}
devImageTag := fmt.Sprintf("selenoid/dev_edge:%s", pkgTagVersion)
devImageRequirements := Requirements{NoCache: c.NoCache, Tags: []string{devImageTag}}
devImage, err := NewImage(srcDir, devDestDir, devImageRequirements)
if err != nil {
return fmt.Errorf("init dev image: %v", err)
}
devBuildArgs := []string{fmt.Sprintf("VERSION=%s", pkgVersion)}
devBuildArgs = append(devBuildArgs, c.channelToBuildArgs()...)
devImage.BuildArgs = devBuildArgs
if pkgSrcPath != "" {
devImage.FileServer = true
}
err = devImage.Build()
if err != nil {
return fmt.Errorf("build dev image: %v", err)
}
// Build main image
destDir, err := tmpDir()
if err != nil {
return fmt.Errorf("create temporary dir: %v", err)
}
image, err := NewImage("edge", destDir, c.Requirements)
if err != nil {
return fmt.Errorf("init image: %v", err)
}
image.BuildArgs = append(image.BuildArgs, fmt.Sprintf("VERSION=%s", pkgTagVersion))
driverVersion, err := c.downloadMSEdgeDriver(image.Dir)
if err != nil {
return fmt.Errorf("failed to download msedgedriver: %v", err)
}
image.Labels = []string{fmt.Sprintf("driver=msedgedriver:%s", driverVersion)}
err = image.Build()
if err != nil {
return fmt.Errorf("build image: %v", err)
}
err = image.Test(c.TestsDir, "MicrosoftEdge", pkgTagVersion)
if err != nil {
return fmt.Errorf("test image: %v", err)
}
err = image.Push()
if err != nil {
return fmt.Errorf("push image: %v", err)
}
return nil
}
func (c *Edge) channelToBuildArgs() []string {
switch c.BrowserChannel {
case "beta":
return []string{"PACKAGE=microsoft-edge-beta", "INSTALL_DIR=msedge-beta"}
case "dev":
return []string{"PACKAGE=microsoft-edge-dev", "INSTALL_DIR=msedge-dev"}
default:
return []string{}
}
}
func (c *Edge) downloadMSEdgeDriver(dir string) (string, error) {
version := c.DriverVersion
// Full driver versions list can be fetched as XML from https://msedgedriver.azureedge.net/
u := fmt.Sprintf("https://msedgewebdriverstorage.blob.core.windows.net/edgewebdriver/%s/edgedriver_linux64.zip", version)
_, err := downloadDriver(u, msedgeDriverBinary, dir)
if err != nil {
return "", fmt.Errorf("download msedgedriver: %v", err)
}
return version, nil
}