Skip to content

FF-160/download docker app#9

Merged
mike-sul merged 6 commits intomasterfrom
FF-160/download-docker-app
May 28, 2020
Merged

FF-160/download docker app#9
mike-sul merged 6 commits intomasterfrom
FF-160/download-docker-app

Conversation

@mike-sul
Copy link
Copy Markdown
Contributor

No description provided.

@mike-sul mike-sul requested a review from doanac May 25, 2020 16:23
@mike-sul mike-sul force-pushed the FF-160/download-docker-app branch from 304ef30 to 5e091cd Compare May 25, 2020 18:04
@mike-sul
Copy link
Copy Markdown
Contributor Author

@doanac I enabled clang tidying again by introducing our own testing docker container based on ubuntu.bionic.
I am going to add some negative tests for the introduced functionality.

Copy link
Copy Markdown
Member

@doanac doanac left a comment

Choose a reason for hiding this comment

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

I've done a first pass. I still need to read a bit more, but this should get things going.

One thing - that would be nice: can we separate the ninja format changes from the actual code changes. Maybe - just merge ninja-format problems now?

Comment thread dev-shell Outdated
if ! docker image inspect $container 2>/dev/null 1>/dev/null ; then
echo "Container not found, doing one time docker build"
docker build -t $container -f ./aktualizr/docker/Dockerfile.debian.testing .
docker build -t $container -f ./docker/Dockerfile.ubuntu.bionic .
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should we go ahead and jump to 20.04, or would that risk some incompatibilities with aktualizr?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

let's see what the aktualizr team will do about it if anything, I would stay with whatever they will come up with because if we just switch to something higher we might end-up with some incompatibilities as you stated. I consider it as a temporal solution.

Comment thread docker/Dockerfile.ubuntu.bionic Outdated
RUN NOCONFIGURE=1 ./autogen.sh
RUN ./configure CFLAGS='-Wno-error=missing-prototypes' --with-libarchive --disable-gtk-doc --disable-gtk-doc-html --disable-gtk-doc-pdf --disable-man --with-builtin-grub2-mkconfig --with-curl --without-soup --prefix=/usr
RUN make VERBOSE=1 -j4
RUN make install
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I've always been curious why ostree is pinned to a specific source revision while the other dependencies are not. You have any insights on that? Just curious.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It has to do with the hack around testing the ostree based package manager (LD_PRELOAD and those two overridden methods ), the hack doesn't work with any ostree version.

