WhoIsHomeUI icon indicating copy to clipboard operation
WhoIsHomeUI copied to clipboard

Docker Hub image?

Open spandan13 opened this issue 2 years ago • 19 comments

Hi, are there any plans of pushing an image onto docker hub for this repo?

spandan13 avatar Aug 14 '22 04:08 spandan13

i second this, let's have a docker-hub image. I've made some externalisations like Timezone and port-number to a separate branch, you can have a look for ideas

https://github.com/babanomania/WhoIsHomeUI

babanomania avatar Aug 14 '22 09:08 babanomania

Thanks for your comments! How nice to see you guys are using and enjoying this!

I've never deployed anything to docker hub before so any help would definitely be welcome!

@babanomania I will have a look at your changes later on! I'm new to collaborating on github. Is there a simple way in which I can see the differences between our forks?

DartLazer avatar Aug 14 '22 09:08 DartLazer

@babanomania I've checked your work. First of all Thx! I think we can merge if you create a pull request.

I suggest the following changes:

docker-compose.yml line 23 replaced by: command: bash -c "python manage.py migrate --noinput && python3 manage.py loaddata static_data.json" (Otherwise it will give an error when trying to run multiple commands)

docker-compose.yml line 17 and onwards (for the depends on statement) replaced by: depends_on: - migration

On my docker-compose version your completed_succesfully gave an error. After checking online that call is not compatible with all docker-compose version hence better perhaps to leave it most compatable.

In the changelog maybe make it more clear on how to restore the data (I suggest putting it there as well) Change the recovery instructions to:

n.b - If you're upgrading from v0.17 to v0.18 or above your previous database will have to manually be reloaded because of the new database saving structure. You can follow the below commands to export data from previous db to new db path:

docker-compose run app cp db.sqlite3 /dbstore/db_whoih.sqlite3

My other suggestion is to not save the .env file as .env.sample but directly as .env. That way the code will just work straightaway when doing docker-compose up --build.

DartLazer avatar Aug 14 '22 11:08 DartLazer

@DartLazer thanks for the review and the comments. i'll definitely update these

also an FYI, i'm planning to have a discord based notification on my branch since i'm more into discord than emails. you don't necessarily have to merge them, i'll keep you posted how it goes.

babanomania avatar Aug 14 '22 11:08 babanomania

Thanks! Sounds cool if it doesn't create too much overhead we could definitely include that too!

How we do merge now? Do you need to create a pull request?

DartLazer avatar Aug 14 '22 11:08 DartLazer

@DartLazer i've created the pull request

https://github.com/DartLazer/WhoIsHomeUI/pull/4

babanomania avatar Aug 14 '22 12:08 babanomania

Thanks for looking into this!

spandan13 avatar Aug 14 '22 15:08 spandan13

Thanks for looking into this!

No worries. I don't use docker hub. What would be advantages of that? Could you fork and create the necessities and we could merge?

DartLazer avatar Aug 14 '22 15:08 DartLazer

A docker hub image would allow a simple one command deployment of the app instead of having to pull the repo and building locally. There's nothing extra to be added to the repo for pushing to docker. You'd just have to build the image locally once and then push to docker hub using their push command. Earlier today I did actually fork and push an image to docker hub based on your current repo and was able to deploy it successfully on another machine. ( My Fork and My Docker Hub Image ) The only issue is that since in the current version the database file is not externalised so if one was to re-deploy the container then they'd loose all data. I guess once you get the database file and timezones externalised with the help of @babanomania then we should be good to go with pushing the file to docker hub.

spandan13 avatar Aug 14 '22 17:08 spandan13

So we should be good to go!?

DartLazer avatar Aug 18 '22 16:08 DartLazer

I think we're good to go, let's have an docker image now. The installation instructions should be updated to run the application using just the docker image

babanomania avatar Aug 18 '22 17:08 babanomania

For the upgrade to happen automatically, the docker images should be tagged with an version number

babanomania avatar Aug 18 '22 17:08 babanomania

Cool I dont have anymore time tonight feel free to work on it and we can merge it into dev or another branch😁

DartLazer avatar Aug 18 '22 17:08 DartLazer

I found this tutorial to create docker images with version number

https://betterprogramming.pub/how-to-version-your-docker-images-1d5c577ebf54

And this is a guide in how to manager versioned image updates via docker-compose

https://www.howtogeek.com/devops/how-to-upgrade-docker-containers-to-apply-image-updates/

We should prepare the installation and update instructions accordingly

babanomania avatar Aug 18 '22 17:08 babanomania

I think we're good to go, let's have an docker image now. The installation instructions should be updated to run the application using just the docker image

Perhaps we could keep instructions for both methods just in case someone wants to build locally for some reason

I'll also take a look at trying to create a docker image tomorrow

spandan13 avatar Aug 18 '22 17:08 spandan13

@DartLazer @spandan13

i was testing some commands with multi-arch build, below are the image sizes for arm, seems pretty small so far

image

below is the command i used

docker buildx create --use
docker buildx build --push --platform linux/arm/v6,linux/arm/v7,linux/arm/v8,linux/amd64 -t <username>/<reponame>:<tag> .

https://hub.docker.com/repository/registry-1.docker.io/babanomania/whoishome/general

babanomania avatar Aug 20 '22 07:08 babanomania

now that the test container is pushed, i just need the below docker-compose.yml file and the .env file only

version: "3.8"

services:
  web:
    network_mode: "host"
    image: babanomania/whoishome:slim
    command: sh -c "python manage.py migrate --noinput && python manage.py runserver 0.0.0.0:${WHOIH_PORT:-8000}"
    environment:
      - DJANGO_TZ=${WHOIH_TZ}
      - DJANGO_DBPATH=/dbstore/db.sqlite3
    restart: always
    volumes:
      - dbstore:/dbstore

  scanner:
    network_mode: "host"
    image: curlimages/curl
    command: sh -c "sleep 60s && curl -s http://0.0.0.0:${WHOIH_PORT}/scan/"
    restart: always

volumes:
  dbstore:

babanomania avatar Aug 20 '22 07:08 babanomania

now that the test container is pushed, i just need the below docker-compose.yml file and the .env file only

This is amazing! Is it possible to set env variables directly in the compose file so that we can deploy the app using something like portainer as well?

Edit: My bad, Portainer does have an option to load .env files

spandan13 avatar Aug 20 '22 08:08 spandan13

Any way we could still realize this?

DartLazer avatar Aug 23 '23 11:08 DartLazer