Skip to content

Commit 097a9c3

Browse files
committed
Use Docker BuildKit secrets for Conan authentication
We don't have a simple way to persist Conan authentication against a remote repository, instead use the BuildKit secrets mechanism to pass CONAN_LOGIN_USERNAME and CONAN_PASSWORD secrets env vars to the build container. Signed-off-by: Jean-Francois Panisset <panisset@gmail.com>
1 parent cfd9a7d commit 097a9c3

3 files changed

Lines changed: 40 additions & 30 deletions

File tree

packages/common/Dockerfile

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,6 @@ ENV GCC_INSTALL_PREFIX=/opt/rh/${ASWF_DTS_PREFIX}-${ASWF_DTS_VERSION}/root/usr
162162
# With "conan create --profile" we no longer need to set a default profile
163163
ENV CONAN_HOME=${CONAN_USER_HOME}/.conan2
164164

165-
# Allow "conan upload" to authenticate without persistent storage
166-
ARG CONAN_LOGIN_USERNAME
167-
ENV CONAN_LOGIN_USERNAME=${CONAN_LOGIN_USERNAME}
168-
ARG CONAN_PASSWORD
169-
ENV CONAN_PASSWORD=${CONAN_PASSWORD}
170-
171165
RUN --mount=type=cache,target=${CONAN_USER_HOME}/d \
172166
--mount=type=cache,target=${CCACHE_DIR} \
173167
--mount=type=bind,rw,target=${CONAN_USER_HOME}/.conan2,source=packages/conan/settings \
@@ -188,6 +182,8 @@ RUN --mount=type=cache,target=${CONAN_USER_HOME}/d \
188182
--mount=type=cache,target=${CCACHE_DIR} \
189183
--mount=type=bind,rw,target=${CONAN_USER_HOME}/.conan2,source=packages/conan/settings \
190184
--mount=type=bind,rw,target=${CONAN_USER_HOME}/recipes,source=packages/conan/recipes \
185+
--mount=type=secret,id=conan_login_username,env=CONAN_LOGIN_USERNAME \
186+
--mount=type=secret,id=conan_password,env=CONAN_PASSWORD \
191187
if [ -n "${ASWF_CONAN_PUSH}" ] ; then \
192188
conan upload --remote ${ASWF_PKG_ORG} ${ASWF_PKG_NAME}/${ASWF_PKG_VERSION}@${ASWF_PKG_ORG}/${ASWF_CONAN_CHANNEL} ;\
193189
else \

python/aswfdocker/builder.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ def make_bake_dict(
131131
},
132132
"tags": tags,
133133
"output": ["type=registry,push=true" if self.push else "type=docker"],
134+
"secrets": [
135+
"id=conan_login_username,env=CONAN_LOGIN_USERNAME",
136+
"id=conan_password,env=CONAN_PASSWORD",
137+
],
134138
}
135139
if self.group_info.type == constants.ImageType.PACKAGE:
136140
if use_conan:
@@ -236,24 +240,25 @@ def _build_conan_package(
236240
):
237241
# pylint: disable=consider-using-f-string
238242
major_version = utils.get_major_version(version)
239-
version_info = self.index.version_info(major_version)
240-
base_cmd = self._get_conan_base_cmd(version_info)
241-
if conan_login:
242-
# We keep this as a separate step: the end result is to store credentials in
243-
# packages/conan/.conan/.conan.db which is not thread safe: once we are able
244-
# to run Conan builds from a single "docker buildx bake" invocation, we will
245-
# want to keep the login step separate.
246-
self._run_in_docker(
247-
base_cmd,
248-
[
249-
"conan",
250-
"remote",
251-
"auth",
252-
self.build_info.docker_org,
253-
],
254-
dry_run,
255-
)
256-
#
243+
# version_info = self.index.version_info(major_version)
244+
# base_cmd = self._get_conan_base_cmd(version_info)
245+
# if conan_login:
246+
# # "conan remote auth" stores credentials in
247+
# # ${CONAN_HOME]/.conan2/credentials.json but we don't have a simple way to persist
248+
# # this file between build steps, since instead we will use the secrets mechanism
249+
# # in the buildx bake file to pass the CONNA_LOGIN_USERNAME and CONAN_PASSWORD
250+
# # values as environment variables to allow `conan upload" to authenticate on the fly.
251+
# self._run_in_docker(
252+
# base_cmd,
253+
# [
254+
# "conan",
255+
# "remote",
256+
# "auth",
257+
# self.build_info.docker_org,
258+
# ],
259+
# dry_run,
260+
# )
261+
257262
# These are kept for reference, they now live in
258263
# packages/common/Dockerfile
259264
#

