@@ -64,6 +64,15 @@ class AirbyteDockerPlugin implements Plugin<Project> {
64
64
static def getBaseTaggedImages (File dockerfile ) {
65
65
def result = [] as Set<String >
66
66
67
+ // Look for "FROM foo AS bar" directives, and add them to the map with .put("bar", "foo")
68
+ Map<String , String > imageAliases = [:]
69
+ dockerfile. eachLine { line ->
70
+ def parts = line. split()
71
+ if (parts. length >= 4 && parts[0 ]. equals(" FROM" ) && parts[parts. length - 2 ]. equals(" AS" )) {
72
+ imageAliases. put(parts[parts. length - 1 ], parts[1 ])
73
+ }
74
+ }
75
+
67
76
dockerfile. eachLine { line ->
68
77
if (line. startsWith(" FROM " )) {
69
78
def image = line. split()[1 ]
@@ -72,7 +81,11 @@ class AirbyteDockerPlugin implements Plugin<Project> {
72
81
} else if (line. startsWith(" COPY --from=" )) {
73
82
def image = line. substring(" COPY --from=" . length()). split()[0 ]
74
83
assert ! image. isEmpty()
75
- result. add(image)
84
+ if (imageAliases[image] != null ) {
85
+ result. add(imageAliases[image])
86
+ } else {
87
+ result. add(image)
88
+ }
76
89
}
77
90
}
78
91
@@ -93,7 +106,20 @@ class AirbyteDockerPlugin implements Plugin<Project> {
93
106
def stdout = new ByteArrayOutputStream ()
94
107
95
108
project. exec {
96
- commandLine " docker" , " images" , " --no-trunc" , " -f" , " dangling=false" , " --format" , " {{.ID}}" , taggedImage
109
+ commandLine " docker" , " images" , " --no-trunc" , " -f" , " dangling=false" , " --format" , " {{.ID}}" , resolveEnvironmentVariables(project, taggedImage)
110
+ standardOutput = stdout;
111
+ }
112
+
113
+ return " $stdout " . toString(). trim()
114
+ }
115
+
116
+ // Some image tags rely on environment variables (e.g. "FROM openjdk:${JDK_VERSION}-slim").
117
+ // dump those into a "sh -c 'echo ...'" command to resolve them (e.g. "openjdk:17-slim")
118
+ static String resolveEnvironmentVariables (Project project , String str ) {
119
+ def stdout = new ByteArrayOutputStream ()
120
+
121
+ project. exec {
122
+ commandLine " sh" , " -c" , " echo " + str
97
123
standardOutput = stdout;
98
124
}
99
125
@@ -112,7 +138,7 @@ class AirbyteDockerPlugin implements Plugin<Project> {
112
138
113
139
def notUpToDate = new ArrayList<String > (getBaseTaggedImages(dockerPath. toFile())). any { baseImage ->
114
140
logger. debug " checking base image " + baseImage
115
- def storedBase = (String ) project. rootProject. imageToHash. get(baseImage)
141
+ def storedBase = (String ) project. rootProject. imageToHash. get(resolveEnvironmentVariables(project, baseImage) )
116
142
def currentBase = getImageHash(project, baseImage)
117
143
118
144
logger. debug " storedBase " + storedBase
0 commit comments