From 96a78647ce70c90028dc4e2754e16fa04b453b2d Mon Sep 17 00:00:00 2001 From: Justin Ross Date: Sat, 13 Jan 2024 07:14:08 -0500 Subject: [PATCH] Move the standard commands into a library file and update the instructions --- .github/workflows/main.yaml | 13 ++- README.md | 46 +++++------ config/.github/workflows/main.yaml | 18 +++-- config/.gitignore | 2 + config/.plano.py | 112 +------------------------- python/skewer/planocommands.py | 124 +++++++++++++++++++++++++++++ test-example/.gitignore | 1 + test-example/.plano.py | 2 +- test-example/plano | 2 +- 9 files changed, 165 insertions(+), 155 deletions(-) create mode 100644 config/.gitignore create mode 100644 python/skewer/planocommands.py diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index e581bed..5394b32 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -5,19 +5,18 @@ on: schedule: - cron: "0 0 * * 0" jobs: - test: + main: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: python-version: "3.x" - - uses: manusa/actions-setup-minikube@v2.7.2 + - uses: manusa/actions-setup-minikube@v2.10.0 with: - minikube version: "v1.28.0" - kubernetes version: "v1.25.4" + minikube version: "v1.32.0" + kubernetes version: "v1.29.0" github token: ${{secrets.GITHUB_TOKEN}} - - run: pip install pyyaml - run: curl https://skupper.io/install.sh | sh - run: echo "$HOME/.local/bin" >> $GITHUB_PATH - run: ./plano test diff --git a/README.md b/README.md index 7cc66a8..312d8e0 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ use the [Skupper example template][template] as a starting point. Add the Skewer code as a subdirectory in your example project: cd / - mkdir external + mkdir -p external curl -sfL https://github.com/skupperproject/skewer/archive/main.tar.gz | tar -C external -xz Symlink the Skewer library into your `python` directory: @@ -33,19 +33,23 @@ Symlink the Skewer library into your `python` directory: ln -s ../external/skewer-main/python/skewer python/skewer Symlink the `plano` command into the root of your project. Symlink -the standard `config/.plano.py` as `.plano.py` in the root as well: +the standard `.plano.py` and `.gitignore` files as well. ln -s external/skewer-main/plano ln -s external/skewer-main/config/.plano.py - +Copy the standard `.gitignore` and GitHub Actions workflow file into +your project: - + cp external/skewer-main/config/.gitignore .gitignore - - + mkdir -p .github/workflows + cp external/skewer-main/config/.github/workflows/main.yaml .github/workflows/main.yaml - +Use your editor to create a `skewer.yaml` file in the root of your +project: + + emacs skewer.yaml To use the `./plano` command, you must have the Python `pyyaml` package installed. Use `pip` (or `pip3` on some systems) to install @@ -53,28 +57,15 @@ it: pip install pyyaml -Use the `plano update-workflow` command to copy the latest GitHub -Actions workflow file into your project: - - ./plano update-workflow - -Use your editor to create a `skewer.yaml` file in the root of your -project: - - emacs skewer.yaml - Run the `./plano` command to see the available commands: ~~~ console $ ./plano -usage: plano [--verbose] [--quiet] [--debug] [-h] [-f FILE] [-m MODULE] {command} ... +usage: plano [-h] [-f FILE] [-m MODULE] {command} ... Run commands defined as Python functions options: - --verbose Print detailed logging to the console - --quiet Print no logging to the console - --debug Print debugging output to the console -h, --help Show this help message and exit -f FILE, --file FILE Load commands from FILE (default '.plano.py') -m MODULE, --module MODULE @@ -89,8 +80,7 @@ commands: run-external Run the example steps with user-provided kubeconfigs demo Run the example steps and pause before cleaning up test Test README generation and run the steps on Minikube - update-workflow Update the GitHub Actions workflow file - update-skewer Update the embedded Skewer repo + update-skewer Update the embedded Skewer repo and GitHub workflow ~~~ ## Skewer YAML @@ -243,10 +233,12 @@ for a condition you require before going to the next step. They are used only for testing and do not impact the README. ~~~ yaml -- await_resource: # A resource (as in, deployment/frontend) for which to await readiness (optional) -- await_external_ip: # A service (as in, service/frontend) for which to await an external IP (optional) -- await_http_ok: # A service and URL template (as in, service/frontend and "http://{}:8080/api/hello") - # for which to await an HTTP OK response (optional) +- await_resource: # A resource for which to await readiness (optional) + # Example: await_resource: deployment/frontend +- await_external_ip: # A service for which to await an external IP (optional) + # Example: await_service: service/frontend +- await_http_ok: # A service and URL template for which to await an HTTP OK response (optional) + # Example: await_http_ok: [service/frontend, "http://{}:8080/api/hello"] ~~~ Example commands: diff --git a/config/.github/workflows/main.yaml b/config/.github/workflows/main.yaml index 3266cb2..eb4adeb 100644 --- a/config/.github/workflows/main.yaml +++ b/config/.github/workflows/main.yaml @@ -24,18 +24,20 @@ on: schedule: - cron: "0 0 * * 0" jobs: - test: + main: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: python-version: "3.x" - - uses: manusa/actions-setup-minikube@v2.7.2 + - uses: manusa/actions-setup-minikube@v2.10.0 with: - minikube version: "v1.28.0" - kubernetes version: "v1.25.4" + minikube version: "v1.32.0" + kubernetes version: "v1.29.0" github token: ${{secrets.GITHUB_TOKEN}} - run: curl https://skupper.io/install.sh | sh - - run: echo "$HOME/.local/bin" >> $GITHUB_PATH - - run: ./plano test --debug + - run: echo "$HOME/.local/bin" >> "$GITHUB_PATH" + - run: ./plano test + env: + PLANO_COLOR: 1 diff --git a/config/.gitignore b/config/.gitignore new file mode 100644 index 0000000..500983c --- /dev/null +++ b/config/.gitignore @@ -0,0 +1,2 @@ +/README.html +__pycache__/ diff --git a/config/.plano.py b/config/.plano.py index 864f076..4609d49 100644 --- a/config/.plano.py +++ b/config/.plano.py @@ -17,114 +17,4 @@ # under the License. # -from skewer import * - -@command -def generate(): - """ - Generate README.md from the data in skewer.yaml - """ - generate_readme("skewer.yaml", "README.md") - -render_template = """ - - - - - - -
- -@content@ - -
- - -""".strip() - -@command -def render(): - """ - Render README.html from the data in skewer.yaml - """ - generate() - - markdown = read("README.md") - data = {"text": markdown} - json = emit_json(data) - content = http_post("https://api.github.com/markdown", json, content_type="application/json") - html = render_template.replace("@content@", content) - - write("README.html", html) - - print(f"file:{get_real_path('README.html')}") - -@command -def clean(): - remove(find(".", "__pycache__")) - remove("README.html") - -@command -def run_(debug=False): - """ - Run the example steps using Minikube - """ - run_steps_minikube("skewer.yaml", debug=debug) - -@command -def run_external(*kubeconfigs, debug=False): - """ - Run the example steps with user-provided kubeconfigs - """ - run_steps("skewer.yaml", kubeconfigs, debug=debug) - -@command -def demo(debug=False): - """ - Run the example steps and pause before cleaning up - """ - with working_env(SKEWER_DEMO=1): - run_steps_minikube("skewer.yaml", debug=debug) - -@command -def test_(debug=False): - """ - Test README generation and run the steps on Minikube - """ - generate_readme("skewer.yaml", make_temp_file()) - run_steps_minikube("skewer.yaml", debug=debug) - -@command -def update_workflow(): - """ - Update the GitHub Actions workflow file - """ - copy("external/skewer-main/config/.github/workflows/main.yaml", ".github/workflows/main.yaml") - -@command -def update_skewer(): - """ - Update the embedded Skewer repo - """ - check_program("curl") - - make_dir("external") - remove("external/skewer-main") - - run("curl -sfL https://github.com/skupperproject/skewer/archive/main.tar.gz | tar -C external -xz", shell=True) +from skewer.planocommands import * diff --git a/python/skewer/planocommands.py b/python/skewer/planocommands.py new file mode 100644 index 0000000..2144e38 --- /dev/null +++ b/python/skewer/planocommands.py @@ -0,0 +1,124 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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 skewer import * + +@command +def generate(): + """ + Generate README.md from the data in skewer.yaml + """ + generate_readme("skewer.yaml", "README.md") + +render_template = """ + + + + + + +
+ +@content@ + +
+ + +""".strip() + +@command +def render(verbose=False, quiet=False): + """ + Render README.html from the data in skewer.yaml + """ + generate() + + markdown = read("README.md") + data = {"text": markdown} + json = emit_json(data) + content = http_post("https://api.github.com/markdown", json, content_type="application/json") + html = render_template.replace("@content@", content) + + write("README.html", html) + + if not quiet: + print(f"file:{get_real_path('README.html')}") + +@command +def clean(): + remove(find(".", "__pycache__")) + remove("README.html") + +@command +def run_(debug=False): + """ + Run the example steps using Minikube + """ + run_steps_minikube("skewer.yaml", debug=debug) + +@command +def run_external(*kubeconfigs, debug=False): + """ + Run the example steps with user-provided kubeconfigs + """ + run_steps("skewer.yaml", kubeconfigs, debug=debug) + +@command +def demo(debug=False): + """ + Run the example steps and pause before cleaning up + """ + with working_env(SKEWER_DEMO=1): + run_steps_minikube("skewer.yaml", debug=debug) + +@command +def test_(debug=False): + """ + Test README generation and run the steps on Minikube + """ + generate_readme("skewer.yaml", make_temp_file()) + run_steps_minikube("skewer.yaml", debug=debug) + +@command +def update_skewer(): + """ + Update the embedded Skewer repo and GitHub workflow + """ + check_program("curl") + + make_dir("external") + remove("external/skewer-main") + run("curl -sfL https://github.com/skupperproject/skewer/archive/main.tar.gz | tar -C external -xz", shell=True) + copy("external/skewer-main/config/.github/workflows/main.yaml", ".github/workflows/main.yaml") diff --git a/test-example/.gitignore b/test-example/.gitignore index 7bd2dc8..500983c 100644 --- a/test-example/.gitignore +++ b/test-example/.gitignore @@ -1 +1,2 @@ /README.html +__pycache__/ diff --git a/test-example/.plano.py b/test-example/.plano.py index 6b89765..a667613 120000 --- a/test-example/.plano.py +++ b/test-example/.plano.py @@ -1 +1 @@ -external/skewer-main/config/.plano.py \ No newline at end of file +../config/.plano.py \ No newline at end of file diff --git a/test-example/plano b/test-example/plano index c04aa5c..22171ee 120000 --- a/test-example/plano +++ b/test-example/plano @@ -1 +1 @@ -external/skewer-main/plano \ No newline at end of file +../plano \ No newline at end of file