python/aswfdocker/tests/test_builder.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ def test_image_base_2019clang_dict(self):
194194
f"{constants.DOCKER_REGISTRY}/aswflocaltesting/ci-openvdb:{openvdb_version}",
195195
],
196196
"output": ["type=docker"],
197+
"secrets": [
198+
"id=conan_login_username,env=CONAN_LOGIN_USERNAME",
199+
"id=conan_password,env=CONAN_PASSWORD",
200+
],
197201
}
198202
},
199203
},
@@ -281,6 +285,10 @@ def test_image_base_2019_2020_dict(self):
281285
f"{constants.DOCKER_REGISTRY}/aswflocaltesting/ci-base:{base_versions[1]}",
282286
],
283287
"output": ["type=docker"],
288+
"secrets": [
289+
"id=conan_login_username,env=CONAN_LOGIN_USERNAME",
290+
"id=conan_password,env=CONAN_PASSWORD",
291+
],
284292
},
285293
"ci-base-2019": {
286294
"context": ".",
@@ -346,6 +354,10 @@ def test_image_base_2019_2020_dict(self):
346354
f"{constants.DOCKER_REGISTRY}/aswflocaltesting/ci-base:{base_versions[0]}",
347355
],
348356
"output": ["type=docker"],
357+
"secrets": [
358+
"id=conan_login_username,env=CONAN_LOGIN_USERNAME",
359+
"id=conan_password,env=CONAN_PASSWORD",
360+
],
349361
},
350362
},
351363
},
@@ -503,25 +515,22 @@ def test_builderlist_cli_conan(self):
503515
tempfile.gettempdir(), "docker-bake-PACKAGE-vfx1-2-2019-2020.json"
504516
)
505517
cmds = result.output.strip().splitlines()
506-
# We expect 5 steps
518+
# We expect 3 steps
507519
# 1 - docker buildx to build the non-Conan packages
508-
# 2 - docker run to login to repository (2x for each image)
509-
# 3 - docker buildx to build and upload (2x for each openexr package)
510-
self.assertEqual(len(cmds), 5)
520+
# 2 - docker buildx to build and upload (2x for each openexr package)
521+
self.assertEqual(len(cmds), 3)
511522
self.assertEqual(
512523
cmds[self._i],
513524
f"INFO:aswfdocker.builder:Would run: 'docker buildx bake -f {bake_path} --progress auto'",
514525
)
515526
self._i += 1
516-
self._assertEndsWith(cmds, "conan remote auth aswftesting'")
517527
self.assertEqual(
518528
cmds[self._i],
519529
f"INFO:aswfdocker.builder:Would run: 'docker buildx bake -f {bake_path} "
520530
+ "--set=*.output=type=cacheonly --set=*.target.target=ci-conan-package-builder "
521531
+ "--progress auto ci-package-openexr-2019'",
522532
)
523533
self._i += 1
524-
self._assertEndsWith(cmds, "conan remote auth aswftesting'")
525534
self.assertEqual(
526535
cmds[self._i],
527536
f"INFO:aswfdocker.builder:Would run: 'docker buildx bake -f {bake_path} "

0 commit comments

Comments
 (0)