Skip to content

Commit

Permalink
auth to dockerhub sometime
Browse files Browse the repository at this point in the history
  • Loading branch information
alafanechere committed Apr 14, 2023
1 parent 9308133 commit d82bf88
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ def with_python_base(context: PipelineContext, python_image_name: str = "python:
.with_exec(["pip", "install", "--upgrade", "pip"])
)

if context.is_ci:
base_container = with_authenticated_to_docker_hub(context, base_container, python_image_name.split(":")[0])

return base_container


Expand Down Expand Up @@ -341,7 +344,7 @@ async def with_connector_acceptance_test(context: ConnectorTestContext, connecto
cat_container = context.dagger_client.container().from_(context.connector_acceptance_test_image)
shared_tmp_volume = ("/tmp", context.dagger_client.cache_volume("share-tmp-cat"))

return (
cat = (
with_bound_docker_host(context, cat_container, shared_tmp_volume, docker_service_name="cat")
.with_entrypoint([])
.with_exec(["pip", "install", "pytest-custom_exit_code"])
Expand All @@ -351,6 +354,8 @@ async def with_connector_acceptance_test(context: ConnectorTestContext, connecto
.with_entrypoint(["python", "-m", "pytest", "-p", "connector_acceptance_test.plugin", "--suppress-tests-failed-exit-code"])
.with_exec(["--acceptance-test-config", "/test_input"])
)
if context.is_ci:
return with_authenticated_to_docker_hub(context, cat, context.connector_acceptance_test_image.split(":")[0])


def with_gradle(
Expand Down Expand Up @@ -413,9 +418,12 @@ def with_gradle(
.with_workdir("/airbyte")
)
if bind_to_docker_host:
return with_bound_docker_host(context, openjdk_with_docker, shared_tmp_volume, docker_service_name=docker_service_name)
else:
return openjdk_with_docker
openjdk_with_docker = with_bound_docker_host(
context, openjdk_with_docker, shared_tmp_volume, docker_service_name=docker_service_name
)
if context.is_ci:
openjdk_with_docker = with_authenticated_to_docker_hub(context, openjdk_with_docker, "openjdk")
return openjdk_with_docker


async def load_image_to_docker_host(
Expand Down Expand Up @@ -527,8 +535,7 @@ async def with_airbyte_java_connector(context: ConnectorTestContext, connector_j
application = context.connector.technical_name
java_base = await with_java_base(context)
enable_sentry = await should_enable_sentry(dockerfile)

return (
java_connector = (
java_base.with_workdir("/airbyte")
.with_env_variable("APPLICATION", application)
.with_file(f"{application}.tar", connector_java_tar_file)
Expand All @@ -539,13 +546,22 @@ async def with_airbyte_java_connector(context: ConnectorTestContext, connector_j
.with_env_variable("ENABLE_SENTRY", str(enable_sentry).lower())
.with_entrypoint("/airbyte/base.sh")
)
if context.is_ci:
return with_authenticated_to_docker_hub(context, java_connector, f"airbyte/{application}")
return java_connector


def with_normalization(context, normalization_dockerfile_name: str) -> Container:
def with_normalization(context: ConnectorTestContext, normalization_dockerfile_name: str) -> Container:
normalization_directory = context.get_repo_dir("airbyte-integrations/bases/base-normalization")
sshtunneling_file = context.get_repo_dir(
"airbyte-connector-test-harnesses/acceptance-test-harness/src/main/resources", include="sshtunneling.sh"
).file("sshtunneling.sh")
normalization_directory_with_build = normalization_directory.with_new_directory("build")
normalization_directory_with_sshtunneling = normalization_directory_with_build.with_file("build/sshtunneling.sh", sshtunneling_file)
return normalization_directory_with_sshtunneling.docker_build(normalization_dockerfile_name)


def with_authenticated_to_docker_hub(context: ConnectorTestContext, container: Container, docker_image_name: str) -> Container:
docker_hub_username: str = context.dagger_client.host().env_variable("DOCKER_HUB_USERNAME").value()
docker_hub_password: Secret = context.dagger_client.host().env_variable("DOCKER_HUB_PASSWORD").secret()
return container.with_registry_auth(f"docker.io/{docker_image_name}:latest", docker_hub_username, docker_hub_password)
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ async def _run(self) -> Tuple[StepResult, File]:
build_normalization_container = environments.with_normalization(self.context, self.normalization_dockerfile)
else:
build_normalization_container = self.context.dagger_client.container().from_(self.normalization_image)

if self.context.is_ci:
build_normalization_container = environments.with_authenticated_to_docker_hub(
self.context, build_normalization_container, self.normalization_image.split(":")[0]
)
try:
export_success = await build_normalization_container.export(f"{self.host_image_export_dir_path}/{normalization_local_tar_path}")
if export_success:
Expand Down

0 comments on commit d82bf88

Please sign in to comment.