Skip to content

Commit c76b742

Browse files
authored
Use docker in synth script (googleapis#123)
1 parent af847d1 commit c76b742

3 files changed

Lines changed: 53 additions & 10 deletions

File tree

lib/google_apis/generator/swagger_cli.ex

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,22 @@ defmodule GoogleApis.Generator.SwaggerCli do
3939

4040
defp generate_code(filename, client_library_name) do
4141
tmp_dir = temp_path(client_library_name, Application.get_env(:google_apis, :tempdir))
42+
File.mkdir_p!(tmp_dir)
4243

4344
with {:ok, volume_name} <- run_docker_command("volume create"),
4445
{:ok, _} <- run_docker_command("pull #{image()}"),
4546
{:ok, container} <-
4647
run_docker_command("container create -v #{volume_name}:/data #{image()}"),
4748
{:ok, _} <- run_docker_command("cp . #{container}:/data"),
48-
{:ok, _} <- run_docker_command("rm #{container}"),
4949
generate_command =
50-
"run --rm -v #{volume_name}:/local -v #{tmp_dir}:/tmp/out #{image()} generate -l elixir -i /local/specifications/openapi/#{
50+
"run --rm -v #{volume_name}:/local #{image()} generate -l elixir -i /local/specifications/openapi/#{
5151
filename
52-
} -c /local/specifications/config/#{filename} -t #{template_dir()} -o /tmp/out/#{
52+
} -c /local/specifications/config/#{filename} -t #{template_dir()} -o /local/#{
5353
client_library_name
5454
}",
55-
{:ok, _} <- run_docker_command(generate_command) do
55+
{:ok, _} <- run_docker_command(generate_command),
56+
{:ok, _} <- run_docker_command("cp #{container}:/data/#{client_library_name} #{tmp_dir}"),
57+
{:ok, _} <- run_docker_command("rm #{container}") do
5658
{:ok, tmp_dir}
5759
else
5860
err -> err

scripts/generate_client.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2018 Google Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -eo pipefail
17+
18+
pushd $(dirname "$0")/../
19+
20+
export TEMPLATE=gax
21+
22+
# clean the codegen directory
23+
# if [ -d .codegen ]; then
24+
# rm -rf .codegen
25+
# fi
26+
# mkdir -p .codegen
27+
# export TEMPDIR=$(pwd)/.codegen
28+
29+
# install npm dependencies
30+
npm install
31+
32+
# install dependencies
33+
mix deps.get
34+
35+
# run generators
36+
mix google_apis.generate $1

synth.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,25 @@
2020
import synthtool.shell as shell
2121
import synthtool.sources.git as git
2222
import logging
23+
import sys
2324

2425
logging.basicConfig(level=logging.DEBUG)
2526

26-
repository_url = "https://github.com/GoogleCloudPlatform/elixir-google-api.git"
27+
repository_url = "https://github.com/googleapis/elixir-google-api.git"
2728

2829
log.debug(f"Cloning {repository_url}.")
2930
repository = git.clone(repository_url, depth=1)
3031

31-
log.debug("Installing dependencies.")
32-
shell.run("mix deps.get".split(), cwd=repository)
33-
shell.run("npm install".split(), cwd=repository)
32+
image = "gcr.io/cloud-devrel-kokoro-resources/elixir16"
33+
generate_command = "scripts/generate_client.sh"
34+
command = f"docker run --rm -v{repository}:/workspace -v/var/run/docker.sock:/var/run/docker.sock -w /workspace {image} {generate_command}"
3435

35-
log.debug("Generating all libraries.")
36-
shell.run("mix google_apis.generate".split(), cwd=repository)
36+
if len(sys.argv) == 2:
37+
command = command + " " + sys.argv[1]
38+
39+
log.debug(f"Running in docker: {command}")
40+
41+
shell.run(command.split(), cwd=repository)
3742

3843
# copy all clients
3944
s.copy(repository / "clients")

0 commit comments

Comments
 (0)