diff --git a/.gitignore b/.gitignore index 7a512f9fa..de9660172 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,5 @@ pbjs-genfiles/ .test-out-showcase .client_library *test-out* +docker/package.tgz +*.tgz diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 000000000..f3f1e8179 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,36 @@ +FROM node:12-alpine + +# Create folder structure +RUN mkdir -p /in +RUN mkdir -p /out +RUN mkdir -p /protos +RUN mkdir -p /root/files + +# Install the generator +COPY ./package.tgz /root/files/ +RUN npm install -g /root/files/package.tgz + +# Download and install protoc +RUN apk update && apk add libc6-compat && rm -f /var/cache/apk/* +ENV LD_LIBRARY_PATH /lib64:$LD_LIBRARY_PATH +RUN cd /root/files && \ + wget https://github.com/protocolbuffers/protobuf/releases/download/v3.10.0/protoc-3.10.0-linux-x86_64.zip +RUN cd /usr/local && unzip /root/files/protoc-3.10.0-linux-x86_64.zip + +# Download a copy of API common protos +RUN cd /root/files && \ + wget https://github.com/googleapis/api-common-protos/archive/master.zip +RUN cd /protos && unzip /root/files/master.zip && chmod -R a+rx /protos + +# Copy the start script +COPY ./start.sh /usr/local/bin/ +RUN chmod +x /usr/local/bin/start.sh + +# Delete downloaded files +RUN rm -rf /root/files + +# Print versions for debugging purposes +RUN gapic-generator-typescript --version +RUN protoc --version + +ENTRYPOINT [ "/usr/local/bin/start.sh" ] diff --git a/docker/build.sh b/docker/build.sh new file mode 100644 index 000000000..87de6e188 --- /dev/null +++ b/docker/build.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +### Prepare the package and run `docker build` + +SCRIPTDIR=`dirname "$0"` +cd "$SCRIPTDIR" +cd .. # now in the package.json directory +npm pack + +VERSION=`cat package.json | grep version | awk -F'"' '{ print $4; }'` + +cp "google-cloud-gapic-generator-$VERSION.tgz" "docker/package.tgz" +cd docker + +docker build -t gapic-generator-typescript . diff --git a/docker/start.sh b/docker/start.sh new file mode 100644 index 000000000..50b6bd6c4 --- /dev/null +++ b/docker/start.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +### Start script that is an entry point for a Docker image. + +# Change directory to the input directory. +# Make it easier to pass gRPC service config relative to it, e.g. +# --grpc-service-config google/cloud/texttospeech/v1/texttospeech_grpc_service_config.json + +cd /in +gapic-generator-typescript \ + --common-proto-path /protos/api-common-protos-master \ + -I /in \ + --output-dir /out \ + $* \ + `find /in -name '*.proto'` +exit 0 diff --git a/package.json b/package.json index 48ad6c6ec..d4784f895 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,6 @@ "c8": "^6.0.0", "codecov": "^3.6.1", "espower-typescript": "^9.0.0", - "google-gax": "^1.7.5", "gts": "^1.0.0", "intelli-espower-loader": "^1.0.1", "mocha": "^6.2.1", @@ -60,6 +59,7 @@ "file-system": "^2.2.2", "fs-extra": "^8.1.0", "get-stdin": "^7.0.0", + "google-gax": "^1.7.5", "nunjucks": "^3.1.3", "object-hash": "^2.0.0", "protobufjs": "^6.8.8", diff --git a/typescript/src/start_script.ts b/typescript/src/start_script.ts index c29a42474..80c6dccab 100755 --- a/typescript/src/start_script.ts +++ b/typescript/src/start_script.ts @@ -34,7 +34,11 @@ const argv = yargs .describe('output_dir', 'Path to a directory for the generated code') .alias('grpc-service-config', 'grpc_service_config') .describe('grpc-service-config', 'Path to gRPC service config JSON') - .usage(`Usage: $0 -I /path/to/googleapis \\ + .alias('common-proto-path', 'common_protos_path') + .describe( + 'common_proto_path', + 'Path to API common protos to use (if unset, will use protos shipped with google-gax)' + ).usage(`Usage: $0 -I /path/to/googleapis \\ --output_dir /path/to/output_directory \\ google/example/api/v1/api.proto`).argv; const outputDir = argv.outputDir as string; @@ -53,10 +57,12 @@ if (Array.isArray(argv._)) { protoFiles.push(argv._); } +const commonProtoPath = argv.commonProtoPath || GOOGLE_GAX_PROTOS_DIR; + // run protoc command to generate client library const cliPath = path.join(__dirname, 'cli.js'); const protocCommand = [ - `-I${GOOGLE_GAX_PROTOS_DIR}`, + `-I${commonProtoPath}`, `--plugin=protoc-gen-typescript_gapic=${cliPath}`, `--typescript_gapic_out=${outputDir}`, ];