How to find the status of automated builds in Docker Hub - dockerhub

How to find the status of automated builds which get triggered either manually or via the Trigger url for a Docker Hub project.
https://hub.docker.com/repository/docker/company/webapp/builds
I would like to understand if its running and if its running the current status (i.e still running or build completed)
List of past builds
Status of all builds (time initiated, completed, build status)

Try with this:
curl https://hub.docker.com/api/build/v1/source/?image={namespace}/{repo} | jq '.objects[0].state'
Add bearer token in your request if it is a private repo
-H "Authorization: Bearer {Token}"

docker ps --no-trunc
will display the list of full containers and builds and details of the other running containers.

Related

How to delete images from an artifactory docker repo

I have a docker repository in artifactory: artifactory.MYCOMPANY.com/artifactory/REPO-docker-local. I'd like to delete images in a periodic cron job. I have full permissions to create, delete and edit files on this artifactory repo.
I'd like to have a job that deletes ALL images once a month (to ensure the size doesn't grow too much, that's OK from the usage scenarios). However I can't find an API that would do that. I've tried docker rmi but it only deletes local images. What API could I use?
Curl can make a DELETE request like below:
curl -u {username}:{password} -X DELETE https://artifactory.MYCOMPANY.com/artifactory/REPO-docker-local/TAG
This can delete many images at once, e.g. TAG:latest, TAG:1, ...
This user plugin on clean Docker images might help in automating the deletion process by writing a script around the suggested curl command and setting up the script based on cronjob.
Note: For this plugin to work, the docker images getting deployed should have the LABEL mentioned in the user plugin.

How do I check for build status, running Jenkins jobs from a BitBucket pipeline?

We're using BitBucket to host our Git repositories.
We have defined build jobs in a locally-hosted Jenkins server.
We are wondering whether we could use BitBucket pipelines to trigger builds in Jenkins, after pull request approvals, etc.
Triggering jobs in Jenkins, through its REST API is fairly straightforward.
1: curl --request POST --user $username:$api_token --head http://jenkins.mydomain/job/myjob/build
This returns a location response header. By doing a GET on that, we can obtain information about the queued item:
2: curl --user $username:$api_token http://jenkins.mydomain/queue/item/<item#>/api/json
This returns JSON describing the queued item, indicating whether the item is blocked, and why. If it's not, it includes the URL for the build. With that, we can check the status of the build, itself:
3: curl -–user $username:$api_token http://jenkins.mydomain/job/myjob/<build#>/api/json
This will return yet more json, indicating whether the job is currently building, and if it's completed, whether the build succeeded.
Now BitBucket pipeline steps run in Docker containers, and have to run on Linux. Our Jenkins build jobs run on a number of platforms, not all of which are Linux. But BitBucket shouldn't care. Making the necessary REST API calls can be done in Linux, as I am in the examples above.
But how do we script this?
Do we create a single step that runs a shell script that runs command #1, then repeatedly calls command #2 until the build is started, then repeatedly calls command #3 until the build is done?
Or do we create three steps, one for each? Do BitBucket pipelines provide for looping on steps? Calling a step, waiting for a bit, then calling it again until it succeeds?
I think you should either use Bitbucket pipeline or Jenkins pipeline. Using both will give you to many options and make the project more complex than it should be.

Bamboo Docker build Errors with Google Container Registry

I'm attempting to run a Bamboo (private server) task that builds a docker image. The dockerfile builds from an image on google container registry. gcr.io/project-name/image-name:tag. However, whenever my task is triggered, I get a build error.
Checking the log, the issue appears to be:
build 23-Aug-2018 20:08:52 Sending build context to Docker daemon 3.072 kB
build 23-Aug-2018 20:08:52
build 23-Aug-2018 20:08:52 Step 1 : FROM gcr.io/project-name/image-name:tag
build 23-Aug-2018 20:08:52 Trying to pull repository gcr.io/project-name/image-name ...
build 23-Aug-2018 20:08:52 Pulling repository gcr.io/project-name/image-name
error 23-Aug-2018 20:08:52 Error: Status 405 trying to pull repository project-name/image-name: "v1 Registry API is disabled. If you are not explicitly using the v1 Registry API, it is possible your v2 image could not be found. Verify that your image is available, or retry with `dockerd --disable-legacy-registry`. See https://cloud.google.com/container-registry/docs/support/deprecation-notices"
simple 23-Aug-2018 20:08:52 Failing task since return code of [/usr/bin/docker build --no-cache=true --force-rm=true --tag=gcr.io/project-name/out_image-name:outer_tag /var/atlassian/application-data/bamboo/xml-data/build-dir/3997697/AN-CA-JOB1] was 149 while expected 0
Looking into the error, I came across this google troubleshooting page, which suggests confirming the names are right. Running the command, I can confirm the name returns results.
Additionally, the "retry with dockerd --disable-legacy-registry" suggestion seems dated, since the Docker docs say:
The disable-legacy-registry configuration option has been removed and,
when used, will produce an error on daemon startup.
What am I doing wrong?
Other details:
Bamboo version 6.4.1 build 60405
Turns out the issue is an outdated version of Docker.

Docker trigger jenkins job when image is pushed

