Remote Worker

Related tags

Miscellaneous remote
Overview

Remote Worker

Separation of Responsibilities

There are several reasons to move some processing out of the main code base for security or performance:

  • If there is a security exploit in the image processing library, it will only impact this remote worker
  • If you need to send some network requests (e.g., link previewing) to a third party, running those tasks on separate servers to prevent leaking the IP addresses of the main web instances
  • If some processing does not rely on the other part of the main code base, then you can move them into the remote worker for better performance

Python Version

This project should always be using the latest version of Python. At the time of this writing, it is 3.10.0. You can install it via pyenv.

We included a pre-commit config to ensure code quality and consistency.

Ubuntu Packages

These packages are required for manipulating images:

sudo apt install libimage-exiftool-perl jhead libmagic-dev

When developing on macOS, you can install those packages with Homebrew:

brew install exiftool jhead

Endpoints

images/prepare_jpeg

Accepts a multipart/form-data request with the following parameters:

- file: the image to process

Two processes are performed on the image:

  • Remove GPS info from EXIF metadata
  • Adjust the orientation of the image to make it work in browsers that don't support EXIF orientation

images/fit/:box

Accepts a multipart/form-data request with the following parameters:

- file: the image to process

Returns a new image that fits within the given box, and the image's aspect ratio is preserved.

images/rescale_avatar

Accepts a multipart/form-data request with the following parameters:

- file: the image to process

Return a JSON object with the processed versions of the image:

- avatar24: a 24x24 version of the image
- avatar48: a 48x48 version of the image
- avatar73: a 73x73 version of the image
- avatar128: a 128x128 version of the image if the original image is larger than 128x128
- avatar256: a 256x256 version of the image if the original image is larger than 256x256
- avatar512: a 512x512 version of the image if the original image is larger than 512x512

These original image formats are supported:

  • JPEG
  • PNG
  • GIF
  • BMP
  • TIFF
  • WEBP

The output format is always in PNG.

curl example for sending such a request:

