Skip to content

Commit

Permalink
feat: docker interface (#77)
Browse files Browse the repository at this point in the history
* feat: docker interface

* gts fix
  • Loading branch information
alexander-fenster committed Oct 28, 2019
1 parent 3ecdf4c commit 193a899
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ pbjs-genfiles/
.test-out-showcase
.client_library
*test-out*
docker/package.tgz
*.tgz
36 changes: 36 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
15 changes: 15 additions & 0 deletions docker/build.sh
Original file line number Diff line number Diff line change
@@ -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 .
16 changes: 16 additions & 0 deletions docker/start.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
10 changes: 8 additions & 2 deletions typescript/src/start_script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}`,
];
Expand Down

0 comments on commit 193a899

Please sign in to comment.