I am trying to build a jenkins job(trigger builds remotely) on docker image build, build all I am getting on docker hub is following:
HISTORY
ID Status Date & Time
7345... ! ERROR 10/12/17 10:03
Reason (I assume): Docker is not authenticated to post to the jenkins url.
Question: How can I trigger the job automatically when an image gets pushed to docker hub?
Pull and run Watchtower docker image to poll any third-party public Docker image on Docker Hub or Quay that you need (typically as a base image of your own containers). Here's how. "Polling" here does not imply crudely pulling the whole image every 5 minutes or so - we are monitoring periodically for changes in the image, downloading only the checksum (SHA digest) most of the time (when there are no changes in the locally cached image).
Install the Build Token Root Plugin in your Jenkins server and set it up to receive Slack-formatted notifications secured with a token to trigger builds remotely or - safer - locally (those triggers will be coming from Watchtower container, not Slack). Here's how.
Set up Watchtower to post Slack messages to your Jenkins endpoint upon every change in the image(s) (tags) that you want. Here's how.
Optionally, if your scale is so large that you could end up overloading and bringing down the entire Docker Hub with a flood HTTP GET requests (should the time triggers go wrong and turn into a tight loop) make sure to build in some safety checks on top of Watchtower to "watch the watchman".
You can try the following plugin: https://wiki.jenkins.io/display/JENKINS/CloudBees+Docker+Hub+Notification
Which claims to do what you're looking for.
You can configure a WebHook in DockerHub wich will trigger the Jenkins-Build.
Docker Hub webhooks targeting your Jenkings server endpoint require making periodic copies of the image to another repo that you own [see my other answer with Docker Hub -> Watchman -> Jenkins integration through Slack notifications].
More details
You need to set up a cron job with periodic polling (docker pull) of the source repo to [docker] pull its `latest' tag, and if a change is detected, re-tag it as your own and [docker] push to a repo you own (e.g. a "clone" of the source Docker Hub repo) where you have set up a webhook targeting your Jenkings build endpoint.
Then and only then (in a repo you own) will Jenkins plugins such as Docker Hub Notification Trigger work for you.
Polling for Dockerfile / release changes
As a substitute of polling the registry for image changes (which need not generate much network traffic thanks to the local cache of docker images) you can also poll the source Dockerfile on Github using wget. For instance Dockerfiles of the official Docker Hub images are here. In case when the Github repo makes releases, you can get push notifications of them using Github Watch > Releases Only feature and if they have CI docker builds. Docker images will usually be available with a delay after code releases, even with complete automation, so image polling is more reliable.
Other projects
There was also a proposal for a 2019 Google Summer of Code project called Polling Docker Registries for Image Changes that tried to solve this problem for Jenkins users (incl. apparently Google), but sadly it was not taken up by participants.
Run a cron job with a periodic docker search to list all tags in the docker image of interest (here's the script). Note that this script requires the substitution of the jannis/jq image with an existing image (e.g. docker run --rm -i imega/jq).
Save resulting tags list to a file, and monitor it for changes (e.g. with inotifywait).
Fire a POST request using curl to your Jenkins server's endpoint using Generic Webhook Trigger plugin.
Cautions:
for efficiency reasons this tags listing script should be limited to a few (say, 3) top pages or simple repos with a few tags,
image tag monitoring relies on tags being updated correctly (automatically) after each image change, rather than being stuck in the past, like say Ubuntu tags (e.g. trusty-20190515 was updated a few days ago - late November, without the change in its mid-May tag).

docker hub webhook for _failed_ build?

I have several automated builds set up on docker hub. I see that I can set up a webhook to POST to a URL on a successful build, but it seems like it's more useful to be notified of a failed build. Is there any way to do that?
I tried adding a webhook and then pushing a deliberately bad RUN instruction to my Dockerfile. The automated build failed as expected but nothing was sent to my webhook.
Some of my builds are triggered not by git pushes but by cron jobs, so even if I tested the build before every commit, it wouldn't catch this situation. Builds that are successful one day could fail the next due to changing contents of URLs downloaded via ADD.
So...is there a way to get a notification of a failed automated build? If not, consider this a feature request.
You can turn on email-based notifications that a build has failed by going under your user settings option and clicking on notifications and checking the appropriate box. (Thanks #docker twitter account; this wasn't obvious to me either! https://twitter.com/DockerSupport/status/555912171792527360 )
As you have observed, a webhook for a POST event is not available for failed builds. I imagine the idea is that these are more for triggering some follow-up event such as telling a machine to pull the new image, while an email notification makes more sense for a failed build.
One option is to poll Docker Hub v2 API and emulate the missing notifications whenever the build history reports a failure (-1) or the build remains queued for too long. The solution is described here: Docker on-failure Webhook and is based on the Axibase Time Series Database sandbox image.
docker run -d -p 8443:8443 -p 9443:9443 \
--name=atsd-sandbox \
--env NAMESPACE='google' \
--env NOTIFY_URL='https://webhook.site/71fd9feb-8751-4afd-9e13-16072a34b259' \
--env ATSD_IMPORT_PATH='https://raw.githubusercontent.com/axibase/atsd-use-cases/master/how-to/docker/resources/notify.xml,https://raw.githubusercontent.com/axibase/atsd-use-cases/master/how-to/docker/resources/rule.xml' \
--env COLLECTOR_IMPORT_PATH='https://raw.githubusercontent.com/axibase/atsd-use-cases/master/how-to/docker/resources/job.xml' \
axibase/atsd-sandbox:latest
If the build fails intermittently, you can even program the rule to 'retaliate' against Docker Hub by initiating a retry using remote triggers.
Disclaimer: I work for Axibase.

Resources