-
I drafted a gist at https://gist.github.com/blaisep/0b8ddf61dcbf6937a1a6c0c2c394c4d3 I know if might sound like "Automation for dummies" but I suspect many of us don't know how to structure our pipelines if we haven't done it before. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi @blaisep! Yes, pypyr is light (ahem, where light=non-existent) on too many practical hands-on step-by-step guides focused on a particular task. So your colophon (wow, fancy word!) is entirely correct. The Getting Started section does have a "write your 1st pipeline" sort of tutorial, and I like to think throughout each step's documentation page I generally try to pick examples that're hopefully useful/practical. . . but your point is very valid - there isn't a How To/Walkthrough section that aims to go in a more "step by step reference implementation" style examples. I am more than enthused adding some! I have actually considered this before, but in between writing the code, planning next features, dealing w tech debt (just upgraded from deprecated setuptools to flit for examples, which is not even something a casual end-user should notice) and writing the explanation/reference docs I haven't had that much time. So if you're volunteering. . . welcome aboard 😁 Couple of notes on your gist:
- name: pypyr.steps.cmd
description: --> installing just published release from pypi for smoke-test
retry:
max: 5
sleep: 10
in:
cmd: pip install --upgrade --no-cache-dir {package_name}=={expected_version} In this example, pypyr will retry the pip install command to install the specific version up to 5 times, with 10 seconds sleep in between. Once the pip command returns status code 0, pypyr automatically continues to the next step. I use this when publishing new packages to the pip, because sometimes pip takes a couple of minutes before the newly uploaded version is available for download. So if you can craft a command that checks the state of the VM and returns a 0 when you're ready to continue, you can follow the same pattern.
There are various ways you can go about achieving idempotency. . . Like you describe, yes, you can generate some sort of unique name on each invocation. Instead, I have a suspicion you might be better served by using a known name - let's say "api-server", and then making it so that only your pipelines are supposed to use that name. Then make sure as part of your pipeline that you: So putting that all together: steps:
- name: pypyr.steps.call
in:
call: start-services
- name: pypyr.steps.echo
in:
echoMe: do your work here and in subsequent steps once services started
- name: pypyr.steps.call
comment: stop the services when done. could also put this in `on_success` group.
in:
call: stop-services
start-services:
- name: pypyr.steps.cmd
comment: this cmd should return 0 if podman api-server already running
swallow: True
in:
cmd: echo some sort of cmd to check if api-server is running
- name: pypyr.steps.call
comment: if previous step errored, means podman already running.
so stop it first, so we can start clean.
run: !py "'runErrors' in locals()"
in:
call: stop-services
# if stop is asynchronous/detached, you might have to have another retry-style
# step here to wait for it to stop completely.
- name: pypyr.steps.cmd
comment: now we know api-server is deffo NOT running. so can just start it here.
in:
cmd: echo start your api-server
- name: pypyr.steps.cmd
comment: this will retry max 5 times w 10s sleep in between to wait for api-server to start
if api-server does not start in this time, will raise error and stop here.
retry:
max: 5
sleep: 10
in:
cmd: echo some sort of cmd that returns 0 when api-server started and ready
stop-services:
- name: pypyr.steps.cmd
in:
cmd: echo stop services here podman api-server stop etc.
# this is the global err handler. this on_failure group will run if any unhandled
# (i.e un-swallowed) error in the pipeline happens.
on_failure:
- name: pypyr.steps.call
comment: try to stop the services. this is best effort, so if this fails
just swallow, not much more we can do.
swallow: True
in:
call: stop-services Here I've made the assumption that you want to start w a fresh new VM each time. You could alter the above so if it's already running it'll just use the running instance instead of stopping it and restarting it 1st, depending on exactly what you want to achieve. [edit:] P.S throughout I just used [edit:] P.S you don't "have" to use |
Beta Was this translation helpful? Give feedback.
-
@yaythomas , I suppose this could become a tutorial in response to https://pythonspeed.com/articles/shell-scripts/ |
Beta Was this translation helpful? Give feedback.
Hi @blaisep!
Yes, pypyr is light (ahem, where light=non-existent) on too many practical hands-on step-by-step guides focused on a particular task. So your colophon (wow, fancy word!) is entirely correct.
The Getting Started section does have a "write your 1st pipeline" sort of tutorial, and I like to think throughout each step's documentation page I generally try to pick examples that're hopefully useful/practical. . . but your point is very valid - there isn't a How To/Walkthrough section that aims to go in a more "step by step reference implementation" style examples.
I am more than enthused adding some! I have actually considered this before, but in between writing the code, planning n…