diff --git a/.github/workflows/run-container-job.yaml b/.github/workflows/run-container-job.yaml new file mode 100644 index 0000000..8008d1d --- /dev/null +++ b/.github/workflows/run-container-job.yaml @@ -0,0 +1,30 @@ +name: Create Container App Job + +on: + workflow_dispatch: + inputs: + python_script: + description: 'The Python script to run' + required: true + default: 'print("Hello from GitHub Actions!")' + +jobs: + run-dynamic-script: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + + - name: Execute dynamic script + run: | + # Create a temporary file and write the input script into it + echo "${{ github.event.inputs.python_script }}" > dynamic_script.py + # Run the script + python3 dynamic_script.py + shell: bash diff --git a/cfa/cloudops/examples/create_container_app.py b/cfa/cloudops/examples/create_container_app.py new file mode 100644 index 0000000..d36942a --- /dev/null +++ b/cfa/cloudops/examples/create_container_app.py @@ -0,0 +1,20 @@ +import random +import string + +from cfa.cloudops import ContainerAppClient + +client = ContainerAppClient() +job_name = "my-job" +if not client.check_job_exists(job_name): + client.start_job( + job_name=job_name, + command=["python", "main.py"], + env=[{"name": "APP_MESSAGE", "value": "This is a container app job!"}], + ) + +characters = string.ascii_letters + string.digits +random_string = "".join(random.choices(characters, k=5)) + +if client.check_job_exists(job_name): + # Stop a job + client.stop_job(job_name=job_name, job_execution_name=f"{job_name}-{random_string}") diff --git a/cfa/cloudops/examples/main.py b/cfa/cloudops/examples/main.py new file mode 100644 index 0000000..21929f6 --- /dev/null +++ b/cfa/cloudops/examples/main.py @@ -0,0 +1,10 @@ +import os + + +def foo(): + message = os.getenv("APP_MESSAGE", "Hello from cfa-cloudops!") + return message + + +if __name__ == "__main__": + print(foo())