Comment thread src/composeappmanager.cc
auto endpoint_pos = registry_conf.auth_creds_endpoint.find(treehub_endpoint);
if (endpoint_pos != std::string::npos) {
registry_conf.auth_creds_endpoint.replace(endpoint_pos, registry_creds_endpoint.length(),
registry_creds_endpoint);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I guess the else branch here helps with testing?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

n/m - i see how you handle this below now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am wondering if we should have this config defined. It pins us to hub.foundries.io. However - docker makes this discoverable. eg:

$ curl -v https://hub.foundries.io/v2/msul-dev01/shellhttpd/manifests/latest
...
< HTTP/1.1 401 Unauthorized
...
< Www-Authenticate: Bearer realm="https://hub.foundries.io/token-auth/",service="registry",scope="repository:msul-dev01/shellhttpd:pull"

Comment thread src/composeappmanager.cc Outdated
if (split_pos == std::string::npos) {
throw std::invalid_argument("Invalid App URI: '@' not found in " + uri);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should we do some assertion that uri starts with hub.foundries.io?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Can't it be different than hub.foundries.io, e.g. test mocks, tests, on prem deployment. I suppose it can be verified/checked if it's inline with what is defined in the config (registry_base_url).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this all fits in with my other comment above about just letting docker's api tell us what to authenticate with.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Maybe I just check if the App URI hostname matches the registry_base_url's hostname here, and check if the registry_base_url is equal to https://hub.foundries.io at the configuration time.
Another option is to get rid off base_url, auth_token_endpoint, repo_base_url configuration variables at all and extracts registry hostname from App URI, although '/token-auth/' and /v2/ has to be hardcoded then. BTW, /token-auth/ is hardcoded in the docker compose download implementation, too.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think getting rid of them is fine for now. "v2" can be hard-coded. I guess I did "auth-token" incorrectly in my docker-compose patch. The "Www-Authenticate:" header should tell the client where to go. For docker, I noticed my logic would be broke as the do:

Www-Authenticate: Bearer realm="https://auth.docker.io/token",service="registry.docker.io"...

Comment thread src/composeappmanager.cc Outdated
Comment thread src/composeappmanager.cc Outdated
Comment thread src/composeappmanager.cc
Comment thread src/composeappmanager.cc Outdated
return "authorization: basic " + encoded_auth_secret;
}

std::string RegistryClient::getBearerAuthHeader(const std::string& repo) const {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this might be too painful for now and we should just keep it like this with a TODO. However, docker provides a way to find credentials. In theory, on LmP, you look at /usr/lib/docker/config.json and then $HOME/.docker/config.json for auths and credHelpers. If "auths" you just use the value provided. If "credsHelpers", you call that program and use its stdout.

Maybe we assert hub.foundries.io for now though and because its hub.fio, we know how to handle this w/o using the credsHelper.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The credHelpers relies on aktaulizr-get. What's the point to go from aktualizr to the docker stuff which in turn comes back to aktualizr if 'we' are aktualizr and go straight to the auth service.
It's not hub.foundries.io, it's https://ota-lite.foundries.io:8443/hub-creds/.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

what i was trying to say here is that: we should really make this generic and not tied to hub.foundries.io. maybe eventually though since its a bit more work. in the case of hub.foundries.io, we could skip looking up the cred helper since we know how to do that.

what's nice about the docker-compose implementation is that it could download the archive from any docker registry with any credentials docker supports.

but since this is tied to hub.foundries.io, I think we can skip the configuration data and just hard-code to hub.foundries.io and raise an error if its not a hub.foundries.io app. In the future we could add logic to support other docker registries.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I see what you mean. Still, we can change our registry's hostname overtime or deploy additional one with the same way of getting creds to it (via https://ota-lite.foundries.io:8443/hub-creds).

Comment thread src/composeappmanager.cc Outdated
}

bool fetch(const std::string &app_uri) {
bool download(const std::string& app_uri);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not against breaking these out. However, it confused my eyes when I first saw this. Maybe you should create a change before this one that breaks out all the methods of ComposeApps to be like this. Then when you do this change it won't look so different from everything else.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I just moved it (download) to the private methods

@mike-sul mike-sul force-pushed the FF-160/download-docker-app branch from f89e4fa to 98d3a3c Compare May 26, 2020 19:17
@mike-sul
Copy link
Copy Markdown
Contributor Author

@doanac I removed the registry's configuration params. I didn't implement the auth request discovery as it requires changing in the aktualizr's HTTP client or developing our own, not sure if it's justifiable at the current moment provided that we don't support other than our Registry.

Comment thread src/composeappmanager.h

// TODO: restructure composeappmanager.* so it contains just the manager implemenation
// ComposeApp and Docker::* stuff should be moved into separate source files

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree. I think a docker.cc file for the implementation would be nice. This is only going to grow in complexity.

@mike-sul
Copy link
Copy Markdown
Contributor Author

Checked this branch on RPi and QEMU, it looks like it works as expected.

Comment thread src/composeappmanager.cc Outdated
docker_prune = val != "0" && val != "false";
}

// Docker Registry Configuration (TODO: to be removed)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we just remove this stuff and hard-code it in getBasicAuthHeader() where we already have the big TODO's? I'm hoping this will never leak into someone's sota.toml. Or do you need someway to intercept things for unit tests?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What about the on-premises deployment? In this case, the base URL will be different than 'https://ota-lite.foundries.io:8443'.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ugh - your right. l guess we should keep the logic that discovers it - lets drop the config value method though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What is the config value method?
I guess you mean that we just deduce the auth base url from ostree_server url and append hub-creds to it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

correct. we deduce from ostree_server

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removing the ability to configure the auth URL and just deducting it from the ostree/treehub URL is fine.
But, removing this param auth_creds_endpoint and moving the deduction logic in getBasicAuthHeader is not fine. First of all, we need to pass at least one param to RegistryClient anyway (either the treehub URL or already deducted auth URL), secondly if we do deduction in getBasicAuthHeader then we will do it for each request while this URL is static and should be evaluated once at startup.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ack.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

@doanac
Copy link
Copy Markdown
Member

doanac commented May 27, 2020

i think this looks pretty good now. Here's how i think we should proceed to merge:

  1. lets do a new PR to foundriesio/aktualizr to pull in the Docker fix. ie to do a [fiofromlist] patch with advancedtelematic/aktualizr@85776e8

  2. lets do a new PR to aktualizr-lite that:
    a) pulls in the new foundriesio/aktualizr
    b) fixes whitespace

  3. update this PR or do a new PR with this stuff minus all the other noise.
    i think breaking out the new docker stuff into docker.[h/cc] files would be great.

let me know if you need help with 1.

@mike-sul
Copy link
Copy Markdown
Contributor Author

3. update this PR or do a new PR with this stuff minus all the other noise.

I opt for a new PR, this one has already too many changes.

@mike-sul
Copy link
Copy Markdown
Contributor Author

I suppose we need to make corresponding changes in lmp-device-register to configure aklite/sota.toml with compose_apps package manager.

@doanac
Copy link
Copy Markdown
Member

doanac commented May 27, 2020

I suppose we need to make corresponding changes in lmp-device-register to configure aklite/sota.toml with compose_apps package manager.

eventually. i think we are a few weeks away from that. we need to first get everyone's personal factories using this (and we can update the fioctl devices config updates command to move each device) first. once everyone is using it and happy we can make this the new default.

we'll also have to update the partner-setup repo to define things using docker-compose rather than .dockerapp

@mike-sul
Copy link
Copy Markdown
Contributor Author

eventually. I think we are a few weeks away from that.

Why not create a branch and PR right now, so we can test the end-to-end flow as it would happen in real-life starting from bitbaking.

@doanac
Copy link
Copy Markdown
Member

doanac commented May 27, 2020

that's fine.

@mike-sul mike-sul force-pushed the FF-160/download-docker-app branch from 761dbe8 to 728c0d3 Compare May 27, 2020 18:51
@mike-sul
Copy link
Copy Markdown
Contributor Author

I rebased this branch on foundriesio/aktualizr#38 and removed the commit that introduces customer docker container for testing.

@doanac doanac marked this pull request as ready for review May 28, 2020 03:39
@doanac
Copy link
Copy Markdown
Member

doanac commented May 28, 2020

looks good.

@mike-sul mike-sul merged commit c3bc433 into master May 28, 2020
@mike-sul mike-sul deleted the FF-160/download-docker-app branch May 28, 2020 07:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants