@@ -78,20 +78,12 @@ const (
78
78
)
79
79
80
80
func (a * app ) run (cmd * cobra.Command , args []string ) error {
81
- defer func () {
82
- err := a .logger .Sync ()
83
- if err != nil && errors .Is (err , syscall .EINVAL ) {
84
- // Sync is not supported on os.Stderr / os.Stdout on arm64 alpine:3.20.3
85
- } else if err != nil {
86
- log .Fatal (err )
87
- }
88
- }()
89
81
ctx := context .Background ()
90
- target := func (tag string , path string ) string {
91
- return fmt .Sprintf ("/ %s/%s" , tag , path )
82
+ target := func (destination string , path string ) string {
83
+ return fmt .Sprintf ("%s/%s" , destination , path )
92
84
}
93
- outputer := func (in []byte , tag , path string ) error {
94
- if err := os .WriteFile (target (tag , path ), in , 0o644 ); err != nil {
85
+ outputer := func (in []byte , destination , path string ) error {
86
+ if err := os .WriteFile (target (destination , path ), in , 0o644 ); err != nil {
95
87
a .logger .Error ("fail to write file" , zap .Error (errors .ErrUnsupported ))
96
88
return err
97
89
}
@@ -102,19 +94,31 @@ func (a *app) run(cmd *cobra.Command, args []string) error {
102
94
if err := gitClient .Clone (a .githubUrl ); err != nil {
103
95
return err
104
96
}
97
+ defer func () {
98
+ err := gitClient .Close ()
99
+ if err != nil {
100
+ log .Fatal (err )
101
+ }
102
+ err = a .logger .Sync ()
103
+ if err != nil && errors .Is (err , syscall .EINVAL ) {
104
+ // Sync is not supported on os.Stderr / os.Stdout on arm64 alpine:3.20.3
105
+ } else if err != nil {
106
+ log .Fatal (err )
107
+ }
108
+ }()
105
109
106
110
s := selectStrategy (a .containerPath , a .taskPath )
107
111
108
112
switch s {
109
113
case TASK_DEFINITION :
110
- ext := filepath .Ext (target (a . tag , a .taskPath ))
114
+ ext := filepath .Ext (target (gitClient . GetDestination () , a .taskPath ))
111
115
format := encoder .GetFormat (ext )
112
116
if format == encoder .Unknow {
113
117
err := errors .New ("unknow extension" )
114
118
a .logger .Error ("unknown extension" , zap .Error (err ))
115
119
return err
116
120
}
117
- in , err := os .ReadFile (target (a . tag , a .taskPath ))
121
+ in , err := os .ReadFile (target (gitClient . GetDestination () , a .taskPath ))
118
122
if err != nil {
119
123
a .logger .Error ("fail to open target file" , zap .Error (err ))
120
124
return err
@@ -139,18 +143,19 @@ func (a *app) run(cmd *cobra.Command, args []string) error {
139
143
githubClient ,
140
144
)
141
145
if err != nil {
146
+ a .logger .Error ("execute task definition" , zap .Error (err ))
142
147
return err
143
148
}
144
149
145
150
case CONTAINER_DEFINITION :
146
- ext := filepath .Ext (target (a . tag , a .containerPath ))
151
+ ext := filepath .Ext (target (gitClient . GetDestination () , a .containerPath ))
147
152
format := encoder .GetFormat (ext )
148
153
if format == encoder .Unknow {
149
154
err := errors .New ("unknow extension" )
150
155
a .logger .Error ("" , zap .Error (err ))
151
156
return err
152
157
}
153
- in , err := os .ReadFile (target (a . tag , a .containerPath ))
158
+ in , err := os .ReadFile (target (gitClient . GetDestination () , a .containerPath ))
154
159
if err != nil {
155
160
a .logger .Error ("fail to open target file" , zap .Error (err ))
156
161
return err
@@ -175,6 +180,7 @@ func (a *app) run(cmd *cobra.Command, args []string) error {
175
180
githubClient ,
176
181
)
177
182
if err != nil {
183
+ a .logger .Info ("execute container definition" , zap .Error (err ))
178
184
return err
179
185
}
180
186
case UNKNOW_DEFINITION :
@@ -212,7 +218,7 @@ func execute[P ecs.EcsTarget](
212
218
transformer transformer.Transformer [P ],
213
219
encoder encoder.Encoder [P ],
214
220
decoder decoder.Decoder [P ],
215
- outputer func (in []byte , tag , path string ) error ,
221
+ outputer func (in []byte , destination , path string ) error ,
216
222
gitClient git.Git ,
217
223
githubClient github.Github ,
218
224
) error {
@@ -228,7 +234,7 @@ func execute[P ecs.EcsTarget](
228
234
if err != nil {
229
235
return err
230
236
}
231
- if err := outputer (decoded , tag , path ); err != nil {
237
+ if err := outputer (decoded , gitClient . GetDestination () , path ); err != nil {
232
238
return err
233
239
}
234
240
if err := gitClient .Add (path ); err != nil {
0 commit comments