Coder is an OSS Cloud Development Environment platform
This example uses Python and is a command line application
Coder has a REST API where a user's session token is provided in a header to authenticate the app to the Coder deployment
The app runs as a while loop prompting the user for actions like:
- list templates
- list workspaces
- search workspaces with a filter e.g.,
owner:me
orflask
- list all users
- show authenticated user information
- list or override environment variable values
- Switch Coder deployments
- list deployment build information
- list health details of the Coder deployment
- start or stop a workspace from a list
- present clickable URLs for workspaces and templates to open Coder in a browser
- quit the app
When the app starts, it checks that environment variables have been entered and does test API calls to retrieve Coder release, # of users, templates and workspaces.
Credential is a session token. It is read as environment variable along with the Coder Access URL, API Route and Organization Id which you place in .zshrc
or .bashrc
of the host computer running the Docker daemon.
# set environment variables
export CODER_URL_1=""
export CODER_SESSION_TOKEN_1=""
Create a Coder Session Token either:
http://your-access-url/cli-auth
from a browser- In the Coder UI or with Coder CLI, create a token
coder token create
If using the dev container, you cannot use localhost but instead the tunnel proxy URL or our host machine URL where Coder is deployed e.g.,
https://*************.pit-1.try.coder.app
At startup, the app gets Coder deployment's Organization Id with http://your-access-url/api/v2/users/me
which you can also see from a browser. CODER_ORG_ID
is no longer required as an environment variable since the app retrieves it with an initial API call.
The app allows up to 3 Coder deployments. When the app starts, the first one entered is loaded. There is an action in the CLI to switch to another deployment if environment variables have been entered.
# set environment variables
export CODER_URL_1=""
export CODER_SESSION_TOKEN_1=""
export CODER_URL_2=""
export CODER_SESSION_TOKEN_2=""
export CODER_URL_3=""
export CODER_SESSION_TOKEN_3=""
Below are build instructions instead of including a large binary and build artifacts in this repo
- Use a build tool like 'pip3 install pystaller'
- 'pyinstaller --onefile --workpath /path/to/build/directory coder-cli.py'
- Run
./coder-cli
from the./dist
directory or add the directory to your path and runcoder-cli
cd
into the repo directory and run the app
python3 coder-cli.py
The dev container automatically starts the app with "postCreateCommand": "python3 coder-cli.py"
Notice the Dockerfile
and devcontainer.json
which uses a slim Python container image in the Dockerfile, and passes the Coder authentication environment variables into the dev container.
This approach frees you up from having a specific Python version and module on your local machine e.g., Mac and let the dev container set all of this up. You do still need to set the environment variables locally which is more secure and better than putting into the repo with .gitignore. ☠️
If not using a dev container, you will need to pip install
the following packages:
requests
python-dateutil
pytz
sharkymark Coder API call examples
This project is licensed under the MIT License
Please note that this program is not actively maintained or tested. While it may work as intended, it's possible that it will break or behave unexpectedly due to changes in dependencies, environments, or other factors.
Use this program at your own risk, and be aware that:
- Bugs may not be fixed
- Compatibility issues may arise
- Security vulnerabilities may exist
If you encounter any issues or have concerns, feel free to open an issue or submit a pull request.