loftwah / linkarooie

Simplify your online presence with a single link.
https://linkarooie.com
MIT License
26 stars 5 forks source link

Migrate Avatar and Banner Storage to DigitalOcean Spaces #172

Closed loftwah closed 1 month ago

loftwah commented 1 month ago

Currently, user avatars and banners are stored locally on the server, which increases storage complexity and reduces scalability. Since we already have a DigitalOcean Spaces bucket configured and operational, migrating these assets to be stored and served from the DigitalOcean Spaces would simplify storage management and improve the performance of the application, especially in production environments.

The task involves:

loftwah commented 1 month ago

Didn't expect to be spending my night on this.

DigitalOcean Spaces Migration Plan

  1. Prepare DigitalOcean Spaces:
    • Create folders: "avatars", "banners", "defaults"
    • Upload default avatar and banner to the "defaults" folder
  2. Update User Model:
    • Modify avatar_url and banner_url methods to return Spaces URLs
    • Update download_and_store_image method to use Spaces for storage
  3. Create DigitalOcean Spaces Service:
    • Implement methods for uploading, downloading, and deleting files
  4. Update Users::RegistrationsController:
    • Modify create and update actions to use the new Spaces service
    • Allow certain attributes to be updated without password confirmation
  5. Update OpenGraphImageGenerator:
    • Modify to use images from Spaces instead of local storage
  6. Create Migration Rake Task:
    • Implement task to migrate existing avatars and banners to Spaces
    • Handle default images, invalid URLs, and non-image URLs
  7. Update Views:
    • Ensure all views are using the correct methods to display images from Spaces
  8. Test Migration:
    • Run migration task in a staging environment
    • Verify that all images are correctly migrated and displayed
  9. Deploy and Monitor:

    • Deploy changes to production
    • Monitor for any issues with image display or uploads

    Am up to 3.

loftwah commented 1 month ago

https://github.com/loftwah/linkarooie/pull/173

loftwah commented 1 month ago

Updated Migration Plan:

1. Prepare DigitalOcean Spaces:

2. Update User Model:

3. Create DigitalOcean Spaces Service:

4. Update Users::RegistrationsController:

5. Update OpenGraphImageGenerator:

6. Create Migration Rake Task:

7. Update Views:

8. Test Migration:

9. Deploy and Monitor:

Immediate Next Steps for Testing:

  1. Verify the corrected bucket variable:

    • Ensure the SPACES_BUCKET_CONTENT is now being used in the DigitalOceanSpacesService.
  2. Test image upload with a valid URL:

    • Use the Rails console to trigger the process_image method on a user and confirm the image uploads to Spaces.
  3. Check the updated user avatar URL:

    • After running the upload, verify that the avatar URL in the database points to Spaces correctly.
loftwah commented 1 month ago

Finally! Wow this was a nightmare but at least my test coverage is good.

loftwah commented 1 month ago

Just finished then. Lesson learned I guess.