Exclude folders under public directory after deploy

Posted November 9, 2021 109 views
DigitalOcean 1-Click Apps MarketplaceDeploymentLaravelGitHub Actions

At my Digital Ocean basic application, I used CRUD photo folder under public directory at laravel.
But when I deploy the application from GitHub repo, it remove all photos and make same with my GitHub repo.
Is there anyway to exclude the custom folders under public directory of laravel?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Hi there @rockoo,

This happens as the DigitalOcean App platform is based on Kubernetes, meaning that each deployment is a separate immutable container.

So after each redeployment, all changes to the container will be lost.

To sort this out, you need to use an Object Storage, like the DigitalOcean Spaces.

To do so, you can follow the instructions from step 5 of this tutorial here:

Basically, what you need to do is:

  • Include the additional package so that you could use the s3 driver:
composer require league/flysystem-aws-s3-v3
  • Add the following details to your .env file:
  • Then in your Storage config at config/filesystems.php you need to define the details for your S3 bucket as follows:
'spaces' => [
   'driver' => 's3',
   'key' => env('DO_SPACES_KEY'),
   'secret' => env('DO_SPACES_SECRET'),
   'endpoint' => env('DO_SPACES_ENDPOINT'),
   'region' => env('DO_SPACES_REGION'),
   'bucket' => env('DO_SPACES_BUCKET'),

Still, in the same file, locate the cloud entry and change it to set the new spaces disk as the default cloud filesystem disk:

'cloud' => env('FILESYSTEM_CLOUD', 'spaces'),
  • Then in your controllers, in order to upload an image to the DigitalOcean Space, you can do the following:
use Illuminate\Support\Facades\Storage;

   public function uploadPhoto(Request $request)

       $photo->image = $request->image->store('/', 'spaces');
       Storage::setVisibility($photo->image, 'public');

       return redirect()->route('home');
  • To access the images in your Blade views, you would use the following:
<img src="{{ asset('storage') . '/' . $photo->image }}" />

Once you implement the S3 driver or the DigitalOcean Space, you will have persistent storage, so when your users upload images via your app, the images will not be uploaded to the container inside the DigitalOcean App itself, but the S3 bucket, so once the container gets redeployed your images will stay intact on the object storage.

Hope that this helps. Let me know how it goes.

by Bobby Iliev
by Erika Heidi
Data persistence and file storage represent two of the biggest challenges when horizontally scaling web applications. This is mainly due to the fact that it is hard to maintain consistency of variable data between multiple application nodes. A practical way of meeting these demands is by using managed databases and object storage. In this guide, we will update an existing Laravel 6 application to use a managed MySQL database and an S3-compatible object store.