diff --git a/mix.lock b/mix.lock index 8cd25fd62b..4a2b07754f 100644 --- a/mix.lock +++ b/mix.lock @@ -4,7 +4,7 @@ "google_gax": {:hex, :google_gax, "0.3.2", "3746309dcf0979312ca8809f8a9f8acb007cad2ee2934406544c8a6d7282e82b", [:mix], [{:poison, ">= 3.0.0 and < 5.0.0", [hex: :poison, repo: "hexpm", optional: false]}, {:tesla, "~> 1.2", [hex: :tesla, repo: "hexpm", optional: false]}], "hexpm", "98516c995d2bde23e65ccbf3cc70645051f755392e7a6dc60d22fd09621ad386"}, "hackney": {:hex, :hackney, "1.15.2", "07e33c794f8f8964ee86cebec1a8ed88db5070e52e904b8f12209773c1036085", [:rebar3], [{:certifi, "2.5.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.5", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm", "e0100f8ef7d1124222c11ad362c857d3df7cb5f4204054f9f0f4a728666591fc"}, "idna": {:hex, :idna, "6.0.0", "689c46cbcdf3524c44d5f3dde8001f364cd7608a99556d8fbd8239a5798d4c10", [:rebar3], [{:unicode_util_compat, "0.4.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "4bdd305eb64e18b0273864920695cb18d7a2021f31a11b9c5fbcd9a253f936e2"}, - "jason": {:hex, :jason, "1.2.0", "10043418c42d2493d0ee212d3fddd25d7ffe484380afad769a0a38795938e448", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "116747dbe057794c3a3e4e143b7c8390b29f634e16c78a7f59ba75bfa6852e7f"}, + "jason": {:hex, :jason, "1.2.1", "12b22825e22f468c02eb3e4b9985f3d0cb8dc40b9bd704730efa11abd2708c44", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "b659b8571deedf60f79c5a608e15414085fa141344e2716fbd6988a084b5f993"}, "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"}, "mime": {:hex, :mime, "1.3.1", "30ce04ab3175b6ad0bdce0035cba77bba68b813d523d1aac73d9781b4d193cf8", [:mix], [], "hexpm", "6cbe761d6a0ca5a31a0931bf4c63204bceb64538e664a8ecf784a9a6f3b875f1"}, "mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"}, diff --git a/scripts/generate_client.sh b/scripts/generate_client.sh index dddf64193b..f94f3a6877 100755 --- a/scripts/generate_client.sh +++ b/scripts/generate_client.sh @@ -24,7 +24,7 @@ git clean -fdx clients function ensure_file_permissions { echo "fixing file permissions" if [[ ! -z "${USER_GROUP}" ]]; then - chown -R ${USER_GROUP} clients + chown -R ${USER_GROUP} . fi } trap ensure_file_permissions EXIT diff --git a/synth.py b/synth.py index b5dc8ab28b..c2a4ae37a7 100644 --- a/synth.py +++ b/synth.py @@ -21,28 +21,43 @@ import synthtool.shell as shell import logging import os +import pathlib +import shutil +import tempfile logging.basicConfig(level=logging.DEBUG) s.metadata.set_track_obsolete_files(False) # TODO: enable again. -repository = os.getcwd() - -image = "gcr.io/cloud-devrel-public-resources/elixir19" -generate_command = "scripts/generate_client.sh" -command = [ - "docker", - "run", - "--rm", - f"-v{repository}:/workspace", - "-v/var/run/docker.sock:/var/run/docker.sock", - "-e", f"USER_GROUP={os.getuid()}:{os.getgid()}", - "-w", "/workspace", - image, - generate_command] - -if extra_args(): - command.extend(extra_args()) - -log.debug(f"Running: {' '.join(command)}") - -shell.run(command, cwd=repository, hide_output=False) +# Copy the repo into a temporary directory, removing the build and deps, and +# perform generation there. This is because the docker command may be a +# cross-compile whose build environment should be isolated from the current +# git clone. +with tempfile.TemporaryDirectory() as tmpdir: + repository = pathlib.Path(tmpdir) / "repo" + shutil.copytree(os.getcwd(), repository) + shutil.rmtree(repository / "_build", ignore_errors=True) + shutil.rmtree(repository / "deps", ignore_errors=True) + + image = "gcr.io/cloud-devrel-public-resources/elixir19" + generate_command = "scripts/generate_client.sh" + command = [ + "docker", + "run", + "--rm", + f"-v{repository}:/workspace", + "-v/var/run/docker.sock:/var/run/docker.sock", + "-e", f"USER_GROUP={os.getuid()}:{os.getgid()}", + "-w", "/workspace", + image, + generate_command] + + if extra_args(): + command.extend(extra_args()) + + log.debug(f"Running: {' '.join(command)}") + + shell.run(command, cwd=repository, hide_output=False) + + # Copy the resulting clients directory back into the git clone. + shutil.rmtree("clients", ignore_errors=True) + shutil.move(repository / "clients", "clients")