kostis-codefresh / humanitec-notify-step

Containerized plugin to notify Humanitec when a new image is pushed to its registry

Home Page:https://codefresh.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Notify Humanitec for new images

Go Report Card Codefresh build status

This is a mini CLI + Container image to work with Humanitec notifications.

How Humanitec container images work

Humanitec has an internal Docker registry at registry.humanitec.io that you can push images to. The credentials for the registry are dynamic and you need to fetch them with an API call.

Once you have the credentials, you can push an image to it like any other container registry. After you finish with the push you also need to notify Humanitec about the new image build with another API call. Here is the whole process:

  1. Signup for Humanitec
  2. Go into the Humanitec UI and create a new token from your organization screen in the Images section
  3. Perform a call to https://api.humanitec.io/orgs/<your org>/registries/humanitec/creds. You will get a JSON with Docker credentials
  4. Use the credentials to push an image like any other standard container registry
  5. Perform another call to https://api.humanitec.io/orgs/<your org>/images/<your image name>/builds with the correct payload
  6. The image will appear in the Humanitec UI and you can use it in your deployments

How to build

Run:

  • go build to get the executable OR
  • docker build . -t humanitec-notify-container to create a container image if you prefer docker instead or don't have access to a Go dev environment

A prebuilt image is already available at https://hub.docker.com/r/kostiscodefresh/humanitec-notify-step

How to use the CLI

This CLI can be used for the two API calls mentioned in the first section

  1. Run humanitec-notify-step -organization <your-org> -humanitec-token <your-token> -mode fetch. This will fetch the registry credentials and save them to a file called creds.json
  2. Push an image to registry.humanitec.io either manually or via an automated method using the credentials
  3. Run humanitec-notify-step -organization <your-org> -humanitec-token <your-token> -mode notify -image-name my-image -image-git-commit my-git-hash -image-git-branch main -image-url registry.humanitec.io/my-org/humanitec-example:latest. This will notify Humanitec about the new image that you pushed

You can use this CLI in any CI/CD system and the Dockerhub image in any container based pipeline.

Codefresh example

See an example for Codefresh at https://github.com/kostis-codefresh/humanitec-example

About

Containerized plugin to notify Humanitec when a new image is pushed to its registry

https://codefresh.io/


Languages

Language:Go 92.2%Language:Dockerfile 7.8%