Skip to content

Connect code repository

o‑o works with Git repositories, transparently copying code before run execution, so you can easily run commands with your own source code.

Example Python code

To demonstrate using o‑o with a Git repository, create the following simple Python source file, print.py

print.py
import sys

print(sys.argv[1])

Then initialize a new Git repository, add print.py, and commit

$ git init ./
$ git add print.py
$ git commit --message "Add print.py"

Now configure o‑o to use the source code in this repository by adding sourcecode: true to our .ooconfig file. Since this is Python code, we also add a new environment (my-python-env) with Python installed:

.ooconfig
project: test-project
sourcecode: true
environments:
  - name: my-simple-env
    provider: Scaleway
    image: docker.io/debian:stable-slim
    machinetype: STARDUST1-S
    region: fr-par-1
    default: true
  - name: my-python-env
    provider: Scaleway
    image: docker.io/python:3-slim
    machinetype: STARDUST1-S
    region: fr-par-1
datastores:
  - name: my-datastore
    provider: Scaleway
    bucket: o-o-data
    region: fr-par
    default: true
.ooconfig
project: test-project
sourcecode: true
environments:
  - name: my-simple-env
    provider: gcp
    image: docker.io/debian:stable-slim
    machinetype: e2-highcpu-2
    region: northamerica-northeast1-b
    default: true
  - name: my-python-env
    provider: gcp
    image: docker.io/python:3-slim
    machinetype: e2-highcpu-2
    region: northamerica-northeast1-b
datastores:
  - name: my-datastore
    provider: gcp
    bucket: o-o-data
    default: true

Now run the checked in code with the new Python environment:

$ o-o run --environment my-python-env --message "first example" -- \
    python print.py Hello! 
Hello!

o‑o copied the current commit to our Python environment and ran the given command. Nice! Let's go a bit further and make changes to our source code

print.py
import sys

message = sys.argv[1]
print(f"Message: {message}")

We can now re-run the script with our new changes. You can commit your changes, but it isn't necessary at this stage. As a convenience, add the --dirty flag and your uncommitted working tree changes are copied to the environment.

$ o-o run --dirty --environment my-python-env --message "second example" -- \
    python print.py Hello!
Message: Hello!

Show code changes

By connecting a repository to your o‑o runs, the source used for the run is versioned and stored in your configured datastore. The o-o diff command will show differences in the code between runs. For example, if we take the two runs from above

$ o-o run --list
hse6u3mhgf first example
fzp965ukoi second example

We can see the code changes that occurred between these runs

$ o-o diff hse6u3mhgf fzp965ukoi
--- hse6u3mhgf/print.py                                                                                                                 
+++ fzp965ukoi/print.py                                                                                                                 
@@ -1,3 +1,4 @@                                                                                                                         
 import sys                                                                                                                             

-print(sys.argv[1])                                                                                                                     
+message = sys.argv[1]                                                                                                                  
+print(f"Message: {message}")