Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Images handling app for c2c.org v6

License

NotificationsYou must be signed in to change notification settings

c2corg/v6_images

Repository files navigation

GitHub licenseBuild statusGithub Code scanningTotal alertsLanguage grade: PythonKnown Vulnerabilities

This project handles receiving images from the user and generating smallerversions. It is using docker to be able to run it either together with theAPI machine or on a separate machine.

Upload

The original image uploaded by the user is:

  • optionally rotate the image according to the EXIF orientation value
  • uniquely renamed using a timestamp and random number;
  • stored locally in an "incoming" directory;
  • converted to smaller sizes.

The image is uploaded immediately to S3.The user receives the renamed filename.

Activation

The user associates the filename to a document, which is stored in the API.At that time, a request is sent to image backend to move original and resizedimages from the incoming bucket to the public bucket. This step ensures theimage is associated with an authenticated user.

Configuration

Configuration should be set by environment variables:

STORAGE_BACKEND: (required)s3 orlocal

  • s3: requiresINCOMING_BUCKET andACTIVE_BUCKET, should be used inproduction.
  • local: requiresINCOMING_FOLDER andACTIVE_FOLDER, should be usedfor tests and development.

TEMP_FOLDER: (required) Local folder to store images temporarily.

INCOMING_FOLDER: Local folder for incoming files.

ACTIVE_FOLDER: Local folder for active files.

INCOMING_BUCKET: Name bucket for incoming files.

INCOMING_PREFIX: Prefix of the incoming bucket connection options.

ACTIVE_BUCKET: Name bucket for active files.

ACTIVE_PREFIX: Prefix of the active bucket connection options.

PREFIX_ENDPOINT: Endpoint url for corresponding prefix.

PREFIX_ACCESS_KEY_ID: API key for corresponding prefix.

PREFIX_SECRET_KEY: Secret key for corresponding prefix.

PREFIX_DEFAULT_REGION: Default region for corresponding prefix.

S3_SIGNATURE_VERSION: S3 signature version ('s3' or 's3v4'), seedocs.

API_SECRET_KEY: API secret key, needed to publish images on the activebucket.

V5_DATABASE_URL: Address of the V5 database for the migration script.

ROUTE_PREFIX: Path prefix for serving the photo backend API.

RESIZING_CONFIG: Configuration of the thumbnail names and sizes serialized in JSON. See c2corg_images/init.py for a description of the format.

AUTO_ORIENT_ORIGINAL:1 to rotate the uploaded image according to the EXIF orientation. Default is0.

CACHE_CONTROL: Cache-Control value to be set to all the images uploaded to s3. Default ispublic, max-age=3600.

Here is an example configuration with S3 backend on exoscale:

STORAGE_BACKEND: s3TEMP_FOLDER: /srv/images/tempINCOMING_FOLDER:ACTIVE_FOLDER:INCOMING_BUCKET: c2corg_demov6_incomingINCOMING_PREFIX: EXOACTIVE_BUCKET: c2corg_demov6_activeACTIVE_PREFIX: EXOEXO_ENDPOINT: https://sos.exo.ioEXO_ACCESS_KEY_ID: xxxEXO_SECRET_KEY: xxxAPI_SECRET_KEY: xxxV5_DATABASE_URL: postgresql://www-data:www-data@postgres/c2corg

Cleaning

The files which were not activated are automatically expired by S3.

Building and running with Docker

make run

Launch images migration from V5 to V6

The migration retrieves a list of images from the v5 database. The connectionto the database can be defined as environment variable, for example:

V5_DATABASE_URL: postgresql://www-data:www-data@postgres/c2corg

The migration script iterates through v5 images. For eachoriginal imagefound:

  • If the image already exists in publication bucket, nothing is done (onlymigrate the new ones).
  • If the image does not exists in the v6 bucket:
    • theoriginal image is copied locally,
    • resized images are produced according to configuration,
    • original andresized images are pushed on publication bucket.

To run the migration script:

docker-compose exec images migrate

docker-compose exec images migrate --help to get options list.

Generateresized images after migration

This can be used to change the size or quality ofresized images.

This script iterates throughpublished images. For eachoriginal imagefound:

  • theoriginal image is copied locally,
  • resized images are produced according to configuration,
  • resized images are pushed in publication bucket, overwriting old ones.

To regenerate theresized images:

docker-compose exec images resize

docker-compose exec images resize --help to get options list.

Release on docker hub

The project is built by Github actions.


[8]ページ先頭

©2009-2025 Movatter.jp