Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added endpoint for docker pull #36

Merged
merged 3 commits into from
Feb 27, 2019
Merged

Conversation

danielwelch
Copy link

I was checking out this project and #20 and thought I'd take a quick stab at this. Ultimately, I'd like to be able to implement a home assistant script, triggerable from the front-end, that does the equivalent of a pull, rm, and run to update home assistant. I think the next step would be to implement an endpoint that does the removing and subsequent running. I just followed the dockerode docs example but don't have any prior experience with the library.

@philhawthorne philhawthorne changed the base branch from master to dev February 26, 2019 02:07
@philhawthorne
Copy link
Owner

Awesome! Thanks for kick-starting this.

So just to confirm, if I wanted to pull the latest Home Assistant release, I would go to

http://127.0.0.1:8129/pull/homeassistant/home-assistant:latest? I am also guessing to get a specific tag, like rc I could use http://127.0.0.1:8129/pull/homeassistant/home-assistant:rc?

@philhawthorne philhawthorne added the enhancement New feature or request label Feb 26, 2019
@danielwelch
Copy link
Author

Yeah, that's right, but now that you've typed it out I'm wondering if there'd be a parsing error. If so, could use two different url path parameters and reconstruct the repoTag.

index.js Outdated
/**
* Pull the lastest image for the given repository, with or without tag
*/
app.get('/pull/:repoTag', function (req, res) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might be better to set this to

Suggested change
app.get('/pull/:repoTag', function (req, res) {
app.get('/pull/*', function (req, res) {

From there, we can then determine what to pull. With that above, req.params[0] should be set to homeassistant/home-assistant:rc for example.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@philhawthorne
Copy link
Owner

One thing that comes to mind here is timeouts.

For example if a user called the pull endpoint from Home Assistant, the request may take longer than 60 seconds for the new Docker image to be pulled down. During this time, Home Assistant would have given up the request and discarded it.

I may need to come up with the concept of webhooks. Where the user could make a POST request to /pull with the repo they want to pull, and an optional callback_uri. Once the docker pull command has finished, if the user provided a webhook_uri, HA-Dockermon would call the URL.

That webhook_uri could be a cloud/local Home Assistant webhook which then kicks off the second part of the automation, or changing the state of a sensor to let the user know the new image has been pulled and ready.

@danielwelch
Copy link
Author

Good thought! I like the idea of a callback uri that could be a webhook platform automation trigger. It’d be up to the user to fill out the automation with something like sending a notification that the docker pull has finished, or sending a request to another ha-dockermon endpoint triggering container removal and restart.

@philhawthorne
Copy link
Owner

Indeed.

For this PR at least, what you've got now with just a basic GET request to /pull/* should suffice. This way it keeps it agnostic enough for users that might want to use it as just a REST platform.

Once this PR is merged, I can then work on the webhook and POST side of things as part of a bigger update 😃

@danielwelch
Copy link
Author

Here you go! Thanks for your work on the pod btw, big fan. Happy to help with further webhook work as time allows.

@philhawthorne
Copy link
Owner

Thanks for the contribution!

I will merge this into the dev branch for now while I test it. If anyone wants to try this out, you can use the respective edge tags from Dockerhub.

For now I'm going to have a think about the best approach for either a webhook or something else approach.

Cheers!

@philhawthorne philhawthorne merged commit 04e52b7 into philhawthorne:dev Feb 27, 2019
@addisonlynch
Copy link

addisonlynch commented Mar 15, 2020

@philhawthorne any chance of this getting merged into master soon? It is a very useful endpoint!

@philhawthorne
Copy link
Owner

Sure is @addisonlynch

I'm hoping to package it up as part of the MQTT additions I'm doing. But for now you can use this endpoint by using the edge tag in your docker run

@avico78
Copy link

avico78 commented May 6, 2020

@philhawthorne - first thanks a lot for the ha-dockermon ,great work!
Question regarding pull - not sure if this functionality added ,
as check on latest version

curl --request GET --url http://127.0.0.1:8129/pull/homeassistant/home-assistant:latest
curl: (7) Failed to connect to 127.0.0.1 port 8129: Connection refused

it would be really great if ha-dockermon wil;l have the functionality for upgrading containers version .
tnx again!

@philhawthorne
Copy link
Owner

Hi @avico78

Check the edge tag in Dockhub. That is where I have merged this and working on MQTT integration.

I'm still testing this myself, just haven't had a chance to work on it much lately. Hoping to do a new release soon with MQTT and the other contributions like this.

@avico78
Copy link

avico78 commented May 6, 2020

@philhawthorne ,

I remove latest and install edge ...run get for pull request without success:


[/share/my/Dockers] # docker ps -a
CONTAINER ID        IMAGE                                 COMMAND                  CREATED             STATUS                PORTS                                                              NAMES
367a50a8ce3f        **philhawthorne/ha-dockermon:edge**       "docker-entrypoint..."   48 seconds ago      Up 45 seconds         0.0.0.0:8126->8126/tcp 
 curl --request GET --url http://127.0.0.1:8129/pull/homeassistant/home-assistant:latest
curl: (7) Failed to connect to 127.0.0.1 port 8129: Connection refused

am I missing something?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants