Skip to content

Commit bd39666

Browse files
committed
Merge branch '380-ci-checker-multiple-run' into 'master'
fix (ci_checker) : avoid conflicts when CI checker sessions run at the same time (#380) Closes #380 See merge request postgres-ai/database-lab!542
2 parents dc32f5b + e475cdb commit bd39666

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

engine/cmd/runci/main.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,18 @@ func main() {
8181
return
8282
}
8383

84+
if err := os.MkdirAll(source.RepoDir, 0666); err != nil {
85+
log.Errf("failed to create a directory to download archives: %v", err)
86+
return
87+
}
88+
89+
defer func() {
90+
if err := os.RemoveAll(source.RepoDir); err != nil {
91+
log.Errf("failed to remove the directory with source code archives: %v", err)
92+
return
93+
}
94+
}()
95+
8496
codeProvider := source.NewCodeProvider(ctx, &cfg.Source)
8597

8698
srv := runci.NewServer(cfg, dleClient, platformSvc, codeProvider, dockerCLI, networkID)
@@ -114,7 +126,7 @@ func discoverNetwork(ctx context.Context, cfg *runci.Config, dockerCLI *client.C
114126
networkID := ""
115127

116128
for networkLabel, endpointSettings := range inspection.NetworkSettings.Networks {
117-
if strings.HasPrefix(networkLabel, "network_") {
129+
if strings.HasPrefix(networkLabel, networks.NetworkPrefix) {
118130
networkResource, err := dockerCLI.NetworkInspect(ctx, endpointSettings.NetworkID, types.NetworkInspectOptions{})
119131
if err != nil {
120132
log.Err(err)

engine/internal/runci/source/github.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (cp *GHProvider) Download(ctx context.Context, opts Opts, outputFile string
4444
log.Dbg(fmt.Sprintf("Download options: %#v", opts))
4545

4646
archiveLink, _, err := cp.client.Repositories.GetArchiveLink(ctx, opts.Owner, opts.Repo,
47-
github.Zipball, &github.RepositoryContentGetOptions{Ref: opts.Ref}, true)
47+
github.Zipball, &github.RepositoryContentGetOptions{Ref: getRunRef(opts)}, true)
4848
if err != nil {
4949
return errors.Wrap(err, "failed to download content")
5050
}
@@ -72,6 +72,16 @@ func (cp *GHProvider) Download(ctx context.Context, opts Opts, outputFile string
7272
return nil
7373
}
7474

75+
func getRunRef(opts Opts) string {
76+
ref := opts.Commit
77+
78+
if ref == "" {
79+
ref = opts.Ref
80+
}
81+
82+
return ref
83+
}
84+
7585
// Extract extracts downloaded repository archive.
7686
func (cp *GHProvider) Extract(file string) (string, error) {
7787
extractDirNameCmd := fmt.Sprintf("unzip -qql %s | head -n1 | tr -s ' ' | cut -d' ' -f5-", file)
@@ -85,14 +95,19 @@ func (cp *GHProvider) Extract(file string) (string, error) {
8595

8696
log.Dbg("Archive directory: ", string(bytes.TrimSpace(dirName)))
8797

88-
resp, err := exec.Command("unzip", "-d", RepoDir, file).CombinedOutput()
98+
archiveDir, err := os.MkdirTemp(RepoDir, "*_extract")
99+
if err != nil {
100+
return "", err
101+
}
102+
103+
resp, err := exec.Command("unzip", "-d", archiveDir, file).CombinedOutput()
89104
log.Dbg("Response: ", string(resp))
90105

91106
if err != nil {
92107
return "", err
93108
}
94109

95-
source := path.Join(RepoDir, string(bytes.TrimSpace(dirName)))
110+
source := path.Join(archiveDir, string(bytes.TrimSpace(dirName)))
96111
log.Dbg("Source: ", source)
97112

98113
return source, nil

engine/pkg/util/networks/networks.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ const (
2323
// InternalType contains name of the internal network type.
2424
InternalType = "internal"
2525

26-
// networkPrefix defines a distinctive prefix for internal DLE networks.
27-
networkPrefix = "dle_network_"
26+
// NetworkPrefix defines a distinctive prefix for internal DLE networks.
27+
NetworkPrefix = "dle_network_"
2828
)
2929

3030
// Setup creates a new internal Docker network and connects container to it.
@@ -164,5 +164,5 @@ func hasContainerConnected(networkResource types.NetworkResource, containerID st
164164
}
165165

166166
func getNetworkName(instanceID string) string {
167-
return networkPrefix + instanceID
167+
return NetworkPrefix + instanceID
168168
}

0 commit comments

Comments
 (0)