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

Image uploader script #2164

Merged
merged 10 commits into from May 29, 2023
Merged

Image uploader script #2164

merged 10 commits into from May 29, 2023

Conversation

jprochazk
Copy link
Member

@jprochazk jprochazk commented May 17, 2023

Closes #2132

What

Adds just upload <image>, which uploads the image to google cloud using gsutil. The resulting URL contains the content hash plus the original file name, which ensures that it is unique.

$ just upload image.png
https://static.rerun.io/dd31922030a6bf7223d5e3728d8da5407f4d6b1a_image.png

The script itself contains instructions for how to setup gsutil. It's really just a link to Google's tutorial. Eventually it will be documented separately together with the rest of the new workflow.

Checklist

PR Build Summary: https://build.rerun.io/pr/2164

@jprochazk jprochazk added the 🧑‍💻 dev experience developer experience (excluding CI) label May 17, 2023
@jprochazk jprochazk marked this pull request as ready for review May 17, 2023 12:25
@jprochazk
Copy link
Member Author

Example image uploaded via this script: https://static.rerun.io/dd31922030a6bf7223d5e3728d8da5407f4d6b1a_minimal.png

scripts/upload_image.py Outdated Show resolved Hide resolved
justfile Outdated Show resolved Hide resolved
Upload an image to Google Cloud.

