{"id":13501311,"url":"https://github.com/pulp/oci_env","last_synced_at":"2025-03-29T08:32:19.684Z","repository":{"id":41260309,"uuid":"508912732","full_name":"pulp/oci_env","owner":"pulp","description":null,"archived":false,"fork":false,"pushed_at":"2025-03-28T17:50:32.000Z","size":298,"stargazers_count":10,"open_issues_count":23,"forks_count":35,"subscribers_count":12,"default_branch":"main","last_synced_at":"2025-03-28T18:47:22.298Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pulp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-06-30T02:53:56.000Z","updated_at":"2025-03-28T17:50:36.000Z","dependencies_parsed_at":"2024-01-15T13:04:38.825Z","dependency_job_id":"e674eab5-e6c9-44af-be94-0985d1b9e754","html_url":"https://github.com/pulp/oci_env","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pulp%2Foci_env","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pulp%2Foci_env/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pulp%2Foci_env/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pulp%2Foci_env/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pulp","download_url":"https://codeload.github.com/pulp/oci_env/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246162092,"owners_count":20733351,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T22:01:32.719Z","updated_at":"2025-03-29T08:32:18.659Z","avatar_url":"https://github.com/pulp.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# OCI Env\n\nA developer environment for pulp based off of the [Pulp OCI Images](https://github.com/pulp/pulp-oci-images)\n\n## Getting started\n\n0. Install the `oci-env` python client.\n\n  ```bash\n  cd oci_env\n\n  # if pip3 isn't available, try pip. Python 3 is required for oci-env.\n  pip3 install -e client\n  ```\n\n1. Install podman or docker compose\n\n    - [docker-compose installation docs](https://docs.docker.com/compose/install/). \n    - [podman-compose installation docs](https://github.com/containers/podman-compose#installation).\n\n2. Set up your directory with the following structure:\n\n    ```\n    .\n    ├── oci_env\n    ├── pulp-openapi-generator\n    ├── pulp_ansible\n    ├── pulp_container\n    ├── pulpcore\n    └── any_other_python_sources\n    ```\n\n    The OCI env project should be in the same directory as any pulp plugins you wish to run.\n\n    Note, the `/src/` folder in the container is the parent folder containing the `oci_env` and all\n    plugin checkouts on the container host.\n\n3. Define your `compose.env` file.\n\n    `cp compose.env.example compose.env`\n\n    A minimal `compose.env` will look something like this:\n\n    ```\n    DEV_SOURCE_PATH=pulpcore:pulp_ansible\n\n    # this is set to podman by default.\n    COMPOSE_BINARY=docker\n    ```\n\n    In this example, `../pulpcore` and `../pulp_ansible` will be installed from source. Other settings\n    include:\n\n    - `COMPOSE_PROFILE`: this is used to define environments with extra services running. This could be\n      used to launch a UI, set up an authentication provider service or configure an object store.\n      Example `COMPOSE_PROFILE=ha:galaxy_ng/ui`. This will use the the `ha` profile from `oci_env/profiles/`\n      and the `ui` profile from `galaxy_ng/profiles/`\n    - `PULP_\u003cSETTING_NAME\u003e`: set any setting.py value for your environment. Example: `PULP_GALAXY_REQUIRE_CONTENT_APPROVAL=False`\n\n4. Run the environment\n\n    ```bash\n    # build the images\n    oci-env compose build\n\n    # start the service\n    oci-env compose up \n    ```\n\n    The `oci-env compose` command accepts all the same arguments as `podman-compose` or `docker-compose`\n\n    By default the API will be served from http://localhost:5001/pulp/api/v3/. You can login with `admin`/`password` by default.\n    E.g.: `http --auth admin:password get http://localhost:5001/pulp/api/v3/status/`\n    The api will reload anytime changes are made to any of the `DEV_SOURCE_PATH` projects.\n\n    `oci-env compose` accepts all of the arguments that docker and podman compose take. You can also launch the environment in the background with `oci-env compose up -d` and access the logs with `oci-env compose logs -f` if you don't want to run it in the foreground.  \n    \\\n    In case you have problems with setup in macOS, check these [troubleshooting tips](/docs/macos_troubleshooting_tips.md). \n\n5. Teardown\n\n    To shut down the containers run `oci-env compose down`. Data in your system will be preserved when you restart the containers.\n\n    To delete the database run `oci-env compose down --volumes`. This will shut down the containers and delete all the container data in your system.\n\n## The oci-env CLI\n\nThis CLI has all the functionality required to run the OCI Env developer environment. See `oci-env --help` for a list of supported commands.\n\n`oci-env` can either be run in the `oci_env/` root dir, or it can be executed from anywhere by setting the `OCI_ENV_PATH` environment variable.\nThe path supplied to `OCI_ENV_PATH` is expected to be the `oci_env/` project root dir.\n\n## Resetting the DB\n\nThe DB can be reset and migrations rerun with the `oci-env db reset` command. Alternatively, you could run the following:\n\n```bash\noci-env compose down --volumes  # Shut down the containers and delete all the container data on your system\noci-env compose up\n```\n\n## Multiple environments\n\noci-env supports running multiple environments simultaneously. To do this, simply create a new .env file such as:\n\n```\n# custom.env\n\nCOMPOSE_PROFILE=my_profiles\nDEV_SOURCE_PATH=pulpcore\n\n# These three values must be different from the api port, docs port and project name for any other\n# instances of the environment that are running to avoid conflicts.\nAPI_PORT=4002\nCOMPOSE_PROJECT_NAME=test\n\n# If you want to use a different directory for your git checkouts you can set this\n# SRC_DIR=/path/to/my/git/checkouts\n```\n\nOnce the file is defined run `oci-env -e custom.env compose up` to launch the new environment. The path to custom.env can be an absolute path or relative to your PWD. If you have `OCI_ENV_PATH` defined you can create a directory for your custom definitions and run oci-env from there without having to specify an absolute path.\n\nExample:\n\n```\n~\n├── oci_env\n└── oci_env_configs\n    ├── custom.env\n    └── test.env\n```\n\n```bash\nexport OCI_ENV_PATH=\"~/oci_env\"\n\ncd oci_env_configs\noci-env -e custom.env compose up\n```\n\n## Running Tests\n\n### Lint\n\n```bash\n# Install the lint requirements and run the linter for a specific plugin\n\noci-env test -i -p PLUGIN_NAME lint\n\n# Run the linter without installing lint dependencies.\noci-env test -p PLUGIN_NAME lint\n```\n\n### Functional\n\nBefore functional tests can be run, you must clone github.com/pulp/pulp-openapi-generator into the parent directory.\n\nEx:\n\n```\n.\n├── (...)\n├── oci_env\n└── pulp-openapi-generator\n```\n\n```bash\n# Generate the pulp client. This will build clients for all plugins in DEV_SOURCE_PATH. -i will also install the client in the container.\noci-env generate-client -i\n\n# Install the functional test requirements and run the tests\noci-env test -i -p PLUGIN_NAME functional\n\n# Run the tests without installing dependencies.\noci-env test -p PLUGIN_NAME functional\n```\n\nBindings for specific plugins can be regenerated with `oci-env generate-client PLUGIN_NAME`.\n\nUse `--language` parameter to specify the programming language the bindings should be generated for (default: python),\ne.g. `oci-env generate-client -l ruby PLUGIN_NAME`.\n\n#### Debugging functional tests\n\n1. Add \"epdb\" to the functest_requirements.txt file in your pulp_ansible checkout path.\n2. Inside any functional test, add `import epdb; epdb.st()`.\n3. Re-run `oci-env test -i functional` and `oci-env test -p pulp_ansible functional --capture=no` commands again.\n\n#### Using PyCharm remote debug server\n\n1. Start the debugger server in PyCharm. When using `podman`, the hostname should be set to\n   `host.containers.internal` hostname. `Docker` users should use `host.docker.internal` hostname. \n2. Add a break point to your Pythong code:\n```\nimport pydevd_pycharm\npydevd_pycharm.settrace('host.containers.internal', port=3013, stdoutToServer=True, stderrToServer=True)`\n```\n3. Restart all services you need to pick up the code change by running `s6-svc -r /var/run/service/\u003cservice_name\u003e`\n4. Perform the action that should trigger the code to run.\n\nPlease note that `host.containers.internal` points to the wrong interface in `podman` \u003c 4.1. When\nusing `podman` \u003c 4.1, you need modify `/etc/hosts` inside the container running Pulp with the IP\naddress for the publicly facing network interface on the host.\n\n\n#### Building docs\n\nInstall the docs building utility from https://github.com/pulp/pulp-docs.\n\nThen, run `make docs` and `make servedocs`. You can install the utility and run these commands outside of oci-env.\n\nThe docs are served on the URL logged by the `make servedocs` step.\n\n### Unit\n\n```bash\n# Install the unit test dependencies for a plugin and run it.\noci-env test -i -p PLUGIN_NAME unit\n\n# Run the unit tests for a plugin without installing test dependencies.\noci-env test -p PLUGIN_NAME unit\n```\n\n## Profiles\n\n### Custom Profiles\n\nYou can create custom profiles for your instance of oci_env by creating adding _local to the end of the profile name. These profiles will be ignored by git. Example `oci_env/profiles/my_custom_profile_local/`.\n\n### Writing New Profiles\n\nOCI env has a pluggable profile system. Profiles can be defined in `oci_env/profiles/` or\nin any pulp plugin at `\u003cPLUGIN_NAME\u003e/profiles/`.\n\nTo generate a new profile template run:\n\n```bash\n# Generate a new profile in oci_env\noci-env profile init my_profile\n\n# Generate a new profile in a plugin repo\noci-env profile init -p PLUGIN_NAME my_profile\n\n# List available profiles\noci-env profile ls\n\n# Display the README.md for a profile\noci-env profile docs my_profile\n```\n\nEach profile goes in it's own directory and can include:\n\n- `compose.yaml`: This is a docker compose file that can define new services or modify the base `pulp` service.\n- `pulp_config.env`: Environment file that defines any settings that the profile needs to run.\n- `init.sh`: Script that gets run when the environment loads. Can be used to initialize data and set up tests. Must be a bash script.\n- `profile_reqirements.txt`: A list of other profiles that are required to be set in COMPOSE_PROFILE for this profile to function.\n- `profile_default_config.env`: A list of default variables to use if not specified by the user.\n- `README.md`: Readme file describing what the profile is for and how to use it.\n\n#### Variables\n\nThese variables can be used in `pulp_config.env` and `compose.yaml`:\n\n- `API_HOST`: hostname where pulp expects to run (default: localhost).\n- `API_PORT`: port that pulp expects to run on. This port will also get exposed on the pulp container (default: 5001).\n- `API_PROTOCOL`: can be http or https (default: http).\n- `NGINX_SSL_PORT`: the port on which Nginx listens to https traffic (default: 443). `API_PROTOCOL` needs to be `https`.\n- `NGINX_PORT`: the port on which Nginx listens to http traffic. Note: the functional tests won't work correctly if this is different from API_PORT. (default: 5001, or the value of `API_PORT`).\n- `DEV_SOURCE_PATH`: colon separated list of python dependencies to include from source.\n- `COMPOSE_PROFILE`: colon separated list of profiles.\n- `DJANGO_SUPERUSER_USERNAME`: username for the super user (default: admin).\n- `DJANGO_SUPERUSER_PASSWORD`: password for the super user (default: password).\n- `COMPOSE_PROJECT_NAME`: the project name passed to podman-compose. Use this when running multiple environments to keep containers and volumes separate (default: oci_env).\n- `SRC_DIR`: path to load source code from. Set this if you want to use a different set of git checkouts with your environment (default: oci_env/../)\n\nVariables are templated using pythons `\"{VAR}\".template(VAR=\"my_var\")` function, so they must be referenced as `{VARIABLE_NAME}` in environment and compose files.\n\nProfiles can use variables outside of this list as well. They are just required to be defined in the user's compose.env file or in the profile's (or its parents) `profile_default_config.env` file.\n\nExample pulp_config.env:\n\n```\nPULP_ANSIBLE_API_HOSTNAME=\"{API_PROTOCOL}://{API_HOST}:{API_PORT}\"\nPULP_ANSIBLE_CONTENT_HOSTNAME=\"{API_PROTOCOL}://{API_HOST}:{API_PORT}/pulp/content\"\n```\n\n#### Example\n\nProfile structure in the galaxy_ng plugin\n\n```\ngalaxy_ng/profiles/\n└── ui\n    ├── compose.yaml\n    └── pulp_config.env\n```\n\ncompose.yaml: This defines a UI service that builds the container found at `ANSIBLE_HUB_UI_PATH` and configures the UI to proxy requests to the pulp API server.\n\n```yaml\nversion: \"3.7\"\n\nservices:\n  ui:\n    build:\n      context: \"{ANSIBLE_HUB_UI_PATH}\"\n    ports:\n      - \"8002:8002\"\n    volumes:\n      - \"{ANSIBLE_HUB_UI_PATH}:/hub/app/\"\n    tmpfs:\n      # Forces npm to ignore the node_modules in the volume and look\n      # for it in ../node_modules instead, while still being able to write .cache\n      - \"/hub/app/node_modules\"\n    depends_on:\n      - pulp\n    environment:\n      - \"API_PROXY_HOST=pulp\"\n      - \"API_PROXY_PORT=80\"\n      - \"DEPLOYMENT_MODE=standalone\"\n```\n\npulp_config.env: The UI expects the galaxy apis to be served from `/api/automation-hub/` and for the app to be launched in standalone mode. The environment file provided with the profile ensures that the API is configured correctly to consume the new service.\n\n```\nPULP_CONTENT_PATH_PREFIX=/api/automation-hub/v3/artifacts/collections/\n\nPULP_GALAXY_API_PATH_PREFIX=/api/automation-hub/\n\nPULP_GALAXY_COLLECTION_SIGNING_SERVICE=ansible-default\nPULP_RH_ENTITLEMENT_REQUIRED=insights\n\nPULP_ANSIBLE_API_HOSTNAME={API_PROTOCOL}://{API_HOST}:{API_PORT}\nPULP_ANSIBLE_CONTENT_HOSTNAME={API_PROTOCOL}://{API_HOST}:{API_PORT}/api/automation-hub/v3/artifacts/collections\n\nPULP_TOKEN_AUTH_DISABLED=true\n\n```\n\nTo activate this profile set `COMPOSE_PROFILE=galaxy_ng/ui`. Running this will launch the UI container along with pulp.\n\n```bash\ndnewswan-mac:oci_env dnewswan$ docker ps\nCONTAINER ID   IMAGE                         COMMAND                  CREATED         STATUS         PORTS                    NAMES\n2cc06f79bc87   oci_env_ui                    \"docker-entrypoint.s…\"   3 seconds ago   Up 1 second    0.0.0.0:8002-\u003e8002/tcp   oci_env_ui_1\ne1c3ae797018   localhost/oci_env/pulp:base   \"/init\"                  6 seconds ago   Up 2 seconds   0.0.0.0:5001-\u003e80/tcp     oci_env_pulp_1\n```\n\nMultiple profiles can be selected with `COMPOSE_PROFILE=galaxy_ng/ui:profile2:profile3`. The last profile loaded gets priority on environment variables. Each `compose.yaml` is added additively, and subsquent profles can modify the services from previous profiles.\n\n## How it Works\n\nAt it's core, the oci-env command launches a predictable set of containers with a CLI interface to communicate with them. Thes containers are launched by taking advantage of a feature in docker and podman compose that allow multiple compose.yaml files to be selected via the `-f` flag. The command that `oci-env` runs can be viewed with the `-v` flag:\n\n```\noci-env -v compose up\nRunning command in container: docker-compose -p oci_env -f /Users/dnewswan/code/hub/oci_env/.compiled/oci_env/base_compose.yaml -f /Users/dnewswan/code/hub/oci_env/.compiled/oci_env/galaxy_ui_compose.yaml up\n```\n\nSince not all compose runtimes support variable interpolation, oci-env handles that by itself. The compose.yaml files provided by all of the plugins are gathered up and the variables defined in your `compose.env` file are substituted using python's `str.format()` command and placed in the `.compiled/\u003cCOMPOSE_PROJECT_NAME\u003e/` directory. This directory contains all the information for the running instance of your dev enviornment:\n\n```\n(venv) dnewswan-mac:oci_env dnewswan$ tree .compiled/\n.compiled/\n├── ci\n│  ├── base_compose.yaml\n│  ├── combined.env\n│  └── init.sh\n└── oci_env\n    ├── base_compose.yaml\n    ├── combined.env\n    ├── galaxy_ui_compose.yaml\n    └── init.sh\n```\n\n`.compiled/` contains all your compose files (with the correct variable substitutions) as well as an `init.sh` script that launches each profile's init.sh script and a combined.env file which combines all the pulp_config.env files into one and performs variable substitution. The `combined.env` file is then loaded into the pulp container as an environment variable, and `init.sh` is run once the container has initialized.\n\nOnce all of the information here is compiled, `oci-env` launches the container runtime and mounts the following directories:\n\n- oci_env is mounted into `/opt/oci_env/`. This creates a predictable location to launch scripts provided by oci_env (such as `/opt/oci_env/base/container_scripts/run_functional_tests.sh`)\n- your source code directory is mountent into `/opt/src/`. This provies a predictable location to find plugin source code (such as `/src/pulpcore/`).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpulp%2Foci_env","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpulp%2Foci_env","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpulp%2Foci_env/lists"}