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

Host docker image on dockerhub #404

Closed
MathiasVDA opened this issue Oct 13, 2023 · 10 comments
Closed

Host docker image on dockerhub #404

MathiasVDA opened this issue Oct 13, 2023 · 10 comments
Labels
Improvement Doing the same thing but better
Milestone

Comments

@MathiasVDA
Copy link
Member

Hello,

This project is really exiting! I found out about it this week. I was a bit dissapointed when I couldn't find any docker image on dockerhub.

I prefer to work with docker containers to avoid dependency issues.

The development version of the dockerfile takes a long time to build and deploy. Therefor I've made a pull request that is based on the latest release.

However, it would be even better if you could set up a pipeline that automatically deploys an image (both release and development) on dockerhub.

@enridaga
Copy link
Member

Thanks! Automating docker hub releases as part of the workflow would be cool. Would you happen to know how to do that or where we should look into to start?

@MathiasVDA
Copy link
Member Author

MathiasVDA commented Oct 16, 2023

It's pretty straight forward. Lots of repo's on github do it and I see there is very good documentation available:
https://docs.github.com/en/actions/publishing-packages/publishing-docker-images

I could offer some assistence to this but I think what you need to do is:

  • Create an official dockerhub account for sparql-anything
  • Save the credentials in the settings/secrets & variables/actions page of your repo
  • Create a new action based on the template in the link above

If you use the template, the action trigger is a new release:

on:
  release:
    types: [published]

You could also add additional actions, for example, push a development version at every merge with the main branch, or in your v0.9-dev branch.

I've tried to do this on my fork of your repository and following my instructions above it seems to work:
https://github.com/MathiasVDA/sparql.anything/actions/runs/6537743045
https://hub.docker.com/r/vbp8501mvda/sparql-anything/tags

However, you'll want to create a dockerfile that doesn't download the release jar file but one that will build the project itself obviously. The dockerfile should be a little similar to your dockerfile.development but I would create one that completely sets up the project so that you don't have to setup a lot of things when running the container first time.

@enridaga
Copy link
Member

Nice, we can automate the dockerhub deployment on releases, then. We need to remember to set the right version number in the docker file at the time of the tag is created, or try to find a way to derive that from the release number.

To do the same with a development version, we need to build the executable and put it somewhere, which may be complicated (at the moment, we don't build runnable jars with the java maven actions, for example).

@MathiasVDA
Copy link
Member Author

I've created a dockerfile and edited all the pom.xml files in order to do this automatically. It's in the new merge request.

Github has an env called GITHUB_REF that is equal to the release name. I've used this to set the project version in the pom files. Github also automatically assigns the release name to the docker image tag, as well as updates the latest tag.

The new dockerfile completely builds the project and handles the resulting server jar file. Some remarks:

  1. I've made it a two stage dockerfile to avoid having the source code in the resulting image and to speed up subsequent builds (as long as the pom files don't change, the first stage should be relatively quick). So you could also use it during development instead of a local build.
  2. I've taken care of some security. Not running the container as root. Which is pretty usefull if you want to run this on Openshift
  3. building the image outside of github pipeline, would look like this: docker build --build-arg GITHUB_REF=v1.2.3 .

And lastly, building the project outside of docker can be done in the usual way. The pom files have a default project version, so if you don't specify -Drevision=v1.2.3 in the mvn clean install, then it should default to v0.9.0-SNAPSHOT

@enridaga
Copy link
Member

This is really cool -- we can make intermediate / dev releases much more quickly... I will try a quick release now :)

@enridaga
Copy link
Member

Battling with a failed auth on push (weird, auth works on login):
https://github.com/SPARQL-Anything/sparql.anything/actions/runs/6585232498/job/17891257863#step:5:32591

enridaga added a commit that referenced this issue Oct 20, 2023
@enridaga
Copy link
Member

Just to double-check I understood this right.

Screenshot 2023-10-20 at 11 00 03 Screenshot 2023-10-20 at 10 59 55

@enridaga
Copy link
Member

Wait! I see the repo should include the username...

@enridaga
Copy link
Member

enridaga commented Oct 20, 2023

It works :)

Leaving this issue open so that we update the documentation #201

Another thing to keep in mind is that the convention for release tags has to change and conform with the pom version (0.9-DEV.1 instead of v0.9-DEV.1 -- without v).

@enridaga enridaga added the Improvement Doing the same thing but better label Oct 20, 2023
@enridaga enridaga added this to the v0.9.0 milestone Oct 20, 2023
@MathiasVDA
Copy link
Member Author

Glad it works :)

I'll see if I can help you automating the release artifacts as well. That way, when you create a tag, not only the docker image is pushed automatically but the jar files are also generated and attached to the release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Improvement Doing the same thing but better
Projects
None yet
Development

No branches or pull requests

2 participants