-
Notifications
You must be signed in to change notification settings - Fork 0
/
ecs.go
37 lines (29 loc) · 774 Bytes
/
ecs.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
package vresolver
import (
"encoding/json"
"io/ioutil"
"strings"
)
// ECSMetadataFileEnvVar contains the default env var
// name that points to the container metadata file
const ECSMetadataFileEnvVar = "ECS_CONTAINER_METADATA_FILE"
// ECS extracts the tag of the Docker image in use.
// See AWS ECS Container Metadata File: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/container-metadata.html
func ECS(file string) string {
if file == "" {
return ""
}
content, err := ioutil.ReadFile(file)
if err != nil {
return ""
}
metadata := struct{ ImageName string }{}
if err := json.Unmarshal(content, &metadata); err != nil {
return ""
}
parts := strings.Split(metadata.ImageName, ":")
if len(parts) < 2 {
return ""
}
return parts[1]
}