Skip to content

Commit

Permalink
Move the standard commands into a library file and update the instruc…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
ssorj committed Jan 13, 2024
1 parent 5176cc3 commit 96a7864
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 155 deletions.
13 changes: 6 additions & 7 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 19 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <project-dir>/
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:
Expand All @@ -33,48 +33,39 @@ 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

<!-- This sucks. GitHub Actions doesn't support workflow files as symlinks. -->
Copy the standard `.gitignore` and GitHub Actions workflow file into
your project:

<!-- Symlink the standard GitHub Actions workflow file: -->
cp external/skewer-main/config/.gitignore .gitignore

<!-- mkdir -p .github/workflows -->
<!-- ln -s ../../external/skewer-main/config/.github/workflows/main.yaml .github/workflows/main.yaml -->
mkdir -p .github/workflows
cp external/skewer-main/config/.github/workflows/main.yaml .github/workflows/main.yaml

<!-- So I have a convenience for copying the latest version into place. -->
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
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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
18 changes: 10 additions & 8 deletions config/.github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions config/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/README.html
__pycache__/
112 changes: 1 addition & 111 deletions config/.plano.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/5.1.0/github-markdown.min.css"
integrity="sha512-KUoB3bZ1XRBYj1QcH4BHCQjurAZnCO3WdrswyLDtp7BMwCw7dPZngSLqILf68SGgvnWHTD5pPaYrXi6wiRJ65g=="
crossorigin="anonymous" referrerpolicy="no-referrer"/>
<style>
.markdown-body {
box-sizing: border-box;
min-width: 200px;
max-width: 980px;
margin: 0 auto;
padding: 45px;
}
@media (max-width: 767px) {
.markdown-body {
padding: 15px;
}
}
</style>
</head>
<body>
<article class="markdown-body">
@content@
</article>
</body>
</html>
""".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 *
124 changes: 124 additions & 0 deletions python/skewer/planocommands.py
Original file line number Diff line number Diff line change
@@ -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 = """
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/5.5.0/github-markdown.min.css"
integrity="sha512-h/laqMqQKUXxFuu6aLAaSrXYwGYQ7qk4aYCQ+KJwHZMzAGaEoxMM6h8C+haeJTU1V6E9jrSUnjpEzX23OmV/Aw=="
crossorigin="anonymous" referrerpolicy="no-referrer"/>
<style>
.markdown-body {
box-sizing: border-box;
min-width: 200px;
max-width: 980px;
margin: 0 auto;
padding: 45px;
}
@media (max-width: 767px) {
.markdown-body {
padding: 15px;
}
}
</style>
</head>
<body>
<article class="markdown-body">
@content@
</article>
</body>
</html>
""".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")
1 change: 1 addition & 0 deletions test-example/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/README.html
__pycache__/
Loading

0 comments on commit 96a7864

Please sign in to comment.