curl -X POST -F "file=@/path/to/image.jpg" http://localhost:5000/images/rescale_avatar
Comments
  • UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7f5a1061c310>

    UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7f5a1061c310>

    Sentry Issue: REMOTE-1D

    UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7f5a1061c310>
      File "app.py", line 431, in resize_avatar
        base_avatar = Image.open(io.BytesIO(base_avatar_data))
      File "PIL/Image.py", line 3030, in open
        raise UnidentifiedImageError(
    
    opened by sentry-io[bot] 11
  • Add CI to build and push image

    Add CI to build and push image

    related #19

    First of all, this is same as that PR about blueprint, I'm not sure if this is what you want, please feel free let me know if not fit. ☺️

    1. Create a Github Token . Github Action should have permission to publish the image, we generate this token first, and make sure it has write:packages permission.

    2. Add token generated on step 1 to remote repo secrets . So that we can use it on Github Action, pls named it as PACKAGES_TOKEN(I call it this in ci.yaml for now).

    3. Merge to run CI.

    4. Push to GHCR by Github Action. If everything is ok, at first time, CI will publish a new private image to GHCR, we can change it to public later.

    opened by luxiaba 10
  • Avatar update issue

    Avatar update issue

    It seems there is still a problem when updating the avatar. I tried just now and got a error: 图片处理没有成功,请重试一次, maybe you can find more details on sentry, if there is anything I need to update, please feel free to let me know : (

    opened by luxiaba 10
  • Test for AVIF is not working in PR #26

    Test for AVIF is not working in PR #26

    With the current implementation, to recognize an image, it needs to be both recognized by libmagic and Pillow. And that caused test for AVIF to fail. Because while Pillow.Image can recognize it:

    Screen Shot 2021-12-14 at 7 07 43 AM

    But libmagic cannot:

    Screen Shot 2021-12-14 at 7 08 15 AM

    If Pillow.Image can return a meaningful result, libmagic should not block the process.

    opened by livid 8
  • Add support to rescale animated PNG(APNG)/GIF/WEBP

    Add support to rescale animated PNG(APNG)/GIF/WEBP

    PNG(APNG)

    • [X] Animated input
    • [ ] Correctly setting (resized) default image for generated content
    • [ ] Compression size check
    • [ ] BUG: output can be broken even the frames themselves are properly processed
    • [X] Animated output

    GIF

    • [X] Animated input
    • [X] ~~Investigate if pasted additive frame needs to be aligned according to GIF tile info~~ Partial frames seem to be deprecated
    • [X] Animated output

    WEBP

    • [X] Animated input
    • [X] Animated output

    Functions

    • [X] Animated controlled by URL search parameter ?animated=1
    • [X] Support for avatar
    • [X] Support for resize (fit)
    • [ ] Cleanup
    opened by stdc105 6
  • Use Codecov to display test coverage automatically

    Use Codecov to display test coverage automatically

    Maybe we can use Codecov to automatically handle the test coverage.

    Use this action to integrate into CI, then we can add a bagde into readme to display test coverage automatically, should I open a PR for this?

    opened by luxiaba 4
  • Unified processing process

    Unified processing process

    • Separate the processing process to remote.utilities.image, keep biz code clear and simple:
      1. According to MIME, converted to a type supported by PIL(such as svg).
      2. Try to load to PIL.Image.
      3. For some types, do some preprocess for later operations.
    • A well-supported MIME type (remote.utilities.image.imagemime).
    • Add avif and icon type tests.
    opened by luxiaba 2
  • Project structure adjustment

    Project structure adjustment

    The app.py will become bigger if there are other functions to be added in the future, if so it'll become hard to read and maintain later.

    Have you think about adjusting the structure? for example create some utils/exceptions/init/... and put them into a package to let main code separate from the configuration file and keep the structure of the main project simple and clear.

    Or you're prefer the structure of one function one file? for now, image processing is a file, and there may be another file like weather.py for weather inquiry in the future?

    opened by luxiaba 2
  • Organize codes using flask blueprint

    Organize codes using flask blueprint

    related #16

    I made some changes to the project structure, mainly is using blueprint to organize the code mentioned before, but I'm not sure whether it conflicts with your code style. but don't worry, even if it doesn't fit, I think my future projects may use this :), the main changes are as follows:

    • A remote package was created to separate the configuration files(eg: flake8 / bandit / dockerfile / ...) with the biz code. It should be noted that the position of configuration file(config.py / config.example.py should be moved to the `remote' directory).

    • The app.py are split into three blueprints(index_bp / image_bp /network_bp) and placed in the remote/blueprints/ directory, I try to make them look independent of each other, each blueprint only import

      1. the built-in modules.
      2. third-party packages.
      3. some common methods in projects(APIError / success / error / ...).
    • Adjusted the app startup process. See remote/app.py for more details.

    • Adjusted the structure of the test. it corresponds to the structure of the biz code, i think is convenient to organize and maintain later.

    • During the test, I found that dockerfile has missing some dependencies, and it didn't run successfully in my test, so I added the some dependencies (gcc / libavif-dev) and simply adjusted the structure.

    opened by luxiaba 1
  • Add test inside container

    Add test inside container

    related #19

    I refer to an example script of docker official, then add a test process to the CI. The current process is:

    build image -> pytest in container -> push to hub

    I added a test script(tests/ci_test.sh) to reference it conveniently in CI to execute the test process.

    The image we build only contains the minimum data needed for running, so when testing in the container, I actively mounted the test data to use, but don't worry that it has no effect on the image itself.

    opened by luxiaba 0
  • OSError: no library called

    OSError: no library called "cairo-2" was found

    cairo is the dependency for SVG support. However, when I installed it on macOS via brew, its Python library had difficulty finding it:

    Screen Shot 2021-12-17 at 10 43 07 AM

    Probably due to SIP or some other reason I currently do now know, modifying DYLD or LD environment variables cannot do the trick. Now I had to link the dylib from opt to usr/local:

    sudo ln -s /opt/homebrew/lib/libcairo.2.dylib /usr/local/lib/
    

    I wonder if there is a better way to handle this on macOS 12.

    opened by livid 1
Find the remote website version based on a git repository

versionshaker Versionshaker is a tool to find a remote website version based on a git repository This tool will help you to find the website version o

Orange Cyberdefense 110 Oct 23, 2022
Package pyVHR is a comprehensive framework for studying methods of pulse rate estimation relying on remote photoplethysmography (rPPG)

Package pyVHR (short for Python framework for Virtual Heart Rate) is a comprehensive framework for studying methods of pulse rate estimation relying on remote photoplethysmography (rPPG)

PHUSE Lab 261 Jan 3, 2023
Remote execution of a simple function on the server

FunFetch Remote execution of a simple function on the server All types of Python support objects.

Decave 4 Jun 30, 2022
Module for remote in-memory Python package/module loading through HTTP/S

httpimport Python's missing feature! The feature has been suggested in Python Mailing List Remote, in-memory Python package/module importing through H

John Torakis 220 Dec 17, 2022
Backup dc registry - A simple POC that abuses Backup Operator privileges to remote dump SAM, SYSTEM, and SECURITY

Backup Operator Registry Backup to Domain Compromise A simple POC that abuses Ba

Horizon 3 AI Inc 57 Dec 18, 2022
Mr. Queue - A distributed worker task queue in Python using Redis & gevent

MRQ MRQ is a distributed task queue for python built on top of mongo, redis and gevent. Full documentation is available on readthedocs Why? MRQ is an

Pricing Assistant 871 Dec 25, 2022
A simple worker for OpenClubhouse to sync data.

OpenClubhouse-Worker This is a simple worker for OpenClubhouse to sync CH channel data.

null 100 Dec 17, 2022
Here is the live demonstration of endpoints and celery worker along with RabbitMQ

whelp-task Here is the live demonstration of endpoints and celery worker along with RabbitMQ Before running the application make sure that you have yo

Yalchin403 0 Nov 14, 2021
Auto locust load test config and worker distribution with Docker and GitHub Action

Auto locust load test config and worker distribution with Docker and GitHub Action Install Fork the repo and change the visibility option to private S

Márk Zsibók 1 Nov 24, 2021
An alternative to OpenFaaS nats-queue-worker for long-running functions

OpenFaas Job Worker OpenFaas Job Worker is a fork of project : OSCAR Worker - https://github.com/grycap/oscar-worker Thanks to Sebástian Risco @srisco

Sebastien Aucouturier 1 Jan 7, 2022
MPV remote controller is a program for remote controlling mpv player with device in your local network through web browser.

MPV remote controller is a program for remote controlling mpv player with device in your local network through web browser.

null 5 May 26, 2022
Simple, Pythonic remote execution and deployment.

Welcome to Fabric! Fabric is a high level Python (2.7, 3.4+) library designed to execute shell commands remotely over SSH, yielding useful Python obje

Fabric 13.8k Jan 6, 2023
Remote task execution tool

Gunnery Gunnery is a multipurpose task execution tool for distributed systems with web-based interface. If your application is divided into multiple s

Gunnery 747 Nov 9, 2022
RPyC (Remote Python Call) - A transparent and symmetric RPC library for python

RPyC (pronounced like are-pie-see), or Remote Python Call, is a transparent library for symmetrical remote procedure calls, clustering, and distribute

null 1.3k Jan 5, 2023
Exploit Discord's cache system to remote upload payloads on Discord users machines

Exploit Discord's cache system to hide payloads PoC Remote upload embedded payload from image using EOF to Discord users machines through cache. Depen

cs 169 Dec 20, 2022
A Python library to simulate a Zoom H6 recorder remote control

H6 A Python library to emulate a Zoom H6 recorder remote control Introduction This library allows you to control your Zoom H6 recorder from your compu

Matias Godoy 68 Nov 2, 2022
Arbitrium is a cross-platform, fully undetectable remote access trojan, to control Android, Windows and Linux and doesn't require any firewall exceptions or port forwarding rules

About: Arbitrium is a cross-platform is a remote access trojan (RAT), Fully UnDetectable (FUD), It allows you to control Android, Windows and Linux an

Ayoub 861 Feb 18, 2021
Mockoon is the easiest and quickest way to run mock APIs locally. No remote deployment, no account required, open source.

Mockoon Mockoon is the easiest and quickest way to run mock APIs locally. No remote deployment, no account required, open source. It has been built wi

mockoon 4.4k Dec 30, 2022
SSH tunnels to remote server.

Author: Pahaz Repo: https://github.com/pahaz/sshtunnel/ Inspired by https://github.com/jmagnusson/bgtunnel, which doesn't work on Windows. See also: h

Pavel White 1k Dec 28, 2022