Tooling for managing asset compression, storage, and retrieval
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

200 lines
6.2 KiB

  1. Asset Compression Manager (ACM)
  2. ========================
  3. ## About
  4. This tool exists to help compress, store, retrieve and validate media for games. The goal is to provide a simple workflow for checking assets for changes, generating new compressed versions based on those changes, storing those changed versions, and retrieving compressed files.
  5. This tool is designed to work with an S3 compatible bucket storage provider.
  6. ## Requirements
  7. - An S3 Compatible Storage Service
  8. - Python 3.7+
  9. - MozJpeg for jpeg compression
  10. - OptiPNG for png optimization
  11. - FFMpeg for video compression and audio decompression
  12. - Opusenc for audio compression
  13. ## Using
  14. ### Configuring
  15. ACM expects a configuration file specified with `--config` or as `acm-config.json` in the current directory.
  16. The S3 compatible endpoint needs to be configured in the `s3` object of the configuration file.
  17. ```json
  18. {
  19. "s3": {
  20. "secure": false,
  21. "host": "127.0.0.1:9000"
  22. }
  23. }
  24. ```
  25. - `secure` - specifies if __*https*__ protocol is used.
  26. - `host` - is the \<hostname>\[:\<port>] for the S3 compatible endpoint.
  27. Additionally the following environment variables need to be populated to interact with the S3 endpoint.
  28. - `ACM_S3_ACCESS` - A valid S3 Access Key for the endpoint.
  29. - `ACM_S3_SECRET` - A valid S3 Secret Key for the Access Key on the endpoint.
  30. ### Common Options
  31. - `-c, --config`: The config file to read. Default file is `acm-config.json` in the current directory.
  32. - `-s, --stdin`: Read the file list to process from stdin.
  33. - `-p, --prefix`: The prefix to strip from the input. i.e. `acm.py -x test -p /tmp/data/storage/ check /tmp/data/storage/images/img1.jpg` => `images/img1.jpg`
  34. ### S3 Common Options
  35. - `-x, --context`: The remote bucket to use. For `store` and `retrieve` operations it is `<value>-data`.
  36. ### S3 Commands
  37. - list - list files in context
  38. - check - find changes in provided files
  39. - match - find matches in provided files
  40. - update - update stored sha256sum values for provided files
  41. - store - put files in data bucket
  42. - retrieve - retrieve files from data bucket
  43. ### Listing Files
  44. List all files in a bucket
  45. ```bash
  46. $ ./acm.py list -x <bucket>
  47. ```
  48. List all files while adding a prefix and stripping a suffix
  49. ```bash
  50. $ ./acm.py --remove-prefix <prefix> list -x <bucket> --suffix <suffix>
  51. ```
  52. List all files with sha256sum compatible output
  53. ```bash
  54. $ ./acm.py --remove-prefix "/tmp/" --stdin list -x testing --suffix .json --sha256sum
  55. ```
  56. Print out a sha256sum compatible check list
  57. ### Checking For Matches
  58. Do a comparison of the remote bucket for files with a matching sha256sum value.
  59. Process a list of files
  60. ```bash
  61. $ ./acm.py --remove-prefix <prefix to strip> match -x <bucket> FILES...
  62. ```
  63. Process a list from stdin
  64. ```bash
  65. $ find /tmp -name '*.jpg' | ./acm.py --remove-prefix <prefix to strip> match -x <bucket>
  66. ```
  67. ### Checking For Changes
  68. Do a comparison of the remote bucket for missing files or files with a mismatch in their sha256sum values.
  69. Process a list of files
  70. ```bash
  71. $ ./acm.py --remove-prefix <prefix to strip> check -x <bucket> FILES...
  72. ```
  73. Process a list from stdin
  74. ```bash
  75. $ find /tmp -name '*.jpg' | ./acm.py --remove-prefix <prefix to strip> check -x <bucket>
  76. ```
  77. ### Updating Metadata For Changed Files
  78. Update the remote bucket with new metadata for the listed files. Calculates new sha256sum values.
  79. Process a list of files
  80. ```bash
  81. $ ./acm.py --remove-prefix <prefix to strip> update -x <bucket> FILES...
  82. ```
  83. Process a list from stdin
  84. ```bash
  85. $ find /tmp -name '*.jpg' | ./acm.py --remove-prefix <prefix to strip> update -x <bucket>
  86. ```
  87. ### Storing Files
  88. Store the listed files in `<bucket>-data`.
  89. Process a list of files
  90. ```bash
  91. $ ./acm.py --remove-prefix <prefix to strip> store -x <bucket> FILES...
  92. ```
  93. Process a list from stdin
  94. ```bash
  95. $ find /tmp -name '*.jpg' | ./acm.py --remove-prefix <prefix to strip> store -x <bucket>
  96. ```
  97. ### Retrieving Files
  98. Retrieve remote files matching listed files. Optionally place the downloaded files in a different destination.
  99. Process a list of files
  100. ```bash
  101. $ ./acm.py --remove-prefix <prefix to strip> retrieve -x <bucket> [-d <destination>] FILES...
  102. ```
  103. Process a list from stdin
  104. ```bash
  105. $ find /tmp -name '*.jpg' | ./acm.py --remove-prefix <prefix to strip> retrieve -x <bucket> [-d <destination>]
  106. ```
  107. ### Configuring Profiles
  108. ### Compressing Changed Assets
  109. Compressing assets based on profiles
  110. ```bash
  111. ```
  112. ## Usage as a workflow
  113. Compressing changed files and storing them for later use
  114. 1. Identify changed files
  115. - `find <file_location> -type f | ./acm.py --stdin -p <file_location> check -x aggressive`
  116. 1. Pass identified files to the compressor with a specific profile
  117. - `<found_files> | ./acm.py --stdin -p <file_location> compress -p aggressive -d /tmp/profile-aggressive/`
  118. 1. Store compressed assets in data bucket
  119. - `<compressed_files> | ./acm.py --stdin -p /tmp/profile/aggressive/ store -x aggressive`
  120. 1. Update metadata about files
  121. - `<found_files> | ./acm.py --stdin -p <file_location> update -x aggressive`
  122. As a combined workflow to only compress and store changed assets
  123. ```bash
  124. export TARGET_DIRECTORY=/mnt/e/data/files/
  125. export CONTEXT=android
  126. export PROFILE=aggressive
  127. export PROFILE_TMP_DIR="/tmp/profile-${PROFILE}/"
  128. export COMPRESSED_FILES="$(mktemp)"
  129. # Compress changed assets
  130. find "$TARGET_DIRECTORY" -type f | ./acm.py --stdin --remove-prefix "$TARGET_DIRECTORY" check -x "$CONTEXT" | ./acm.py --stdin --remove-prefix "$TARGET_DIRECTORY" compress --print-input-and-identity -p "$PROFILE" -d "$PROFILE_TMP_DIR" > "$COMPRESSED_FILES"
  131. # Store compressed assets
  132. find "$PROFILE_TMP_DIR" -type f | ./acm.py --stdin --remove-prefix "$PROFILE_TMP_DIR" --add-prefix "$TARGET_DIRECTORY" store -x "${CONTEXT}-data" > /dev/null
  133. # Update Asset manifests
  134. cat "$COMPRESSED_FILES" | ./acm.py --stdin --remove-prefix "$TARGET_DIRECTORY" update -x "$CONTEXT" --input-and-identity > /dev/null
  135. ```
  136. As a combined workflow to download matching assets
  137. ```bash
  138. TARGET_DIRECTORY=/mnt/e/data/files/
  139. CONTEXT=android
  140. PROFILE=aggressive
  141. PROFILE_TMP_DIR="/tmp/profile-${PROFILE}"
  142. find "$TARGET_DIRECTORY" -type f | ./acm.py --stdin --remove-prefix "$TARGET_DIRECTORY" match -x "$CONTEXT" --print-identity | ./acm.py --stdin retrieve -x "${CONTEXT}-data" -d "$PROFILE_TMP_DIR" > /dev/null`
  143. ```
  144. ## Contributing
  145. ## License
  146. See [LICENSE.md](LICENSE.md)