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

DockerHub fix #2 #3631

Merged
merged 19 commits into from
Aug 12, 2020
Merged

DockerHub fix #2 #3631

merged 19 commits into from
Aug 12, 2020

Conversation

aasifkhan7
Copy link
Contributor

Closes #3615

@cdrini Seems like DockerHub is itself able to pull the submodules before the any of the steps in Dockerfile are run (effectively doing git pulling of submodules before the docker build)

Hence another solution for this issue, in addition to #3628 might be to add a check - for the sake of checking if DockerHub has already recursively cloned the submodules, and run git submodule commands in git rule of Makefile only when vendor/infogami is empty implying that submodule hasn't yet been cloned (we could have chosen any of the 3 submodules for checking if they're empty, the choice of vendor/infogami is entirely random).

This seems a better fix to the DockerHub publishing issue rather than the related PR: #3628

I was able to build on publish the image on DockerHub using this.

@aasifkhan7 aasifkhan7 changed the title Dockerhub fix #2 DockerHub fix #2 Jul 27, 2020
@cclauss
Copy link
Contributor

cclauss commented Jul 28, 2020

In the current effort to port to Python 3 #3333 we want the flexibility to use the local infogami (whatever the current local checked out branch is in /vendor/local) or the branch that Python 2 production uses or the master branch that we are trying to get to be fully Python 3 compatible. This complication means that we might not always want the master branch of infogami. Hopefully, we can move quickly to a world where Python 2 is deprecated and we usually want the master branch of infogami.

@cdrini cdrini self-assigned this Aug 4, 2020
@cdrini
Copy link
Collaborator

cdrini commented Aug 5, 2020

Hey @aasifkhan7 , nice work! In docker hub, we can add build environment variables; we could define a DOCKER_HUB environment variable, which, if set, does not call make git! :) Then we could do something like this: https://github.com/internetarchive/openlibrary/compare/docker-test-hub to checkout the git submodules; not sure if that would work, but do you think you could give it a try? That helps us (1) avoid code duplication in #3628, and (2) limit the number of changes we have to make at to just docker hub files.

@@ -0,0 +1,2 @@
#!/bin/bash
export DOCKER_HUB=TRUE
Copy link
Contributor

Choose a reason for hiding this comment

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

Should TRUE be uppercase or lowercase?

On the csh or zsh command line, man true provides a man page but man TRUE does not.

Copy link
Contributor Author

@aasifkhan7 aasifkhan7 Aug 5, 2020

Choose a reason for hiding this comment

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

doesn't matter, I guess. ifneq is not a shell "command". I tried with even TRue and ifneq ($(DOCKER_HUB),TRue) - works good. (it's string matching, in my opinion)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we will be OK but try doing the same with false...

bash
$ if true == "true" ; then echo yes; fi
yes
$ if false == "false" ; then echo yes; fi
<nothing>

Copy link
Contributor Author

@aasifkhan7 aasifkhan7 Aug 5, 2020

Choose a reason for hiding this comment

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

tried with fAlse as well. works like string matching for that as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

In bash?!?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not in bash, but it's easier to write an if using ifeq() than figuring out its bash equivalent for the Makefile.

@aasifkhan7
Copy link
Contributor Author

aasifkhan7 commented Aug 5, 2020

@cdrini Added the environment variable and a build hook - docker/hooks/build.
Tested this and it builds successfully on Docker Hub as well as on local machine. (and it's cleaner than counting the files in vendor/infogami :) )

Copy link
Collaborator

@cdrini cdrini left a comment

Choose a reason for hiding this comment

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

Awesome! This is looking great :) A few things to test:

Try editing the Dockerfile.oldev to FROM aasifkhan7/olbase:latest (what is the link you're pushing to?), then try rebuilding web docker-compose build web and see if it runs! I think we might need to do the post_checkout hook as well as the build hook, because I don't believe the submodules get initialized at all otherwise. (The build won't fail if the submodules aren't initialized, but the site won't run :P)

docker/hooks/build Outdated Show resolved Hide resolved
Makefile Show resolved Hide resolved
Makefile Show resolved Hide resolved
@cdrini cdrini added this to the Active Sprint milestone Aug 10, 2020
@cdrini
Copy link
Collaborator

cdrini commented Aug 11, 2020

Hi @aasifkhan7 ! I tried pulling and it worked 🤩 I also confirmed that vendor/infogami was defined inside the docker image.

Hmmm, IMAGE_NAME should be defined when this is built in docker hub. Are you running the build step on your computer, and then running docker push? Or have you set up an automatic build on docker hub?

@aasifkhan7
Copy link
Contributor Author

aasifkhan7 commented Aug 11, 2020

@cdrini I have setup automatic build on dockerhub - no pushing from my computer. 🙂
I created a repository named openlibrary - and it built the image with the name martiansoul/openlibrary by default.
For central DockerHub repositories - we can have a user openlibrary on Dockerhub and make a public repository with name olbase for olbase and oldev for oldev and so on.

@cdrini
Copy link
Collaborator

cdrini commented Aug 12, 2020

I was getting an error when trying this on my test repo; docker hub said:

Successfully built 49544179094f
Successfully tagged olbase:latest
Pushing index.docker.io/cdrini/openlibrary-base:docker-test-gitfix...
Push failed. Attempt 2 in 60 seconds.
Push failed. Attempt 3 in 60 seconds.
Push failed. Attempt 4 in 60 seconds.
Push failed. Attempt 5 in 60 seconds.
{u'message': u'An image does not exist locally with the tag: cdrini/openlibrary-base'}

I'm trying changing the build hook right now 👍

@cdrini
Copy link
Collaborator

cdrini commented Aug 12, 2020

You can set the image name (e.g. olbase) and tags (e.g. latest) from the dockerhub UI; that's what the IMAGE_NAME is for. I'm going to see if we can actually remove the build hook entirely; the Makefile changes might be enough to make this work. I can set environment variables from the docker hub UI:

image

That might be enough!

@cdrini
Copy link
Collaborator

cdrini commented Aug 12, 2020

Didn't work :/ Looks like that doesn't set it during build for some reason. Going to try changing build hook to use IMAGE_NAME

@cdrini
Copy link
Collaborator

cdrini commented Aug 12, 2020

That did it! First successful build 🎉
image

This is needed in order to let us set the build name/tag and dockerfile path from the docker hub UI.

See https://docs.docker.com/docker-hub/builds/advanced/#environment-variables-for-building-and-testing
Copy link
Collaborator

@cdrini cdrini left a comment

Choose a reason for hiding this comment

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

Lgtm; tested it builds the image, and that the built image can run (not the latest iteration, but a recent one).

@cdrini cdrini merged commit 61096f2 into internetarchive:master Aug 12, 2020
@cdrini
Copy link
Collaborator

cdrini commented Aug 12, 2020

Here's the docker hub repo; I'll test a little more, and if it works, update the docs!

https://hub.docker.com/r/openlibrary/olbase

@cclauss
Copy link
Contributor

cclauss commented Aug 12, 2020

Awesome work here!! Well done @aasifkhan7

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.

Add docker image to docker hub
3 participants