-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat: implement a simple docker file to run cli commands #14111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| # Copyright 2025 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| FROM marketplace.gcr.io/google/ubuntu2404 AS builder | ||
|
|
||
| # TODO(https://github.com/googleapis/librarian/issues/901): Install the necssary dependencies and build tools. | ||
| RUN apt-get update && \ | ||
| apt-get install -y --no-install-recommends \ | ||
| # Essential for compiling C code | ||
| build-essential \ | ||
| # For downloading secure files | ||
| wget \ | ||
| ca-certificates \ | ||
| # --- Critical libraries for a complete Python build --- | ||
| libssl-dev \ | ||
| zlib1g-dev \ | ||
| libbz2-dev \ | ||
| libffi-dev \ | ||
| libsqlite3-dev \ | ||
| libreadline-dev \ | ||
| # ------------------------------------------------------ | ||
| && apt-get clean && \ | ||
| rm -rf /var/lib/apt/lists/* | ||
|
|
||
| # Set up environment variables for tool versions to make updates easier. | ||
| # TODO(): Downgrade to Python `3.11` if `3.13.5` is incompatible with googleapis. | ||
| ENV PYTHON_VERSION=3.13.5 | ||
|
|
||
| # Create a symbolic link for `python3` to point to our specific version. | ||
| ENV PATH /usr/local/bin/python3.13:$PATH | ||
|
|
||
| # Install Python from source | ||
| RUN wget https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz && \ | ||
| tar -xvf Python-${PYTHON_VERSION}.tgz && \ | ||
| cd Python-${PYTHON_VERSION} && \ | ||
| ./configure --enable-optimizations && \ | ||
| make altinstall && \ | ||
| cd / && \ | ||
| rm -rf Python-${PYTHON_VERSION}* | ||
|
|
||
| # TODO(https://github.com/googleapis/librarian/issues/904): Install protoc for gencode. | ||
|
|
||
| # TODO(https://github.com/googleapis/librarian/issues/903): Install Bazelisk for building a client library. | ||
|
|
||
| # TODO(https://github.com/googleapis/librarian/issues/902): Create a dedicate non-root user and | ||
| # switch to the non-root user to run subsequent commands. | ||
|
|
||
| # Set the working directory in the container. | ||
| WORKDIR /app | ||
|
|
||
| # TODO(https://github.com/googleapis/librarian/issues/907): Install Python dependencies from requirements.in. | ||
| # TODO(https://github.com/googleapis/librarian/issues/905): Install Synthtool by cloning its repo. | ||
| # TODO(https://github.com/googleapis/librarian/issues/906): Clone googleapis and run bazelisk build. | ||
|
|
||
| # Copy the CLI script into the container and set ownership. | ||
| # No other files or dependencies are needed for this simple script. | ||
| COPY cli.py . | ||
|
|
||
| # Set the entrypoint for the container to run the script. | ||
| ENTRYPOINT ["python3.13", "./cli.py"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # Copyright 2025 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import argparse | ||
| import sys | ||
|
|
||
| def handle_configure(dry_run=False): | ||
| # TODO(https://github.com/googleapis/librarian/issues/466): Implement configure command. | ||
| print("'configure' command executed.") | ||
|
|
||
| def handle_generate(dry_run=False): | ||
| # TODO(https://github.com/googleapis/librarian/issues/448): Implement generate command. | ||
| print("'generate' command executed.") | ||
|
|
||
| def handle_build(dry_run=False): | ||
| # TODO(https://github.com/googleapis/librarian/issues/450): Implement build command. | ||
| print("'build' command executed.") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| parser = argparse.ArgumentParser(description="A simple CLI tool.") | ||
| subparsers = parser.add_subparsers(dest="command", required=True, help="Available commands") | ||
|
|
||
| # Define commands | ||
| for command_name, help_text in [ | ||
| ("configure", "Onboard a new library or an api path to Librarian workflow."), | ||
| ("generate", "generate a python client for an API."), | ||
| ("build", "Run unit tests via nox for the generated library.") | ||
| ]: | ||
| handler_map = {"configure": handle_configure, "generate": handle_generate, "build": handle_build} | ||
| parser_cmd = subparsers.add_parser(command_name, help=help_text) | ||
| parser_cmd.set_defaults(func=handler_map[command_name]) | ||
|
|
||
| if len(sys.argv) == 1: | ||
| parser.print_help(sys.stderr) | ||
| sys.exit(1) | ||
|
|
||
| args = parser.parse_args() | ||
| args.func(args) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # Copyright 2025 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from cli import handle_generate, handle_build, handle_configure | ||
|
|
||
|
|
||
| def test_handle_configure_dry_run(): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will you also have tests with I could imagine that when |
||
| # This is a simple test to ensure that the dry run command succeeds. | ||
| handle_configure(dry_run=True) | ||
|
|
||
| def test_handle_generate_dry_run(): | ||
| # This is a simple test to ensure that the dry run command succeeds. | ||
| handle_generate(dry_run=True) | ||
|
|
||
| def test_handle_build_dry_run(): | ||
| # This is a simple test to ensure that the dry run command succeeds. | ||
| handle_build(dry_run=True) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| on: | ||
| pull_request: | ||
| branches: | ||
| - main | ||
| name: generator | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| test_generator_cli: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| # Use a fetch-depth of 2 | ||
| # See https://github.com/googleapis/google-cloud-python/issues/12013 | ||
| # and https://github.com/actions/checkout#checkout-head. | ||
| with: | ||
| fetch-depth: 2 | ||
| - name: Setup Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: "3.10" | ||
ohmayr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - name: Install pytest | ||
| run: | | ||
| python -m pip install pytest | ||
| - name: Run generator_cli tests | ||
| run: | | ||
| pytest .generator/test_cli.py | ||
Uh oh!
There was an error while loading. Please reload this page.