Skip to content

Commit 2c2fd91

Browse files
committed
add support for remote docker file + TOML tags
1 parent e4f7cf2 commit 2c2fd91

File tree

2 files changed

+55
-5
lines changed

2 files changed

+55
-5
lines changed

framework/components/chip_ingress_set/chip_ingress.go

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ package chipingressset
33
import (
44
"context"
55
"fmt"
6+
"io"
7+
"net/http"
8+
"os"
69
"strings"
710
"time"
811

@@ -68,8 +71,13 @@ func New(in *Input) (*Output, error) {
6871
in = defaultChipIngress(in)
6972
identifier := framework.DefaultTCName(DEFAULT_CHIP_INGRESS_SERVICE_NAME)
7073

74+
composeFilePath, fileErr := composeFilePath(in.ComposeFile)
75+
if fileErr != nil {
76+
return nil, errors.Wrap(fileErr, "failed to get compose file path")
77+
}
78+
7179
stack, stackErr := compose.NewDockerComposeWith(
72-
compose.WithStackFiles(in.ComposeFile),
80+
compose.WithStackFiles(composeFilePath),
7381
compose.StackIdentifier(identifier),
7482
)
7583
if stackErr != nil {
@@ -195,3 +203,30 @@ func New(in *Input) (*Output, error) {
195203

196204
return output, nil
197205
}
206+
207+
func composeFilePath(rawFilePath string) (string, error) {
208+
// if it's not a URL, return it as is and assume it's a local file
209+
if !strings.HasPrefix(rawFilePath, "http") {
210+
return rawFilePath, nil
211+
}
212+
213+
resp, respErr := http.Get(rawFilePath)
214+
if respErr != nil {
215+
return "", errors.Wrap(respErr, "failed to download docker-compose file")
216+
}
217+
defer resp.Body.Close()
218+
219+
tempFile, tempErr := os.CreateTemp(".", "chip-ingress-docker-compose.yml")
220+
if tempErr != nil {
221+
return "", errors.Wrap(tempErr, "failed to create temp file")
222+
}
223+
defer tempFile.Close()
224+
225+
_, copyErr := io.Copy(tempFile, resp.Body)
226+
if copyErr != nil {
227+
tempFile.Close()
228+
return "", errors.Wrap(copyErr, "failed to write compose file")
229+
}
230+
231+
return tempFile.Name(), nil
232+
}

framework/components/chip_ingress_set/protos.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ type protoFile struct {
2323
}
2424

2525
type RepoConfiguration struct {
26-
Owner string
27-
Repo string
28-
Ref string // ref or tag or commit SHA
29-
Folders []string // if not provided, all protos will be fetched, otherwise only protos in these folders will be fetched
26+
Owner string `toml:"owner"`
27+
Repo string `toml:"repo"`
28+
Ref string `toml:"ref"` // ref or tag or commit SHA
29+
Folders []string `toml:"folders"` // if not provided, all protos will be fetched, otherwise only protos in these folders will be fetched
3030
}
3131

3232
// SubjectNamingStrategyFn is a function that is used to determine the subject name for a given proto file in a given repo
@@ -40,6 +40,21 @@ var DefaultRepoToSubjectNamingStrategy = RepoToSubjectNamingStrategyFn{
4040
"chainlink-protos": ChainlinkProtosSubjectNamingStrategy,
4141
}
4242

43+
func ValidateRepoConfiguration(repoConfig RepoConfiguration) error {
44+
if repoConfig.Owner == "" {
45+
return errors.New("owner is required")
46+
}
47+
if repoConfig.Repo == "" {
48+
return errors.New("repo is required")
49+
}
50+
51+
if repoConfig.Ref == "" {
52+
return errors.New("ref is required")
53+
}
54+
55+
return nil
56+
}
57+
4358
func DefaultRegisterAndFetchProtos(ctx context.Context, client *github.Client, reposConfig []RepoConfiguration, schemaRegistryURL string) error {
4459
return RegisterAndFetchProtos(ctx, client, reposConfig, schemaRegistryURL, DefaultRepoToSubjectNamingStrategy)
4560
}

0 commit comments

Comments
 (0)