To use this:
- Install the Google Cloud CLI (https://cloud.google.com/storage/docs/gsutil_install)
Copy link
Member

@emilk emilk May 17, 2023

Choose a reason for hiding this comment

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

I installed it, and this is my reward:

❯  gsutil --help
ImportError: dlopen(/Users/emilk/.pyenv/versions/3.8.12/lib/python3.8/site-packages/_cffi_backend.cpython-38-darwin.so, 0x0002): symbol not found in flat namespace '_ffi_prep_closure'
thread '<unnamed>' panicked at 'Python API call failed', /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pyo3-0.15.2/src/err/mod.rs:582:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
  File "/Users/emilk/Downloads/google-cloud-sdk/bin/bootstrapping/gsutil.py", line 16, in <module>
    import bootstrapping
  File "/Users/emilk/Downloads/google-cloud-sdk/bin/bootstrapping/bootstrapping.py", line 50, in <module>
    from googlecloudsdk.core.credentials import store as c_store
  File "/Users/emilk/Downloads/google-cloud-sdk/lib/googlecloudsdk/core/credentials/store.py", line 34, in <module>
    from google.auth import external_account as google_auth_external_account
  File "/Users/emilk/Downloads/google-cloud-sdk/lib/third_party/google/auth/external_account.py", line 42, in <module>
    from google.auth import impersonated_credentials
  File "/Users/emilk/Downloads/google-cloud-sdk/lib/third_party/google/auth/impersonated_credentials.py", line 39, in <module>
    from google.auth import jwt
  File "/Users/emilk/Downloads/google-cloud-sdk/lib/third_party/google/auth/jwt.py", line 57, in <module>
    from google.auth import _service_account_info
  File "/Users/emilk/Downloads/google-cloud-sdk/lib/third_party/google/auth/_service_account_info.py", line 22, in <module>
    from google.auth import crypt
  File "/Users/emilk/Downloads/google-cloud-sdk/lib/third_party/google/auth/crypt/__init__.py", line 43, in <module>
    from google.auth.crypt import rsa
  File "/Users/emilk/Downloads/google-cloud-sdk/lib/third_party/google/auth/crypt/rsa.py", line 20, in <module>
    from google.auth.crypt import _cryptography_rsa
  File "/Users/emilk/Downloads/google-cloud-sdk/lib/third_party/google/auth/crypt/_cryptography_rsa.py", line 25, in <module>
    from cryptography.hazmat.primitives import serialization
  File "/Users/emilk/.pyenv/versions/3.8.12/lib/python3.8/site-packages/cryptography/hazmat/primitives/serialization/__init__.py", line 16, in <module>
    from cryptography.hazmat.primitives.serialization.base import (
  File "/Users/emilk/.pyenv/versions/3.8.12/lib/python3.8/site-packages/cryptography/hazmat/primitives/serialization/base.py", line 9, in <module>
    from cryptography.hazmat.primitives.asymmetric.types import (
  File "/Users/emilk/.pyenv/versions/3.8.12/lib/python3.8/site-packages/cryptography/hazmat/primitives/asymmetric/types.py", line 8, in <module>
    from cryptography.hazmat.primitives.asymmetric import (
  File "/Users/emilk/.pyenv/versions/3.8.12/lib/python3.8/site-packages/cryptography/hazmat/primitives/asymmetric/dsa.py", line 10, in <module>
    from cryptography.hazmat.primitives.asymmetric import utils as asym_utils
  File "/Users/emilk/.pyenv/versions/3.8.12/lib/python3.8/site-packages/cryptography/hazmat/primitives/asymmetric/utils.py", line 6, in <module>
    from cryptography.hazmat.bindings._rust import asn1
pyo3_runtime.PanicException: Python API call failed

god damn you python.

gcloud --help works though

Copy link
Member Author

@jprochazk jprochazk May 18, 2023

Choose a reason for hiding this comment

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

I changed the script to use the gcloud client library. If gcloud works, hopefully gcloud init should too, which should be enough to use this. Strange that the Rust bindings out of all things failed to install 🤔.

Copy link
Member

Choose a reason for hiding this comment

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

Sadly I still get the same error 😭

Copy link
Member Author

@jprochazk jprochazk May 22, 2023

Choose a reason for hiding this comment

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

How did you install it? I remember using apt (https://cloud.google.com/storage/docs/gsutil_install#deb)

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

You could try installing via brew install --cask google-cloud-sdk, I tried it on my mac and it seems to work

Copy link
Member

Choose a reason for hiding this comment

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

I tried the brew version now; same problem. I'll take a deeper look after the 0.6 release

@emilk
Copy link
Member

emilk commented May 17, 2023

It would be nice to run pngcrush -rem allb -brute -reduce on all pngs, but I guess that is something we can add later (and perhaps even do in batch on everything uploaded)

args = parser.parse_args()

hash = content_hash(args.path)
object_name = f"{hash}_{args.path}"
Copy link
Member

@emilk emilk May 25, 2023

Choose a reason for hiding this comment

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

Looks like if I do scripts/upload_image.py /Users/emilk/image.pg, that will result in a really bad object_name. I think we should just use the filename here, not the whole path

@jprochazk jprochazk requested a review from emilk May 25, 2023 09:43
@Wumpf Wumpf self-requested a review May 29, 2023 11:44
Copy link
Member

@Wumpf Wumpf left a comment

Choose a reason for hiding this comment

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

works like a charm for me :)

@Wumpf Wumpf merged commit e1f0e39 into main May 29, 2023
17 checks passed
@Wumpf Wumpf deleted the jan/upload-img branch May 29, 2023 11:47
emilk added a commit that referenced this pull request May 30, 2023
### What
I had problems running our image uploader script
(#2164) due to `gsutil` refusing
to work on my machine, however I installed it:

```
❯  gsutil --help
ImportError: dlopen(/Users/emilk/.pyenv/versions/3.8.12/lib/python3.8/site-packages/_cffi_backend.cpython-38-darwin.so, 0x0002): symbol not found in flat namespace '_ffi_prep_closure'
thread '<unnamed>' panicked at 'Python API call failed', /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pyo3-0.15.2/src/err/mod.rs:582:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
  File "/Users/emilk/Downloads/google-cloud-sdk/bin/bootstrapping/gsutil.py", line 16, in <module>
    import bootstrapping
  File "/Users/emilk/Downloads/google-cloud-sdk/bin/bootstrapping/bootstrapping.py", line 50, in <module>
    from googlecloudsdk.core.credentials import store as c_store
  File "/Users/emilk/Downloads/google-cloud-sdk/lib/googlecloudsdk/core/credentials/store.py", line 34, in <module>
    from google.auth import external_account as google_auth_external_account
  File "/Users/emilk/Downloads/google-cloud-sdk/lib/third_party/google/auth/external_account.py", line 42, in <module>
    from google.auth import impersonated_credentials
  File "/Users/emilk/Downloads/google-cloud-sdk/lib/third_party/google/auth/impersonated_credentials.py", line 39, in <module>
    from google.auth import jwt
  File "/Users/emilk/Downloads/google-cloud-sdk/lib/third_party/google/auth/jwt.py", line 57, in <module>
    from google.auth import _service_account_info
  File "/Users/emilk/Downloads/google-cloud-sdk/lib/third_party/google/auth/_service_account_info.py", line 22, in <module>
    from google.auth import crypt
  File "/Users/emilk/Downloads/google-cloud-sdk/lib/third_party/google/auth/crypt/__init__.py", line 43, in <module>
    from google.auth.crypt import rsa
  File "/Users/emilk/Downloads/google-cloud-sdk/lib/third_party/google/auth/crypt/rsa.py", line 20, in <module>
    from google.auth.crypt import _cryptography_rsa
  File "/Users/emilk/Downloads/google-cloud-sdk/lib/third_party/google/auth/crypt/_cryptography_rsa.py", line 25, in <module>
    from cryptography.hazmat.primitives import serialization
  File "/Users/emilk/.pyenv/versions/3.8.12/lib/python3.8/site-packages/cryptography/hazmat/primitives/serialization/__init__.py", line 16, in <module>
    from cryptography.hazmat.primitives.serialization.base import (
  File "/Users/emilk/.pyenv/versions/3.8.12/lib/python3.8/site-packages/cryptography/hazmat/primitives/serialization/base.py", line 9, in <module>
    from cryptography.hazmat.primitives.asymmetric.types import (
  File "/Users/emilk/.pyenv/versions/3.8.12/lib/python3.8/site-packages/cryptography/hazmat/primitives/asymmetric/types.py", line 8, in <module>
    from cryptography.hazmat.primitives.asymmetric import (
  File "/Users/emilk/.pyenv/versions/3.8.12/lib/python3.8/site-packages/cryptography/hazmat/primitives/asymmetric/dsa.py", line 10, in <module>
    from cryptography.hazmat.primitives.asymmetric import utils as asym_utils
  File "/Users/emilk/.pyenv/versions/3.8.12/lib/python3.8/site-packages/cryptography/hazmat/primitives/asymmetric/utils.py", line 6, in <module>
    from cryptography.hazmat.bindings._rust import asn1
pyo3_runtime.PanicException: Python API call failed
```

After a lot of googling [I found the
fix](https://levelup.gitconnected.com/fix-attributeerror-module-lib-has-no-attribute-openssl-521a35d83769):
`python3 -m pip install cryptography==38.0.4`

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)

<!-- This line will get updated when the PR build summary job finishes.
-->
PR Build Summary: https://build.rerun.io/pr/2278
emilk added a commit that referenced this pull request Jun 15, 2023
<!--
Open the PR up as a draft until you feel it is ready for a proper
review.

Do not make PR:s from your own `main` branch, as that makes it difficult
for reviewers to add their own fixes.

Add any improvements to the branch as new commits to make it easier for
reviewers to follow the progress. All commits will be squashed to a
single commit once the PR is merged into `main`.

Make sure you mention any issues that this PR closes in the description,
as well as any other related issues.

To get an auto-generated PR description you can put "copilot:summary" or
"copilot:walkthrough" anywhere.
-->

Closes #2132

### What

Adds `just upload <image>`, which uploads the image to google cloud
using `gsutil`. The resulting URL contains the content hash plus the
original file name, which ensures that it is unique.

```
$ just upload image.png
https://static.rerun.io/dd31922030a6bf7223d5e3728d8da5407f4d6b1a_image.png
```

The script itself contains instructions for how to setup `gsutil`. It's
really just a link to Google's tutorial. Eventually it will be
documented separately together with the rest of the new workflow.

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [ ] I've included a screenshot or gif (if applicable)

<!-- This line will get updated when the PR build summary job finishes.
-->
PR Build Summary: https://build.rerun.io/pr/2164

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
emilk added a commit that referenced this pull request Jun 15, 2023
### What
I had problems running our image uploader script
(#2164) due to `gsutil` refusing
to work on my machine, however I installed it:

```
❯  gsutil --help
ImportError: dlopen(/Users/emilk/.pyenv/versions/3.8.12/lib/python3.8/site-packages/_cffi_backend.cpython-38-darwin.so, 0x0002): symbol not found in flat namespace '_ffi_prep_closure'
thread '<unnamed>' panicked at 'Python API call failed', /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pyo3-0.15.2/src/err/mod.rs:582:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
  File "/Users/emilk/Downloads/google-cloud-sdk/bin/bootstrapping/gsutil.py", line 16, in <module>
    import bootstrapping
  File "/Users/emilk/Downloads/google-cloud-sdk/bin/bootstrapping/bootstrapping.py", line 50, in <module>
    from googlecloudsdk.core.credentials import store as c_store
  File "/Users/emilk/Downloads/google-cloud-sdk/lib/googlecloudsdk/core/credentials/store.py", line 34, in <module>
    from google.auth import external_account as google_auth_external_account
  File "/Users/emilk/Downloads/google-cloud-sdk/lib/third_party/google/auth/external_account.py", line 42, in <module>
    from google.auth import impersonated_credentials
  File "/Users/emilk/Downloads/google-cloud-sdk/lib/third_party/google/auth/impersonated_credentials.py", line 39, in <module>
    from google.auth import jwt
  File "/Users/emilk/Downloads/google-cloud-sdk/lib/third_party/google/auth/jwt.py", line 57, in <module>
    from google.auth import _service_account_info
  File "/Users/emilk/Downloads/google-cloud-sdk/lib/third_party/google/auth/_service_account_info.py", line 22, in <module>
    from google.auth import crypt
  File "/Users/emilk/Downloads/google-cloud-sdk/lib/third_party/google/auth/crypt/__init__.py", line 43, in <module>
    from google.auth.crypt import rsa
  File "/Users/emilk/Downloads/google-cloud-sdk/lib/third_party/google/auth/crypt/rsa.py", line 20, in <module>
    from google.auth.crypt import _cryptography_rsa
  File "/Users/emilk/Downloads/google-cloud-sdk/lib/third_party/google/auth/crypt/_cryptography_rsa.py", line 25, in <module>
    from cryptography.hazmat.primitives import serialization
  File "/Users/emilk/.pyenv/versions/3.8.12/lib/python3.8/site-packages/cryptography/hazmat/primitives/serialization/__init__.py", line 16, in <module>
    from cryptography.hazmat.primitives.serialization.base import (
  File "/Users/emilk/.pyenv/versions/3.8.12/lib/python3.8/site-packages/cryptography/hazmat/primitives/serialization/base.py", line 9, in <module>
    from cryptography.hazmat.primitives.asymmetric.types import (
  File "/Users/emilk/.pyenv/versions/3.8.12/lib/python3.8/site-packages/cryptography/hazmat/primitives/asymmetric/types.py", line 8, in <module>
    from cryptography.hazmat.primitives.asymmetric import (
  File "/Users/emilk/.pyenv/versions/3.8.12/lib/python3.8/site-packages/cryptography/hazmat/primitives/asymmetric/dsa.py", line 10, in <module>
    from cryptography.hazmat.primitives.asymmetric import utils as asym_utils
  File "/Users/emilk/.pyenv/versions/3.8.12/lib/python3.8/site-packages/cryptography/hazmat/primitives/asymmetric/utils.py", line 6, in <module>
    from cryptography.hazmat.bindings._rust import asn1
pyo3_runtime.PanicException: Python API call failed
```

After a lot of googling [I found the
fix](https://levelup.gitconnected.com/fix-attributeerror-module-lib-has-no-attribute-openssl-521a35d83769):
`python3 -m pip install cryptography==38.0.4`

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)

<!-- This line will get updated when the PR build summary job finishes.
-->
PR Build Summary: https://build.rerun.io/pr/2278
This was referenced Jun 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧑‍💻 dev experience developer experience (excluding CI)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Image uploader tool
4 participants