Skip to content

Commit b97a992

Browse files
authored
fix: run synth docker script in a separate directory (googleapis#5285)
1 parent de8280c commit b97a992

File tree

3 files changed

+38
-23
lines changed

3 files changed

+38
-23
lines changed

mix.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"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"},
55
"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"},
66
"idna": {:hex, :idna, "6.0.0", "689c46cbcdf3524c44d5f3dde8001f364cd7608a99556d8fbd8239a5798d4c10", [:rebar3], [{:unicode_util_compat, "0.4.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "4bdd305eb64e18b0273864920695cb18d7a2021f31a11b9c5fbcd9a253f936e2"},
7-
"jason": {:hex, :jason, "1.2.0", "10043418c42d2493d0ee212d3fddd25d7ffe484380afad769a0a38795938e448", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "116747dbe057794c3a3e4e143b7c8390b29f634e16c78a7f59ba75bfa6852e7f"},
7+
"jason": {:hex, :jason, "1.2.1", "12b22825e22f468c02eb3e4b9985f3d0cb8dc40b9bd704730efa11abd2708c44", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "b659b8571deedf60f79c5a608e15414085fa141344e2716fbd6988a084b5f993"},
88
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"},
99
"mime": {:hex, :mime, "1.3.1", "30ce04ab3175b6ad0bdce0035cba77bba68b813d523d1aac73d9781b4d193cf8", [:mix], [], "hexpm", "6cbe761d6a0ca5a31a0931bf4c63204bceb64538e664a8ecf784a9a6f3b875f1"},
1010
"mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"},

scripts/generate_client.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ git clean -fdx clients
2424
function ensure_file_permissions {
2525
echo "fixing file permissions"
2626
if [[ ! -z "${USER_GROUP}" ]]; then
27-
chown -R ${USER_GROUP} clients
27+
chown -R ${USER_GROUP} .
2828
fi
2929
}
3030
trap ensure_file_permissions EXIT

synth.py

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,43 @@
2121
import synthtool.shell as shell
2222
import logging
2323
import os
24+
import pathlib
25+
import shutil
26+
import tempfile
2427

2528
logging.basicConfig(level=logging.DEBUG)
2629
s.metadata.set_track_obsolete_files(False) # TODO: enable again.
2730

28-
repository = os.getcwd()
29-
30-
image = "gcr.io/cloud-devrel-public-resources/elixir19"
31-
generate_command = "scripts/generate_client.sh"
32-
command = [
33-
"docker",
34-
"run",
35-
"--rm",
36-
f"-v{repository}:/workspace",
37-
"-v/var/run/docker.sock:/var/run/docker.sock",
38-
"-e", f"USER_GROUP={os.getuid()}:{os.getgid()}",
39-
"-w", "/workspace",
40-
image,
41-
generate_command]
42-
43-
if extra_args():
44-
command.extend(extra_args())
45-
46-
log.debug(f"Running: {' '.join(command)}")
47-
48-
shell.run(command, cwd=repository, hide_output=False)
31+
# Copy the repo into a temporary directory, removing the build and deps, and
32+
# perform generation there. This is because the docker command may be a
33+
# cross-compile whose build environment should be isolated from the current
34+
# git clone.
35+
with tempfile.TemporaryDirectory() as tmpdir:
36+
repository = pathlib.Path(tmpdir) / "repo"
37+
shutil.copytree(os.getcwd(), repository)
38+
shutil.rmtree(repository / "_build", ignore_errors=True)
39+
shutil.rmtree(repository / "deps", ignore_errors=True)
40+
41+
image = "gcr.io/cloud-devrel-public-resources/elixir19"
42+
generate_command = "scripts/generate_client.sh"
43+
command = [
44+
"docker",
45+
"run",
46+
"--rm",
47+
f"-v{repository}:/workspace",
48+
"-v/var/run/docker.sock:/var/run/docker.sock",
49+
"-e", f"USER_GROUP={os.getuid()}:{os.getgid()}",
50+
"-w", "/workspace",
51+
image,
52+
generate_command]
53+
54+
if extra_args():
55+
command.extend(extra_args())
56+
57+
log.debug(f"Running: {' '.join(command)}")
58+
59+
shell.run(command, cwd=repository, hide_output=False)
60+
61+
# Copy the resulting clients directory back into the git clone.
62+
shutil.rmtree("clients", ignore_errors=True)
63+
shutil.move(repository / "clients", "clients")

0 commit comments

Comments
 (0)