Skip to content

Commit db5a796

Browse files
yzheng6GitHub Enterprise
authored andcommitted
Create image tags based on Jenkins run to avoid race condition (#759)
Use the username and abbreviated git hash, if available, to create unique Docker image tags. Also specifies Docker centos7 base image SHA (other OS are not used currently). Example with git info: REPOSITORY TAG IMAGE ID nisar-adt/isce3 centos7conda-nisar-yzheng-5f3e4714 39c58c69f136 nisar-adt/isce3 centos7conda-yzheng-5f3e4714 753d172c2241 nisar-adt/isce3dev centos7conda-dev-yzheng-5f3e4714 c854b0666f86 nisar-adt/isce3dev centos7conda-runtime-yzheng-5f3e4714 88d3297e2c85 Example without git info: REPOSITORY TAG IMAGE ID nisar-adt/isce3 centos7conda-nisar-yzheng 1235fbd655e3 nisar-adt/isce3 centos7conda-yzheng f3a110d9b86 nisar-adt/isce3dev centos7conda-dev-yzheng c854b0666f86 nisar-adt/isce3dev centos7conda-runtime-yzheng 88d3297e2c85
1 parent f31a4b5 commit db5a796

File tree

3 files changed

+38
-18
lines changed

3 files changed

+38
-18
lines changed

tools/imagesets/centos7conda/distrib_nisar/Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ARG distrib_img
22
# create intermediate image to hide credentials
3-
FROM alpine as distrib_nisar_tmp
3+
FROM alpine
44

55
# install git
66
RUN apk add git
@@ -21,9 +21,9 @@ RUN conda install testfixtures scikit-image
2121
RUN conda install cfunits --channel conda-forge
2222

2323
# copy the repo from the intermediate image
24-
COPY --from=distrib_nisar_tmp /opt/QualityAssurance /opt/QualityAssurance
25-
COPY --from=distrib_nisar_tmp /opt/CFChecker /opt/CFChecker
26-
COPY --from=distrib_nisar_tmp /opt/calTools /opt/calTools
24+
COPY --from=0 /opt/QualityAssurance /opt/QualityAssurance
25+
COPY --from=0 /opt/CFChecker /opt/CFChecker
26+
COPY --from=0 /opt/calTools /opt/calTools
2727

2828
# install
2929
RUN cd /opt/QualityAssurance \

tools/imagesets/centos7conda/runtime/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM nvidia/cuda:11.0-base-centos7
1+
# Use specific version of nvidia/cuda:11.0-base-centos7 image
2+
FROM nvidia/cuda@sha256:260c6346ca819adcfb71993ad44c0d0623ab93ce6df67567eec9d2278da07802
23

34
# Trying to install a package that doesn't exist should be an error.
45
RUN yum update -y \

tools/imagesets/imgset.py

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import os, subprocess, sys, shutil, stat, logging, shlex
1+
import os, subprocess, sys, shutil, stat, logging, shlex, getpass
22
# see no evil
33
from .workflowdata import workflowdata, workflowtests
44
pjoin = os.path.join
@@ -65,11 +65,31 @@ class ImageSet:
6565

6666
cpack_generator = "RPM"
6767

68-
def imgname(self, img):
69-
return f"nisar-adt/isce3dev:{self.name}-{img}" # labels used for above images
68+
def imgname(self, repomod="", tagmod=""):
69+
"""
70+
Return unique Docker image name per Jenkins run, uses Jenkins environment variables
71+
JOB_NAME and EXECUTOR_NUMBER
72+
73+
Parameters
74+
----------
75+
repomod : str, optional
76+
Modifier to nominal Docker repository name
77+
tagmod : str, optional
78+
Modifier to nominal Docker tag name
79+
80+
"""
81+
if tagmod != "":
82+
tagmod = "-" + tagmod
83+
try:
84+
gitmod = '-' + subprocess.check_output(["git", "rev-parse", "--short", "HEAD"]).decode('ascii').strip()
85+
except:
86+
gitmod = ""
87+
return f"nisar-adt/isce3{repomod}:{self.name}{tagmod}" \
88+
+ f"-{getpass.getuser()}{gitmod}"
7089

7190
def docker_run(self, img, cmd):
72-
runcmd = f"{docker} run {self.run_args} --rm -i {self.tty} {self.imgname(img)} bash -ci"
91+
runcmd = f"{docker} run {self.run_args} --rm -i {self.tty} " \
92+
+ f"{self.imgname(repomod='dev', tagmod=img)} bash -ci"
7393
subprocess.check_call(runcmd.split() + [cmd])
7494

7595
def docker_run_dev(self, cmd):
@@ -97,7 +117,7 @@ def __init__(self, name, *, projblddir, printlog=False):
97117
self.testdir = projblddir + "/workflow_testdata_tmp/test"
98118
self.build_args = f'''
99119
--network=host
100-
''' + " ".join(f"--build-arg {x}_img={self.imgname(x)}" for x in self.imgs)
120+
''' + " ".join(f"--build-arg {x}_img={self.imgname(repomod='dev', tagmod=x)}" for x in self.imgs)
101121

102122
self.cmake_defs = {
103123
"WITH_CUDA": "YES",
@@ -135,7 +155,8 @@ def setup(self):
135155
(should not change often, so these will usually be cached)
136156
"""
137157
for img in self.imgs:
138-
cmd = f"{docker} build {self.build_args} {thisdir}/{self.name}/{img} -t {self.imgname(img)}"
158+
cmd = f"{docker} build {self.build_args} {thisdir}/{self.name}/{img}" \
159+
+ f" -t {self.imgname(repomod='dev', tagmod=img)}"
139160
subprocess.check_call(cmd.split())
140161

141162
def configure(self):
@@ -192,7 +213,7 @@ def makedistrib(self):
192213
squash_arg = "--squash" if "Experimental: true" in docker_info else ""
193214

194215
cmd = f"{docker} build {self.build_args} {squash_arg} \
195-
{thisdir}/{self.name}/distrib -t nisar-adt/isce3:{self.name}"
216+
{thisdir}/{self.name}/distrib -t {self.imgname()}"
196217
subprocess.check_call(cmd.split())
197218

198219

@@ -202,11 +223,11 @@ def makedistrib_nisar(self):
202223
noise estimator caltool
203224
"""
204225

205-
build_args = f"--build-arg distrib_img=nisar-adt/isce3:{self.name} \
226+
build_args = f"--build-arg distrib_img={self.imgname()} \
206227
--build-arg GIT_OAUTH_TOKEN={os.environ.get('GIT_OAUTH_TOKEN').strip()}"
207228

208229
cmd = f"{docker} build {build_args} \
209-
{thisdir}/{self.name}/distrib_nisar -t nisar-adt/isce3:{self.name}-nisar"
230+
{thisdir}/{self.name}/distrib_nisar -t {self.imgname(tagmod='nisar')}"
210231
subprocess.check_call(cmd.split())
211232

212233

@@ -280,10 +301,9 @@ def distribrun(self, testdir, cmd, logfile=None, dataname=None, nisarimg=False,
280301
logger.addHandler(hdlr)
281302

282303
if nisarimg:
283-
tag = self.name + "-nisar"
304+
img = self.imgname(tagmod="nisar")
284305
else:
285-
tag = self.name
286-
img = 'nisar-adt/isce3:' + tag
306+
img = self.imgname()
287307

288308
datamount = ""
289309
if dataname is not None:
@@ -560,4 +580,3 @@ def tartests(self):
560580
for test in workflowtests[workflow]:
561581
print(f"\ntarring workflow test {test}\n")
562582
subprocess.check_call(f"tar cvzf {test}.tar.gz {test}".split(), cwd=self.testdir)
563-

0 commit comments

Comments
 (0)