ServiceWeaver / weaver-kube

Run Service Weaver applications on vanilla Kubernetes.
Apache License 2.0
61 stars 19 forks source link

Automatically infer Docker Hub username. #21

Closed mwhittaker closed 1 year ago

mwhittaker commented 1 year ago

Before this PR, you had to pass weaver kube deploy your Docker Hub username using the SERVICEWEAVER_DOCKER_HUB_ID environment variable. This PR does a couple of things:

  1. It replaces the environment variable with a flag, --username.
  2. It automatically infers the username from the output of docker info. This username is established when you run docker login and is the username used when you docker push.
  3. It expands the help message of docker kube deploy to explain the use of Docker Hub usernames.
giautm commented 1 year ago

I don't know why we need use the docker username here. Why not just allow the user provider their docker image prefix? So, this:

fmt.Sprintf("%s/weaver-%s:tag%s", username, dep.App.Name, dep.Id[:8])

will becomes

fmt.Sprintf("%s%s:tag%s", imagePrefix, dep.App.Name, dep.Id[:8])

And, tada, we support Google CR with: IMAGE_PREFIX=LOCATION-docker.pkg.dev/PROJECT-ID/REPOSITORY/IMAGE?

mwhittaker commented 1 year ago

@giautm, I think that's a great idea! We should definitely move towards something that lets people specify where to upload the container.

Srdjan was mentioning this up above, do you know how this would interact with docker login? Like, if I docker login into Docker Hub but then try to docker push to Google Artifact Registry, would docker push fail? Or can you be logged in to multiple registries at once? I'm not super familiar with docker, so I'm not sure how this works.

giautm commented 1 year ago

@mwhittaker: docker info doesn't work on my end. it doesn't report the username anymore. Please revert this changes. :(

https://stackoverflow.com/a/58795217

docker info
Client:
 Version:    24.0.2
 Context:    orbstack
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.11.0
    Path:     /Users/giautm/.docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.18.1
    Path:     /Users/giautm/.docker/cli-plugins/docker-compose

Server:
 Containers: 24
  Running: 14
  Paused: 0
  Stopped: 10
 Images: 44
 Server Version: 24.0.2
 Storage Driver: overlay2
  Backing Filesystem: btrfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 1677a17964311325ed1c31e2c0a3589ce6d5c30d
 runc version: 860f061b76bb4fc671f0f9e900f7d80ff93d4eb7
 init version:
 Security Options:
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.3.8-orbstack-00160-g7d081b6f2c97
 Operating System: OrbStack
 OSType: linux
 Architecture: aarch64
 CPUs: 10
 Total Memory: 5.132GiB
 Name: docker
 ID: ac48e8ff-a3a7-41bb-b368-6a1012adb137
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false
 Default Address Pools:
   Base: 198.19.192.0/19, Size: 23
   Base: 198.19.224.0/20, Size: 23
   Base: 172.17.0.0/16, Size: 16
   Base: 172.18.0.0/16, Size: 16
   Base: 172.19.0.0/16, Size: 16
   Base: 172.20.0.0/14, Size: 16
   Base: 172.24.0.0/14, Size: 16
   Base: 172.28.0.0/14, Size: 16
   Base: 192.168.0.0/16, Size: 20
mwhittaker commented 1 year ago

Oops 🤦

spetrovic77 commented 1 year ago

I don't know why we need use the docker username here. Why not just allow the user provider their docker image prefix? So, this:

fmt.Sprintf("%s/weaver-%s:tag%s", username, dep.App.Name, dep.Id[:8])

will becomes

fmt.Sprintf("%s%s:tag%s", imagePrefix, dep.App.Name, dep.Id[:8])

And, tada, we support Google CR with: IMAGE_PREFIX=LOCATION-docker.pkg.dev/PROJECT-ID/REPOSITORY/IMAGE?

@giautm, WDYT about figuring out the registry URL somehow using the docker command (i.e., the LOCATION-docker.pkg.dev/PROJECT-ID prefix in your example)? Then we can assume a fixed REPOSITORY path and can auto-generate IMAGE. That way the user doesn't have to provide IMAGE_PREFIX, which is gnarly IMO.

giautm commented 1 year ago

@spetrovic77 : empty IMAGE_PREFIX mean docker will trying to push to the default registry (docker hub) with the currently login user. So, if the app named as "foobar". It will push the image to giautm/foobar. It's safe to push image without any prefix.

giautm commented 1 year ago

We don't need to care about the registry with the image name. Docker already handle all use case by itself, it auto parse the image name to find out which registry it need to push image to.

giautm commented 1 year ago

Doc for reference: https://docs.docker.com/engine/reference/commandline/tag/

spetrovic77 commented 1 year ago

Got it, that makes sense @giautm