{"id":13451627,"url":"https://github.com/triggermesh/tm","last_synced_at":"2025-03-23T19:32:14.589Z","repository":{"id":33042044,"uuid":"142234428","full_name":"triggermesh/tm","owner":"triggermesh","description":"TriggerMesh CLI to work with knative objects","archived":true,"fork":false,"pushed_at":"2023-05-09T07:09:01.000Z","size":13756,"stargazers_count":84,"open_issues_count":5,"forks_count":15,"subscribers_count":10,"default_branch":"main","last_synced_at":"2024-06-18T21:36:19.852Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://triggermesh.com","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/triggermesh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2018-07-25T02:04:28.000Z","updated_at":"2024-02-17T14:34:24.000Z","dependencies_parsed_at":"2024-06-18T21:17:29.334Z","dependency_job_id":"503cbaa4-f379-4113-82b4-e78b30d00d79","html_url":"https://github.com/triggermesh/tm","commit_stats":null,"previous_names":[],"tags_count":47,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/triggermesh%2Ftm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/triggermesh%2Ftm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/triggermesh%2Ftm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/triggermesh%2Ftm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/triggermesh","download_url":"https://codeload.github.com/triggermesh/tm/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":213325044,"owners_count":15570226,"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-31T07:00:57.350Z","updated_at":"2024-10-28T17:33:13.446Z","avatar_url":"https://github.com/triggermesh.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"[![Release](https://img.shields.io/github/v/release/triggermesh/tm?label=release)](https://github.com/triggermesh/tm/releases) [![Downloads](https://img.shields.io/github/downloads/triggermesh/tm/total?label=downloads)](https://github.com/triggermesh/tm/releases) [![CircleCI](https://circleci.com/gh/triggermesh/tm/tree/master.svg?style=shield)](https://circleci.com/gh/triggermesh/tm/tree/master) [![Go Report Card](https://goreportcard.com/badge/github.com/triggermesh/tm)](https://goreportcard.com/report/github.com/triggermesh/tm) [![License](https://img.shields.io/github/license/triggermesh/tm?label=license)](LICENSE)\n\n*THIS REPOSITORY IS NOW ARCHIVED IN FAVOR OF https://github.com/triggermesh/tmctl*\n\nA CLI for [knative](https://github.com/knative)\n\n## Installation\n\nThere are two ways of tm CLI installation:\n\n- Download a binary from the [latest release](https://github.com/triggermesh/tm/releases/latest)\n\n- Install CLI from sources:\n```\ngit clone https://github.com/triggermesh/tm.git\ncd tm\ngo install\n```\n\n### Configuration\n\n**On TriggerMesh:**\n\n1. Request beta access to TriggerMesh cloud at [https://triggermesh.com](https://triggermesh.com)\n2. Download your TriggerMesh configuration file by clicking on the `download` button in the upper right corner\n3. Save the file as $HOME/.tm/config.json and you are ready to use the `tm` CLI\n\n**On your own knative cluster:**\n\nAssuming you have access to the Kubernetes API and have a working `kubectl` setup, `tm` should work out of the box.\n\n### Examples\n\nDeploy service from Docker image\n```\ntm deploy service foo -f gcr.io/google-samples/hello-app:1.0 --wait\n```\n\nIf you have Dockerfile for your service, you can use kaniko runtime to deploy it\n```\ntm deploy service foobar \\\n    -f https://github.com/knative/docs \\\n    --runtime https://raw.githubusercontent.com/triggermesh/knative-lambda-runtime/master/kaniko/runtime.yaml \\\n    --build-argument DIRECTORY=docs/serving/samples/hello-world/helloworld-go \\\n    --wait\n```\n\nor deploy service straight from Go source using OpenFaaS runtime\n```\ntm deploy service bar \\\n    -f https://github.com/golang/example \\\n    --runtime https://raw.githubusercontent.com/triggermesh/openfaas-runtime/master/go/openfaas-go-runtime.yaml \\\n    --build-argument DIRECTORY=hello \\\n    --wait\n```\n\nMoreover, for more complex deployments, tm CLI supports function definition parsing from [YAML](https://github.com/tzununbekov/serverless/blob/master/serverless.yaml) file and ability to combine multiple functions, runtimes and repositories\n```\ntm deploy -f https://github.com/tzununbekov/serverless\n```\n\n_If you are interested in a building image without deploying knative service, then `--build-only` flag is available in \"deploy service\" command_\n\n### Running Tests Locally\n\nTo run tests you first have to set namespace you have access to with the following command:\n```\nexport NAMESPACE=yourNamespace\n```\nRun unit-tests with following command from project root directory:\n```\nmake test\n```\n\n\n## AWS Lambda\n\nWith the TriggerMesh CLI you can easily deploy AWS Lambda functions on Kubernetes:\n\nPrepare local source for Golang function\n\n```\nmkdir lambda\ncd lambda\ncat \u003e main.go \u003c\u003cEOF\npackage main\n\nimport (\n        \"fmt\"\n        \"context\"\n        \"github.com/aws/aws-lambda-go/lambda\"\n)\n\ntype MyEvent struct {\n        Name string\n}\n\nfunc HandleRequest(ctx context.Context, name MyEvent) (string, error) {\n        return fmt.Sprintf(\"Hello %s!\", name.Name ), nil\n}\n\nfunc main() {\n        lambda.Start(HandleRequest)\n}\nEOF\n```\n\nDeploy function using Go Knative Lambda Runtime\n\n```\ntm deploy service go-lambda -f . --runtime https://raw.githubusercontent.com/triggermesh/knative-lambda-runtime/master/go/runtime.yaml --wait\n```\n\nLambda function available via http events\n\n```\ncurl http://go-lambda.default.dev.triggermesh.io --data '{\"Name\": \"Foo\"}'\n\"Hello Foo!\"\n```\n\n[Here](https://github.com/triggermesh/knative-lambda-runtime) you can find more information about Knative Lambda Runtimes\n\n\n## Deployment pipelines\n\n_This feature is only available for Github.com repositories at the moment_\n\nWith TriggerMesh CLI you can create fully functional deployment pipeline of existing git repository with a single command. In example below we're assuming that you have an access to Kubernetes cluster with Knative and Tekton pipelines installed. If you use TriggerMesh Cloud you should not worry about requirements; platform is ready to go.\n\nAs a first step, you should create new public repository in GitHub.com which we will use in our example. After the empty repository has been created, we need to push sample AWS Lambda project to it:\n\n```\ntm generate python foo\ncd foo\ngit init\ngit add --all\ngit commit -m \"Sample AWS Lambda project\"\ngit remote add origin git@github.com:\u003cUSERNAME\u003e/\u003cREPOSITORY\u003e.git\ngit push -u origin master\n```\n\nNow that we have repository with Python project, let's create build pipeline:\n\n```\ntm push | kubectl apply -f -\n```\n-this command creates several Knative and Tekton components:\n\n1. Tekton task with `tm` image to build AWS Lambda project using [KLR](https://github.com/triggermesh/knative-lambda-runtime)\n1. Tekton taskrun to initiate project build and corresponding pipelineresource with source URL\n1. TriggerMesh GitHub custom \"third-party\" containersource that allows to track events on GitHub repositories*\n1. TriggerMesh Aktion [transceiver](https://github.com/triggermesh/aktion/tree/master/cmd/transceiver) and its configmap to create new taskruns on incoming events from GitHub containersource\n\n\n\\* our GitHub containersource is aimed at simplifying event tracking and based on periodic GitHub API requests (one request per minute). As a result, you don't need to create and store any tokens. Downside of this approach is that containersource have requests rate limitation (60 requests per hour) and it doesn't work with private repositories. Both of these limitations can be bypassed by providing GitHub personal access token in push command parameter: `tm push --token \u003cTOKEN\u003e`\n\nAfter few minutes you should be able to see new Knative service deployed in cluster. Any commits will trigger new build and deploy so that new function will reflect all code changes.\n\n### Docker registry\n\nDocker images are used to run functions code in Knative services. This means that image registry is important part of service deployment scheme. Depending on type of service, Knative controller may either only pull or also push service image from and to registry. TriggerMesh CLI provides simple configuration interface to setup registry address and user access credentials.\n\n#### Service from pre-build image\n\nMost simple type of service deployment uses service based on pre-built Docker image available in **public** registry. This kind of service doesn't require any additional configuration and may be started with following command:\n\n```\ntm deploy service foo -f gcr.io/google-samples/hello-app:1.0 --wait\n```\n\nThis case doesn't produce any images so no authentication is required.\n\nIf pre-built image stored in **private** registry, you must specify access credentials by running following command before starting deployment:\n\n```\ntm set registry-auth foo-registry\n```\n\nYou will be asked to enter a registry address, username, and password - they will be saved to k8s secret and be used to pull images deployed under your service account.\n\nBesides pulling, this secret may be used to push new images for service deployment based on function source code and build template. Name of one particular k8s secret should be passed to deployment command to make CLI work with private registry:\n\n```\ntm deploy service foo-private -f https://github.com/serverless/examples \\\n                              --runtime knative-node4-runtime \\\n                              --build-argument DIRECTORY=aws-node-serve-dynamic-html-via-http-endpoint \\\n                              --build-argument HANDLER=handler.landingPage \\\n                              --registry-secret foo-registry \\\n                              --wait\n```\n\nIf user whose credentials are specified in `foo-registry` have \"write\" permissions, resulting service image will be pushed to URL composed as `registry/username/service_name`\n\n#### Gitlab CI registry\n\nTriggerMesh CLI can be used as deployment step in GitLab CI pipeline, but considering [tokens](https://docs.gitlab.com/ee/user/project/deploy_tokens/) security policy, user must manually create CI deployment token as described [here](https://docs.gitlab.com/ee/user/project/deploy_tokens/#gitlab-deploy-token).\nDeployment token must have registry read permission and should be valid for as long as the service expected to be active. If token is created, `tm` deployment step must include following commands:\n\n```\n...\nscript:\n  - tm -n \"$KUBE_NAMESPACE\" set registry-auth gitlab-registry --registry \"$CI_REGISTRY\" --username \"$CI_REGISTRY_USER\" --password \"$CI_JOB_TOKEN\" --push\n  - tm -n \"$KUBE_NAMESPACE\" set registry-auth gitlab-registry --registry \"$CI_REGISTRY\" --username \"$CI_DEPLOY_USER\" --password \"$CI_DEPLOY_PASSWORD\" --pull\n...\n```\nAfter this, you may pass `--registry-secret gitlab-registry` parameter to `tm deploy` command (or in [serverless.yml](https://gitlab.com/knative-examples/functions/blob/master/serverless.yaml#L6)) so that Knative could authenticate against Gitlab registry.\nGitLab registry doesn't provide permanent read-write token that can be used in CI, but it has job-specific `CI_JOB_TOKEN` with \"write\" permission which is valid only while CI job running and `CI_DEPLOY_PASSWORD` with read permission which we created before. Considering this, we can see that CLI `set registry-auth` command supports `--push` and `--pull` flags that indicates which secret must be used to push image and which for \"pull\" operations only. Resulting images will be stored under `registry.gitlab.com/username/project/function_name` path\n\n### Custom registry name\n\nWhile using a username as a registry identifier (docker.io/username) is a common practice, in some cases we must be able to use different values for an authentication and in destination URL (for example, [gcr.io](https://cloud.google.com/container-registry/docs/advanced-authentication#linux-macos)). TriggerMesh CLI `set registry-auth` command provides such ability by exposing an optional `--project` argument which will be used as a part of the image URL instead of the username:\n\n```\nTOKEN=$(gcloud auth print-access-token)\ntm set registry-auth gcr --registry eu.gcr.io --project my-org/my-project --username oauth2accesstoken --password $TOKEN\ntm generate python\ntm deploy -f python --registry-secret gcr --wait\n```\n\nAs a result, Knative service image will be pushed to `eu.gcr.io/my-org/my-project` registry\n\n#### AWS ECR\n\nECR is a specific case of the custom registry destination with an additional requirement - a repository must be created before pushing the image. Thus, service deployment steps should be slightly altered:\n\n1. Create ECR repository in `\u003cproject\u003e/\u003cservice\u003e` format where \"project\" is an arbitrary identifier for the service (e.g., namespace) and \"service\" is the name of the service that is being deployed (in the example below it is `python-test`). \n1. Retrieve ECR token:\n    ```\n    TOKEN=$(aws ecr get-login-password --region \u003cregion\u003e)\n    ```\n1. Create the registry auth secret by running following command:\n    ```\n    tm set registry-auth ecr --registry \u003cregistry host\u003e --project \u003cproject\u003e --username AWS --password $TOKEN\n    ```\n\n1. Deploy the service. For example Python KLR: \n    ```\n    tm deploy service python-test -f https://github.com/serverless/examples \\\n      --runtime https://raw.githubusercontent.com/triggermesh/knative-lambda-runtime/master/python37/runtime.yaml \\\n      --registry-secret ecr \\\n      --build-argument DIRECTORY=aws-python-simple-http-endpoint \\\n      --build-argument HANDLER=handler.endpoint \\\n      --wait\n    ```\n\n#### Unauthenticated registry\n\nBesides hosted registries, the TriggerMesh CLI may work with unauthenticated registries which do not require setting access credentials. For such cases, you may simply add `--registry-host` argument to the deployment command with registry domain name parameter and the resulting image will be pushed to `registry-host/namespace/service_name` URL\n\n### How-To\n\nFor additional details on how to use `tm`, consult the [HOWTO Guide](./HOWTO.md)\n\n### Support\n\nWe would love your feedback on this CLI tool so don't hesitate to let us know what is wrong and how we could improve it, just file an [issue](https://github.com/triggermesh/tm/issues/new)\n\n### Code of Conduct\n\nThis plugin is by no means part of [CNCF](https://www.cncf.io/) but we abide by its [code of conduct](https://github.com/cncf/foundation/blob/master/code-of-conduct.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftriggermesh%2Ftm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftriggermesh%2Ftm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftriggermesh%2Ftm/lists"}