@@ -3,6 +3,9 @@ package chipingressset
33import (
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+ }
0 commit comments