<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>cellar Archives | Clever Cloud</title>
	<atom:link href="https://www.clever.cloud/blog/tag/cellar/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.clever.cloud/blog/tag/cellar/</link>
	<description>From Code to Product</description>
	<lastBuildDate>Tue, 24 Oct 2023 09:12:45 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://cdn.clever-cloud.com/uploads/2023/03/cropped-cropped-favicon-32x32.png</url>
	<title>cellar Archives | Clever Cloud</title>
	<link>https://www.clever.cloud/blog/tag/cellar/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Migration Required for Buckets on Cellar C1 Cluster</title>
		<link>https://www.clever.cloud/blog/engineering/2022/01/19/migration-required-for-buckets-on-cellar-c1-cluster/</link>
		
		<dc:creator><![CDATA[Arnaud Lefebvre]]></dc:creator>
		<pubDate>Wed, 19 Jan 2022 09:41:48 +0000</pubDate>
				<category><![CDATA[Engineering]]></category>
		<category><![CDATA[addon]]></category>
		<category><![CDATA[addons]]></category>
		<category><![CDATA[cellar]]></category>
		<category><![CDATA[migration]]></category>
		<category><![CDATA[Support]]></category>
		<guid isPermaLink="false">https://www.clever-cloud.com/?p=5142</guid>

					<description><![CDATA[<p><img width="1400" height="540" src="https://cdn.clever-cloud.com/uploads/2022/01/cellarupdate.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="cellarupdate" decoding="async" fetchpriority="high" srcset="https://cdn.clever-cloud.com/uploads/2022/01/cellarupdate.png 1400w, https://cdn.clever-cloud.com/uploads/2022/01/cellarupdate-300x116.png 300w, https://cdn.clever-cloud.com/uploads/2022/01/cellarupdate-1024x395.png 1024w, https://cdn.clever-cloud.com/uploads/2022/01/cellarupdate-768x296.png 768w, https://cdn.clever-cloud.com/uploads/2022/01/cellarupdate-1368x528.png 1368w" sizes="(max-width: 1400px) 100vw, 1400px" /></p><!-- wp:paragraph -->
<p><strong>tl;dr: </strong>On March 21th 2022 the Cellar C1 cluster will reach its end of life. So we ask you to perform a migration to a newer cluster Cellar, which will also improve performance. The C1 cluster did not accept new add-ons since the 20th January 2019.<br></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>In fact, data need to be migrated from this old add-on to a new Cellar add-on. Newly created Cellar C2 add-ons come with various improvements&nbsp;:</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li>A better S3 protocol support (including the AWS V4&nbsp;signature)</li><li>Improved upload and download performances (x3 for upload, x2 for download)</li><li>Improved resilience and availability of your data (Data is now replicated across two datacenters more than 20km apart)</li></ul>
<!-- /wp:list -->

<!-- wp:heading {"level":3} -->
<h3><strong>How to migrate my data?</strong></h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>We can help you to migrate your data by syncing it directly on our side. To do that, reach the support and include in your message source and destination add-ons, including the buckets to migrate. The support team is here to help.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>If you wish to migrate on your side, or at least keep your buckets synchronized, we built a simple tool to help you:&nbsp;<a href="https://github.com/CleverCloud/cellar-c1-migration-tool" target="_blank" rel="noreferrer noopener">Cellar&nbsp;migration tool</a>.<br>You can run this tool as many times as you need. It will only synchronize objects that are different between the source and the destination buckets.<br>If you do not feel comfortable using it, you can also use the&nbsp;<code>s3cmd sync</code>&nbsp;command from the&nbsp;<a href="https://s3tools.org/s3cmd" target="_blank" rel="noreferrer noopener">s3cmd tool</a>.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>If your application handle it, we encourage you to upload new objects as soon as possible to the new bucket. Then when you need to query that object, your application can query both buckets (old and new) to get it. You can also store the complete URL to make this easier. This should help you transition from one bucket to another without downtime.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Please note that we can't make sure that the buckets names you use will be available on the destination cluster. If you have a name conflict, please contact us and we will work something out.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>A few days before the deadline, we will have short service brown-outs to remind customers that the service is going to be shut down. Those brown-outs will be announced on our&nbsp;<a href="https://www.clevercloudstatus.com" target="_blank" rel="noreferrer noopener">status page</a>&nbsp;a few days before. Make sure to&nbsp;<a href="https://www.clevercloudstatus.com/subscribe" target="_blank" rel="noreferrer noopener">subscribe to Status Updates</a>&nbsp;to receive a notification.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3><strong>What will happen if I can't do the migration?</strong></h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>If you can't do the migration or have any questions about it, we strongly recommend that you contact our support team via the console.<br>Before shutting down the cluster, we will backup your data and keep it for 6 months. Our support team will be able to provide you a download link or re-inject the data in a new bucket if you wish to recover it.</p>
<!-- /wp:paragraph -->]]></description>
										<content:encoded><![CDATA[<p><img width="1400" height="540" src="https://cdn.clever-cloud.com/uploads/2022/01/cellarupdate.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="cellarupdate" decoding="async" srcset="https://cdn.clever-cloud.com/uploads/2022/01/cellarupdate.png 1400w, https://cdn.clever-cloud.com/uploads/2022/01/cellarupdate-300x116.png 300w, https://cdn.clever-cloud.com/uploads/2022/01/cellarupdate-1024x395.png 1024w, https://cdn.clever-cloud.com/uploads/2022/01/cellarupdate-768x296.png 768w, https://cdn.clever-cloud.com/uploads/2022/01/cellarupdate-1368x528.png 1368w" sizes="(max-width: 1400px) 100vw, 1400px" /></p><!-- wp:paragraph -->
<p><strong>tl;dr: </strong>On March 21th 2022 the Cellar C1 cluster will reach its end of life. So we ask you to perform a migration to a newer cluster Cellar, which will also improve performance. The C1 cluster did not accept new add-ons since the 20th January 2019.<br></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>In fact, data need to be migrated from this old add-on to a new Cellar add-on. Newly created Cellar C2 add-ons come with various improvements&nbsp;:</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li>A better S3 protocol support (including the AWS V4&nbsp;signature)</li><li>Improved upload and download performances (x3 for upload, x2 for download)</li><li>Improved resilience and availability of your data (Data is now replicated across two datacenters more than 20km apart)</li></ul>
<!-- /wp:list -->

<!-- wp:heading {"level":3} -->
<h3><strong>How to migrate my data?</strong></h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>We can help you to migrate your data by syncing it directly on our side. To do that, reach the support and include in your message source and destination add-ons, including the buckets to migrate. The support team is here to help.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>If you wish to migrate on your side, or at least keep your buckets synchronized, we built a simple tool to help you:&nbsp;<a href="https://github.com/CleverCloud/cellar-c1-migration-tool" target="_blank" rel="noreferrer noopener">Cellar&nbsp;migration tool</a>.<br>You can run this tool as many times as you need. It will only synchronize objects that are different between the source and the destination buckets.<br>If you do not feel comfortable using it, you can also use the&nbsp;<code>s3cmd sync</code>&nbsp;command from the&nbsp;<a href="https://s3tools.org/s3cmd" target="_blank" rel="noreferrer noopener">s3cmd tool</a>.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>If your application handle it, we encourage you to upload new objects as soon as possible to the new bucket. Then when you need to query that object, your application can query both buckets (old and new) to get it. You can also store the complete URL to make this easier. This should help you transition from one bucket to another without downtime.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Please note that we can't make sure that the buckets names you use will be available on the destination cluster. If you have a name conflict, please contact us and we will work something out.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>A few days before the deadline, we will have short service brown-outs to remind customers that the service is going to be shut down. Those brown-outs will be announced on our&nbsp;<a href="https://www.clevercloudstatus.com" target="_blank" rel="noreferrer noopener">status page</a>&nbsp;a few days before. Make sure to&nbsp;<a href="https://www.clevercloudstatus.com/subscribe" target="_blank" rel="noreferrer noopener">subscribe to Status Updates</a>&nbsp;to receive a notification.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3><strong>What will happen if I can't do the migration?</strong></h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>If you can't do the migration or have any questions about it, we strongly recommend that you contact our support team via the console.<br>Before shutting down the cluster, we will backup your data and keep it for 6 months. Our support team will be able to provide you a download link or re-inject the data in a new bucket if you wish to recover it.</p>
<!-- /wp:paragraph -->]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Setup a directory listing for an S3 bucket</title>
		<link>https://www.clever.cloud/blog/features/2020/10/08/s3-directory-listing/</link>
		
		<dc:creator><![CDATA[Laurent Doguin]]></dc:creator>
		<pubDate>Thu, 08 Oct 2020 15:35:00 +0000</pubDate>
				<category><![CDATA[Features]]></category>
		<category><![CDATA[cellar]]></category>
		<category><![CDATA[s3]]></category>
		<guid isPermaLink="false">https://www2.cleverapps.io/wp/blog/technology/2020/10/08/s3-directory-listing/</guid>

					<description><![CDATA[<p><img width="1400" height="540" src="https://cdn.clever-cloud.com/uploads/2021/08/directorylistingbanner.jpg" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="directorylistingbanner" decoding="async" srcset="https://cdn.clever-cloud.com/uploads/2021/08/directorylistingbanner.jpg 1400w, https://cdn.clever-cloud.com/uploads/2021/08/directorylistingbanner-300x116.jpg 300w, https://cdn.clever-cloud.com/uploads/2021/08/directorylistingbanner-1024x395.jpg 1024w, https://cdn.clever-cloud.com/uploads/2021/08/directorylistingbanner-768x296.jpg 768w, https://cdn.clever-cloud.com/uploads/2021/08/directorylistingbanner-1368x528.jpg 1368w" sizes="(max-width: 1400px) 100vw, 1400px" /></p>Yesterday I had a customer asking me how to make a simple directory listing like you have with apache server, but with the content stored in an S3 bucket. This way they can replace their git lfs + apache setup with something possibly simpler and more suited to binary storage.

<span id="more-2977"></span>

As it turns out it's not that complicated. You need to get the permissions right, and to be aware of a listing option in S3 API. Let's see how to make this work on Clever Cloud.
<h2 id="create-a-cellar-addon">Create a Cellar Addon</h2>
Clever Cloud is a Platform as a Service. We provide many <a href="https://www.clever.cloud/developers/addons/">managed services</a> and one of them is Cellar, our S3 compatible storage. Assuming you already have an account, here's how to create a Cellar add-on.
<h3 id="using-the-cli">Using the CLI</h3>
Assuming you are already using <a href="https://github.com/CleverCloud/clever-tools">clever-tools</a>, all you have to do is run <code>clever addon create cellar-addon --plan S myCellarService</code>.
<h3 id="using-the-web-console">Using the Web Console</h3>
You can login to our console on <code>https://console.clever-cloud.com/</code>. From there click on Create, an add-on and choose Cellar. There is only one plan available since Cellar is billed based on consumption so click next. We have no need to link it to an existing application so click next again, give it a name and click on create.

<video style="margin: 0 auto; display: block;" autoplay="autoplay" loop="loop" width="70%" height="150"><source src="//assets.clever-cloud.com/website/blog/create-cellar.mp4" type="video/mp4" /><source src="//assets.clever-cloud.com/website/blog/create-cellar.webm" type="video/webm" /></video>
<h2 id="setup-a-bucket">Setup a Bucket</h2>
Now that you have your S3 add-on, the easiest way to manage buckets is probably to use <a href="https://s3tools.org/s3cmd">s3cmd</a> or <a href="https://rclone.org/">Rclone</a>. Here's how to create a bucket, make it public and store some files.

First get your configuration file. It's waiting for you on the add-on dashboard. Browse your Cellar add-on from the console, you should see some details and a link to <code>Download a pre-filled s3cfg file.</code>. Download it and place it under your home directory. If you are a linux user it should be <code>~/.s3cfg</code>.

<video style="margin: 0 auto; display: block;" autoplay="autoplay" loop="loop" width="70%" height="150"><source src="//assets.clever-cloud.com/website/blog/get-cellar-conf.mp4" type="video/mp4" /><source src="//assets.clever-cloud.com/website/blog/get-cellar-conf.webm" type="video/webm" /></video>

Now s3cmd will use this configuration. Nothing else to do. Typing <code>s3cmd la</code> list all resources available. If you just created the Cellar add-on, you should see nothing listed. To create your bucket run <code>s3cmd mb s3://your-unique-bucket-name/</code>. The chosen name should be lower case and unique. If I insist on the uniqueness of that name, it's because it can't be already taken by someone else. All buckets are made available by default on <code>http://your-unique-bucket-name.cellar-c2.services.clever-cloud.com</code>. You can see why they have to be unique.

You can also name it after your domain name, and put a CNAME redirection to <code>cellar-c2.services.clever-cloud.com.</code>. This way it will be available from your domain name directly. You will find more information on <a href="https://www.clever.cloud/developers/addons/cellar/">our documenation</a>.

Once you have created your bucket, you are ready to upload your files. Run <code>s3cmd sync ./ s3://your-unique-bucket-name/</code> and the content of the current folder will be automatically updated to your bucket.

By default everything is private so if you browse <code>http://your-unique-bucket-name.cellar-c2.services.clever-cloud.com</code> you should get an XML error saying access denied. To change this and make it readable by everyone, run <code>s3cmd setacl --acl-public s3://your-unique-bucket-name/*</code>. This will grant read access to all anonymous users.

Each file should be accessible separately but you still cannot list the content of the bucket. This is because the bucket itself has to be set to public. Run <code>s3cmd setacl --acl-public s3://your-unique-bucket-name</code> and it will allow you to see the list of objects as XML. You can get a simpler list by adding <code>type-list=2</code> as query param. So by browsing <a href="https://www.clever.cloud/developers/deploy/addon/fs-bucket/">http://your-unique-bucket-name.cellar-c2.services.clever-cloud.com/?type-list=2</a>, you should see something like:
<pre><code class="language-xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"&gt;
&lt;Name&gt;ldoguinbucket&lt;/Name&gt;
&lt;Prefix&gt;&lt;/Prefix&gt;
&lt;MaxKeys&gt;1000&lt;/MaxKeys&gt;
&lt;IsTruncated&gt;false&lt;/IsTruncated&gt;
&lt;Contents&gt;
    &lt;Key&gt;hello.txt&lt;/Key&gt;
    &lt;LastModified&gt;2020-10-05T13:07:08.664Z&lt;/LastModified&gt;
    &lt;ETag&gt;&amp;quot;b1946ac92492d2347c6235b4d2611184&amp;quot;&lt;/ETag&gt;
    &lt;Size&gt;6&lt;/Size&gt;
    &lt;StorageClass&gt;STANDARD&lt;/StorageClass&gt;
    &lt;Owner&gt;
        &lt;ID&gt;cellar_0e275449-c02a-4e07-b100-2e357b532e3b&lt;/ID&gt;
        &lt;DisplayName&gt;cellar_0e275449-c02a-4e07-b100-2e357b532e3b@user_51f7098f-604e-4d9e-8fb6-4026fd1767bb&lt;/DisplayName&gt;
    &lt;/Owner&gt;
    &lt;Type&gt;Normal&lt;/Type&gt;
&lt;/Contents&gt;
&lt;Marker&gt;&lt;/Marker&gt;
&lt;/ListBucketResult&gt;
</code></pre>
You can of course adjust the permissions to your liking. Not everything has to be public. You can make that listing look much better and be actually browsable. Here's how.
<h2 id="add-the-listing">Add the Listing</h2>
As you have seen it's easy to get an XML list of your bucket content. You will find many examples on GitHub of single page HTML that fetch the XML list with an XHR request and then renders it nicely. All you have to do is usually upload that files at the root of your bucket and everything should work.

I have tried with <a href="https://github.com/qoomon/aws-s3-bucket-browser">https://github.com/qoomon/aws-s3-bucket-browser</a> and it works great. Simply clone this repo and upload all the files at the root of your bucket with the public ACL.
<pre><code class="language-bash">git clone https://github.com/qoomon/aws-s3-bucket-browser/ 
s3cmd put --acl-public aws-s3-bucket-browser/favicon.ico s3://your-unique-bucket-name/favicon.ico
s3cmd put --acl-public aws-s3-bucket-browser/index.html s3://your-unique-bucket-name/index.html
s3cmd put --acl-public aws-s3-bucket-browser/logo.png s3://your-unique-bucket-name/logo.png
</code></pre>
<figure><img style="width: 70%; margin: 0 auto; display: block; max-width: 100%;" src="https://cdn.clever-cloud.com/uploads/2021/08/directorylisting.png" alt="S3 directory listing" />
<figcaption>Cellar directory listing</figcaption></figure>
From there you should see a very nice listing when you browse <code>http://your-unique-bucket-name.cellar-c2.services.clever-cloud.com/index.html</code>. Thanks to <a href="https://github.com/qoomon">Bengt Brodersen</a> for providing this :)]]></description>
										<content:encoded><![CDATA[<p><img width="1400" height="540" src="https://cdn.clever-cloud.com/uploads/2021/08/directorylistingbanner.jpg" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="directorylistingbanner" decoding="async" loading="lazy" srcset="https://cdn.clever-cloud.com/uploads/2021/08/directorylistingbanner.jpg 1400w, https://cdn.clever-cloud.com/uploads/2021/08/directorylistingbanner-300x116.jpg 300w, https://cdn.clever-cloud.com/uploads/2021/08/directorylistingbanner-1024x395.jpg 1024w, https://cdn.clever-cloud.com/uploads/2021/08/directorylistingbanner-768x296.jpg 768w, https://cdn.clever-cloud.com/uploads/2021/08/directorylistingbanner-1368x528.jpg 1368w" sizes="auto, (max-width: 1400px) 100vw, 1400px" /></p>Yesterday I had a customer asking me how to make a simple directory listing like you have with apache server, but with the content stored in an S3 bucket. This way they can replace their git lfs + apache setup with something possibly simpler and more suited to binary storage.

<span id="more-2977"></span>

As it turns out it's not that complicated. You need to get the permissions right, and to be aware of a listing option in S3 API. Let's see how to make this work on Clever Cloud.
<h2 id="create-a-cellar-addon">Create a Cellar Addon</h2>
Clever Cloud is a Platform as a Service. We provide many <a href="https://www.clever.cloud/developers/addons/">managed services</a> and one of them is Cellar, our S3 compatible storage. Assuming you already have an account, here's how to create a Cellar add-on.
<h3 id="using-the-cli">Using the CLI</h3>
Assuming you are already using <a href="https://github.com/CleverCloud/clever-tools">clever-tools</a>, all you have to do is run <code>clever addon create cellar-addon --plan S myCellarService</code>.
<h3 id="using-the-web-console">Using the Web Console</h3>
You can login to our console on <code>https://console.clever-cloud.com/</code>. From there click on Create, an add-on and choose Cellar. There is only one plan available since Cellar is billed based on consumption so click next. We have no need to link it to an existing application so click next again, give it a name and click on create.

<video style="margin: 0 auto; display: block;" autoplay="autoplay" loop="loop" width="70%" height="150"><source src="//assets.clever-cloud.com/website/blog/create-cellar.mp4" type="video/mp4" /><source src="//assets.clever-cloud.com/website/blog/create-cellar.webm" type="video/webm" /></video>
<h2 id="setup-a-bucket">Setup a Bucket</h2>
Now that you have your S3 add-on, the easiest way to manage buckets is probably to use <a href="https://s3tools.org/s3cmd">s3cmd</a> or <a href="https://rclone.org/">Rclone</a>. Here's how to create a bucket, make it public and store some files.

First get your configuration file. It's waiting for you on the add-on dashboard. Browse your Cellar add-on from the console, you should see some details and a link to <code>Download a pre-filled s3cfg file.</code>. Download it and place it under your home directory. If you are a linux user it should be <code>~/.s3cfg</code>.

<video style="margin: 0 auto; display: block;" autoplay="autoplay" loop="loop" width="70%" height="150"><source src="//assets.clever-cloud.com/website/blog/get-cellar-conf.mp4" type="video/mp4" /><source src="//assets.clever-cloud.com/website/blog/get-cellar-conf.webm" type="video/webm" /></video>

Now s3cmd will use this configuration. Nothing else to do. Typing <code>s3cmd la</code> list all resources available. If you just created the Cellar add-on, you should see nothing listed. To create your bucket run <code>s3cmd mb s3://your-unique-bucket-name/</code>. The chosen name should be lower case and unique. If I insist on the uniqueness of that name, it's because it can't be already taken by someone else. All buckets are made available by default on <code>http://your-unique-bucket-name.cellar-c2.services.clever-cloud.com</code>. You can see why they have to be unique.

You can also name it after your domain name, and put a CNAME redirection to <code>cellar-c2.services.clever-cloud.com.</code>. This way it will be available from your domain name directly. You will find more information on <a href="https://www.clever.cloud/developers/addons/cellar/">our documenation</a>.

Once you have created your bucket, you are ready to upload your files. Run <code>s3cmd sync ./ s3://your-unique-bucket-name/</code> and the content of the current folder will be automatically updated to your bucket.

By default everything is private so if you browse <code>http://your-unique-bucket-name.cellar-c2.services.clever-cloud.com</code> you should get an XML error saying access denied. To change this and make it readable by everyone, run <code>s3cmd setacl --acl-public s3://your-unique-bucket-name/*</code>. This will grant read access to all anonymous users.

Each file should be accessible separately but you still cannot list the content of the bucket. This is because the bucket itself has to be set to public. Run <code>s3cmd setacl --acl-public s3://your-unique-bucket-name</code> and it will allow you to see the list of objects as XML. You can get a simpler list by adding <code>type-list=2</code> as query param. So by browsing <a href="https://www.clever.cloud/developers/deploy/addon/fs-bucket/">http://your-unique-bucket-name.cellar-c2.services.clever-cloud.com/?type-list=2</a>, you should see something like:
<pre><code class="language-xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"&gt;
&lt;Name&gt;ldoguinbucket&lt;/Name&gt;
&lt;Prefix&gt;&lt;/Prefix&gt;
&lt;MaxKeys&gt;1000&lt;/MaxKeys&gt;
&lt;IsTruncated&gt;false&lt;/IsTruncated&gt;
&lt;Contents&gt;
    &lt;Key&gt;hello.txt&lt;/Key&gt;
    &lt;LastModified&gt;2020-10-05T13:07:08.664Z&lt;/LastModified&gt;
    &lt;ETag&gt;&amp;quot;b1946ac92492d2347c6235b4d2611184&amp;quot;&lt;/ETag&gt;
    &lt;Size&gt;6&lt;/Size&gt;
    &lt;StorageClass&gt;STANDARD&lt;/StorageClass&gt;
    &lt;Owner&gt;
        &lt;ID&gt;cellar_0e275449-c02a-4e07-b100-2e357b532e3b&lt;/ID&gt;
        &lt;DisplayName&gt;cellar_0e275449-c02a-4e07-b100-2e357b532e3b@user_51f7098f-604e-4d9e-8fb6-4026fd1767bb&lt;/DisplayName&gt;
    &lt;/Owner&gt;
    &lt;Type&gt;Normal&lt;/Type&gt;
&lt;/Contents&gt;
&lt;Marker&gt;&lt;/Marker&gt;
&lt;/ListBucketResult&gt;
</code></pre>
You can of course adjust the permissions to your liking. Not everything has to be public. You can make that listing look much better and be actually browsable. Here's how.
<h2 id="add-the-listing">Add the Listing</h2>
As you have seen it's easy to get an XML list of your bucket content. You will find many examples on GitHub of single page HTML that fetch the XML list with an XHR request and then renders it nicely. All you have to do is usually upload that files at the root of your bucket and everything should work.

I have tried with <a href="https://github.com/qoomon/aws-s3-bucket-browser">https://github.com/qoomon/aws-s3-bucket-browser</a> and it works great. Simply clone this repo and upload all the files at the root of your bucket with the public ACL.
<pre><code class="language-bash">git clone https://github.com/qoomon/aws-s3-bucket-browser/ 
s3cmd put --acl-public aws-s3-bucket-browser/favicon.ico s3://your-unique-bucket-name/favicon.ico
s3cmd put --acl-public aws-s3-bucket-browser/index.html s3://your-unique-bucket-name/index.html
s3cmd put --acl-public aws-s3-bucket-browser/logo.png s3://your-unique-bucket-name/logo.png
</code></pre>
<figure><img style="width: 70%; margin: 0 auto; display: block; max-width: 100%;" src="https://cdn.clever-cloud.com/uploads/2021/08/directorylisting.png" alt="S3 directory listing" />
<figcaption>Cellar directory listing</figcaption></figure>
From there you should see a very nice listing when you browse <code>http://your-unique-bucket-name.cellar-c2.services.clever-cloud.com/index.html</code>. Thanks to <a href="https://github.com/qoomon">Bengt Brodersen</a> for providing this :)]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to Deploy a Static Site on Cellar</title>
		<link>https://www.clever.cloud/blog/engineering/2020/06/24/deploy-cellar-s3-static-site/</link>
		
		<dc:creator><![CDATA[Laurent Doguin]]></dc:creator>
		<pubDate>Wed, 24 Jun 2020 12:00:00 +0000</pubDate>
				<category><![CDATA[Engineering]]></category>
		<category><![CDATA[cellar]]></category>
		<category><![CDATA[static]]></category>
		<guid isPermaLink="false">https://www2.cleverapps.io/wp/blog/technology/2020/06/24/deploy-cellar-s3-static-site/</guid>

					<description><![CDATA[<p><img width="1400" height="540" src="https://cdn.clever-cloud.com/uploads/2021/08/staticsite.jpg" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="staticsite" decoding="async" loading="lazy" srcset="https://cdn.clever-cloud.com/uploads/2021/08/staticsite.jpg 1400w, https://cdn.clever-cloud.com/uploads/2021/08/staticsite-300x116.jpg 300w, https://cdn.clever-cloud.com/uploads/2021/08/staticsite-1024x395.jpg 1024w, https://cdn.clever-cloud.com/uploads/2021/08/staticsite-768x296.jpg 768w, https://cdn.clever-cloud.com/uploads/2021/08/staticsite-1368x528.jpg 1368w" sizes="auto, (max-width: 1400px) 100vw, 1400px" /></p>You don't need an application to deploy a static site on Clever Cloud anymore. Let's see how :)

<span id="more-2830"></span>

For years the only way to deploy a static website on Clever Cloud was to create an application. While the type of this application says static, it's in fact a PHP application in disguise. The good thing about this is it allows you to play with Apache's configuration to manage custom redirection and the likes. But sometimes you don't need any flexibility. And you don't want to pay for an application running when you don't need one.

Enter <a href="https://www.clever.cloud/developers/addons/cellar/">Cellar</a>, our S3 compatible object storage. You can use it to serve static assets. By default it uses the Cellar cluster URL, but with the right CNAME redirection and naming convention, it will serve your website behind your own custom domain. Cellar prices are available in <a href="https://www.clever.cloud/developers/addons/cellar/#clever-cloud-cellar-plans">our documentation</a>.

Here's how it works.
<h2 id="domain-redirection">Domain Redirection</h2>
To redirect your domain name to Clever Cloud's server, go to your domain name registrar dashboard and select the domain you want to redirect. In my case it's <code>ldoguin.name</code> on OVHCloud.
<figure style="position: relative; width: 100%; height: auto; margin: 0 auto;"><img src="https://cdn.clever-cloud.com/uploads/2021/08/ovh-cname-redirect.png" alt="Domain CNAME redirection" data-action="zoom" /></figure>
You need to add a CNAME redirection to our Cellar's CNAME: <code>cellar-c2.services.clever-cloud.com.</code> CNAME redirection are not available for root domains. If you want to redirect a root domain you will need all the public IPs of our cluster. You can easily get them by typing <code>dig cellar-c2.services.clever-cloud.com</code> in a terminal.
<h2 id="create-the-bucket">Create the Bucket</h2>
Once you have redirected your domain name to the Cellar cluster, create the Cellar add-on and add a new bucket named after your domain name, in my case <code>blog.ldoguin.name</code>.

An auto-renewed Let's Encrypt certificate will be setup automatically shortly after the bucket creation.

Everything you will upload to this bucket will be served as a static file.
<h2 id="upload-your-site">Upload your Site</h2>
If you already have your files ready, my favorite solution to upload them is to use <a href="https://rclone.org">rclone</a>. It's great to sync your files to many different cloud storage from Cellar to S3, Google drive, Swift, Dropbox and more.

Assuming all the files are in a folder called <code>public</code> and that you have a configured connection to Cellar called <code>mys3</code>, this is what you need to type:

<code>rclone sync ./public mys3:blog.ldoguin.name --progress --s3-acl=public-read</code>

This is pretty much rsync but for cloud storage :) To configure my connection I had the following environment variables:
<pre><code class="language-bash">export RCLONE_CONFIG_MYS3_ACCESS_KEY_ID=$CELLAR_ADDON_KEY_ID
export RCLONE_CONFIG_MYS3_SECRET_ACCESS_KEY=$CELLAR_ADDON_KEY_SECRET
export RCLONE_CONFIG_MYS3_ENDPOINT=$CELLAR_ADDON_HOST
export RCLONE_CONFIG_MYS3_TYPE="s3"
</code></pre>
I copied them from the my Cellar add-on dashboard. We could stop here. You have a static website hosted on Clever Cloud without a running application. Let's take this a bit further by using an application to build the website.
<h2 id="build-and-upload-your-static-site">Build and Upload your Static Site</h2>
I wrote about Hugo in a <a href="https://www.clever.cloud/blog/engineering/2020/06/18/deploy-static-site-hugo/">previous post</a>. This is going to be almost similar so I'll be quick.

The plan is to create a Clever Cloud application. Each time you will push new content to this application, it will start, generate the Hugo website, upload it to Cellar then stop itself.

Assuming you have installed Hugo and clever-tools, this is everything you need to do to have a generated website:
<pre><code class="language-bash">mkdir hugo-cellar-static # Create the site root folder
cd hugo-cellar-static/
hugo new site . # Generate a new Hugo site
git init # initialize the git repository
git submodule add https://github.com/jakewies/hugo-theme-codex themes/codex # add a theme
cp themes/codex/exampleSite/config.toml config.toml # copy the default configuration
cp -r themes/codex/exampleSite/content/ . # copy default content for the exemple
gedit config.toml  # edit the configuration, like the theme or the baseUrl
clever create --type static-apache myapp # Create a new clever cloud application
clever service link-addon MyCellar # link the app to the Cellar add-on 
cat ~/.config/clever-cloud  # Get the clever-tools token
</code></pre>
At that point you should have created a website structure and a Clever Cloud application. These are the environment variables needed to configure it:
<pre><code class="language-bash">CC_PHP_VERSION="7"
CC_PRE_RUN_HOOK="./hugo.sh" # A prerun hook to execute the build and sync it to Cellar
CC_RUN_SUCCEEDED_HOOK="clever stop" # use clever-tools to turn off the app when finished 
CLEVER_SECRET="xxxx" # Tokens for clever-tools
CLEVER_TOKEN="xxxxx" # Tokens for clever-tools
DL_RCLONE_VERSION="1.52.1" # which version of rclone to use
HUGO_VERSION="0.62.0" # which version of hugo to use
MY_DOMAIN="blog.ldoguin.name/" # The name of the bucket to sync
PORT="8080"
HUGO_ENV="production"
</code></pre>
The <code>clever stop</code> trick is likely to be replaced by something cleaner in the coming weeks, with something like a task or job. The build and sync of the site is done when the pre run hook executes <code>hugo.sh</code>, which has the following content:
<pre><code class="language-bash"># Configure rclone Cellar connection
export RCLONE_CONFIG_MYS3_ACCESS_KEY_ID=$CELLAR_ADDON_KEY_ID
export RCLONE_CONFIG_MYS3_SECRET_ACCESS_KEY=$CELLAR_ADDON_KEY_SECRET
export RCLONE_CONFIG_MYS3_ENDPOINT=$CELLAR_ADDON_HOST
export RCLONE_CONFIG_MYS3_TYPE="s3"

# Download and unpack rclone and hugo
wget https://downloads.rclone.org/v$DL_RCLONE_VERSION/rclone-v$DL_RCLONE_VERSION-linux-amd64.zip
wget https://github.com/gohugoio/hugo/releases/download/v$HUGO_VERSION/hugo_extended_"$HUGO_VERSION"_Linux-64bit.tar.gz
unzip rclone-v$DL_RCLONE_VERSION-linux-amd64.zip
tar xvf hugo_extended_"$HUGO_VERSION"_Linux-64bit.tar.gz

# Execute the site generation with Hugo
chmod +x ./hugo
./hugo --gc --minify

# Sync the site to Cellar
./rclone-v$DL_RCLONE_VERSION-linux-amd64/rclone sync ./public mys3:$MY_DOMAIN --progress --s3-acl=public-read
</code></pre>
Now what's left to do is add and commit all the files and deploy.
<pre><code class="language-bash">git add .  # add the current folder to git
git commit -m"init" # commit
clever deploy # Deploy your website
</code></pre>
The application will start, generate the website and sync it to Cellar then stop itself. So there it is you will still have your website running, but without running an application.

Please let us know what you think and what kind of features you would like to see supported for static sites :)]]></description>
										<content:encoded><![CDATA[<p><img width="1400" height="540" src="https://cdn.clever-cloud.com/uploads/2021/08/staticsite.jpg" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="staticsite" decoding="async" loading="lazy" srcset="https://cdn.clever-cloud.com/uploads/2021/08/staticsite.jpg 1400w, https://cdn.clever-cloud.com/uploads/2021/08/staticsite-300x116.jpg 300w, https://cdn.clever-cloud.com/uploads/2021/08/staticsite-1024x395.jpg 1024w, https://cdn.clever-cloud.com/uploads/2021/08/staticsite-768x296.jpg 768w, https://cdn.clever-cloud.com/uploads/2021/08/staticsite-1368x528.jpg 1368w" sizes="auto, (max-width: 1400px) 100vw, 1400px" /></p>You don't need an application to deploy a static site on Clever Cloud anymore. Let's see how :)

<span id="more-2830"></span>

For years the only way to deploy a static website on Clever Cloud was to create an application. While the type of this application says static, it's in fact a PHP application in disguise. The good thing about this is it allows you to play with Apache's configuration to manage custom redirection and the likes. But sometimes you don't need any flexibility. And you don't want to pay for an application running when you don't need one.

Enter <a href="https://www.clever.cloud/developers/addons/cellar/">Cellar</a>, our S3 compatible object storage. You can use it to serve static assets. By default it uses the Cellar cluster URL, but with the right CNAME redirection and naming convention, it will serve your website behind your own custom domain. Cellar prices are available in <a href="https://www.clever.cloud/developers/addons/cellar/#clever-cloud-cellar-plans">our documentation</a>.

Here's how it works.
<h2 id="domain-redirection">Domain Redirection</h2>
To redirect your domain name to Clever Cloud's server, go to your domain name registrar dashboard and select the domain you want to redirect. In my case it's <code>ldoguin.name</code> on OVHCloud.
<figure style="position: relative; width: 100%; height: auto; margin: 0 auto;"><img src="https://cdn.clever-cloud.com/uploads/2021/08/ovh-cname-redirect.png" alt="Domain CNAME redirection" data-action="zoom" /></figure>
You need to add a CNAME redirection to our Cellar's CNAME: <code>cellar-c2.services.clever-cloud.com.</code> CNAME redirection are not available for root domains. If you want to redirect a root domain you will need all the public IPs of our cluster. You can easily get them by typing <code>dig cellar-c2.services.clever-cloud.com</code> in a terminal.
<h2 id="create-the-bucket">Create the Bucket</h2>
Once you have redirected your domain name to the Cellar cluster, create the Cellar add-on and add a new bucket named after your domain name, in my case <code>blog.ldoguin.name</code>.

An auto-renewed Let's Encrypt certificate will be setup automatically shortly after the bucket creation.

Everything you will upload to this bucket will be served as a static file.
<h2 id="upload-your-site">Upload your Site</h2>
If you already have your files ready, my favorite solution to upload them is to use <a href="https://rclone.org">rclone</a>. It's great to sync your files to many different cloud storage from Cellar to S3, Google drive, Swift, Dropbox and more.

Assuming all the files are in a folder called <code>public</code> and that you have a configured connection to Cellar called <code>mys3</code>, this is what you need to type:

<code>rclone sync ./public mys3:blog.ldoguin.name --progress --s3-acl=public-read</code>

This is pretty much rsync but for cloud storage :) To configure my connection I had the following environment variables:
<pre><code class="language-bash">export RCLONE_CONFIG_MYS3_ACCESS_KEY_ID=$CELLAR_ADDON_KEY_ID
export RCLONE_CONFIG_MYS3_SECRET_ACCESS_KEY=$CELLAR_ADDON_KEY_SECRET
export RCLONE_CONFIG_MYS3_ENDPOINT=$CELLAR_ADDON_HOST
export RCLONE_CONFIG_MYS3_TYPE="s3"
</code></pre>
I copied them from the my Cellar add-on dashboard. We could stop here. You have a static website hosted on Clever Cloud without a running application. Let's take this a bit further by using an application to build the website.
<h2 id="build-and-upload-your-static-site">Build and Upload your Static Site</h2>
I wrote about Hugo in a <a href="https://www.clever.cloud/blog/engineering/2020/06/18/deploy-static-site-hugo/">previous post</a>. This is going to be almost similar so I'll be quick.

The plan is to create a Clever Cloud application. Each time you will push new content to this application, it will start, generate the Hugo website, upload it to Cellar then stop itself.

Assuming you have installed Hugo and clever-tools, this is everything you need to do to have a generated website:
<pre><code class="language-bash">mkdir hugo-cellar-static # Create the site root folder
cd hugo-cellar-static/
hugo new site . # Generate a new Hugo site
git init # initialize the git repository
git submodule add https://github.com/jakewies/hugo-theme-codex themes/codex # add a theme
cp themes/codex/exampleSite/config.toml config.toml # copy the default configuration
cp -r themes/codex/exampleSite/content/ . # copy default content for the exemple
gedit config.toml  # edit the configuration, like the theme or the baseUrl
clever create --type static-apache myapp # Create a new clever cloud application
clever service link-addon MyCellar # link the app to the Cellar add-on 
cat ~/.config/clever-cloud  # Get the clever-tools token
</code></pre>
At that point you should have created a website structure and a Clever Cloud application. These are the environment variables needed to configure it:
<pre><code class="language-bash">CC_PHP_VERSION="7"
CC_PRE_RUN_HOOK="./hugo.sh" # A prerun hook to execute the build and sync it to Cellar
CC_RUN_SUCCEEDED_HOOK="clever stop" # use clever-tools to turn off the app when finished 
CLEVER_SECRET="xxxx" # Tokens for clever-tools
CLEVER_TOKEN="xxxxx" # Tokens for clever-tools
DL_RCLONE_VERSION="1.52.1" # which version of rclone to use
HUGO_VERSION="0.62.0" # which version of hugo to use
MY_DOMAIN="blog.ldoguin.name/" # The name of the bucket to sync
PORT="8080"
HUGO_ENV="production"
</code></pre>
The <code>clever stop</code> trick is likely to be replaced by something cleaner in the coming weeks, with something like a task or job. The build and sync of the site is done when the pre run hook executes <code>hugo.sh</code>, which has the following content:
<pre><code class="language-bash"># Configure rclone Cellar connection
export RCLONE_CONFIG_MYS3_ACCESS_KEY_ID=$CELLAR_ADDON_KEY_ID
export RCLONE_CONFIG_MYS3_SECRET_ACCESS_KEY=$CELLAR_ADDON_KEY_SECRET
export RCLONE_CONFIG_MYS3_ENDPOINT=$CELLAR_ADDON_HOST
export RCLONE_CONFIG_MYS3_TYPE="s3"

# Download and unpack rclone and hugo
wget https://downloads.rclone.org/v$DL_RCLONE_VERSION/rclone-v$DL_RCLONE_VERSION-linux-amd64.zip
wget https://github.com/gohugoio/hugo/releases/download/v$HUGO_VERSION/hugo_extended_"$HUGO_VERSION"_Linux-64bit.tar.gz
unzip rclone-v$DL_RCLONE_VERSION-linux-amd64.zip
tar xvf hugo_extended_"$HUGO_VERSION"_Linux-64bit.tar.gz

# Execute the site generation with Hugo
chmod +x ./hugo
./hugo --gc --minify

# Sync the site to Cellar
./rclone-v$DL_RCLONE_VERSION-linux-amd64/rclone sync ./public mys3:$MY_DOMAIN --progress --s3-acl=public-read
</code></pre>
Now what's left to do is add and commit all the files and deploy.
<pre><code class="language-bash">git add .  # add the current folder to git
git commit -m"init" # commit
clever deploy # Deploy your website
</code></pre>
The application will start, generate the website and sync it to Cellar then stop itself. So there it is you will still have your website running, but without running an application.

Please let us know what you think and what kind of features you would like to see supported for static sites :)]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Cellar a S3-like service for Rails&#8217; Active Storage</title>
		<link>https://www.clever.cloud/blog/engineering/2020/05/28/cellar-s3-active-storage-ruby-on-rails/</link>
		
		<dc:creator><![CDATA[Valeriane Venance]]></dc:creator>
		<pubDate>Thu, 28 May 2020 14:20:00 +0000</pubDate>
				<category><![CDATA[Engineering]]></category>
		<category><![CDATA[active storage]]></category>
		<category><![CDATA[cellar]]></category>
		<category><![CDATA[rails attachments]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<guid isPermaLink="false">https://www2.cleverapps.io/wp/blog/technology/2020/05/28/cellar-s3-active-storage-ruby-on-rails/</guid>

					<description><![CDATA[<p><img width="1400" height="540" src="https://cdn.clever-cloud.com/uploads/2021/08/railsbanner-1.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="railsbanner 1" decoding="async" loading="lazy" srcset="https://cdn.clever-cloud.com/uploads/2021/08/railsbanner-1.png 1400w, https://cdn.clever-cloud.com/uploads/2021/08/railsbanner-1-300x116.png 300w, https://cdn.clever-cloud.com/uploads/2021/08/railsbanner-1-1024x395.png 1024w, https://cdn.clever-cloud.com/uploads/2021/08/railsbanner-1-768x296.png 768w, https://cdn.clever-cloud.com/uploads/2021/08/railsbanner-1-1368x528.png 1368w" sizes="auto, (max-width: 1400px) 100vw, 1400px" /></p><p>Introduced with the release of Rails 5.2 , Active Storage replaces previous solutions for storing user videos, images, PDF, etc..</p>
<p>In the documentation only three implementations are demonstrated and they all rely on cloud services. Today I am going to show you how to use it to be Clever Cloud compatible.</p>
<span id="more-2827"></span>
<p>To follow this tutorial you must already have a Rails &gt;= 5.2 application running on Clever Cloud with a PostgreSQL database. You can <a href="https://www.clever.cloud/blog/engineering/2019/05/07/setup-your-ruby-on-rails-online-dev-environment/">read this</a> if you need a basic setup.</p>
<h2 id="tell-rails-you-want-to-use-active-storage">Tell Rails you want to use Active Storage</h2>
<p>In your console, at the root of your rails project repository, type in <code>$ rails active_storage:install</code>. This will create two migration files under <code>./db/migrate</code>. These migrations will create two new tables: <code>active_storage_blobs</code> and <code>active_storage_attachments</code>, which is everything we need to start storing user attachments without adding new columns to our already existent models. Let&#39;s run them with <code>$ rake db:migrate</code> to have a local database up to date. You can now use <code>has_one_attached :&lt;the name you want to give&gt;</code> on any of your models to add an attachment on it.</p>
<h2 id="setting-up-the-application-for-clever-cloud">Setting up the application for Clever Cloud</h2>
<p>As we do provide AWS S3 like storage at Clever Cloud, we will use AWS gem and define custom endpoints. Add <code>gem &quot;aws-sdk-s3&quot;, require: false</code> to your Gemfile. Run <code>$ bundle install</code>. Then in <code>config/environments/production.yml</code> add <code>config.active_storage.service = :clevercloud</code>. Now in <code>config/storage.yml</code> add the following lines:</p>
<pre><code class="language-yaml">clevercloud:
  service: S3
  access_key_id: &lt;%= ENV[&#39;CELLAR_ADDON_KEY_ID&#39;] %&gt;
  secret_access_key: &lt;%= ENV[&#39;CELLAR_ADDON_KEY_SECRET&#39;] %&gt;
  region: us-east-1
  bucket: &lt;%= ENV[&#39;CELLAR_ADDON_BUCKET_NAME&#39;] %&gt;
  endpoint: &lt;%= ENV[&#39;CELLAR_ADDON_ENDPOINT&#39;] %&gt;
</code></pre>
<p>I must make clear here that we do not use regions at Clever Cloud, but the aws-sdk-s3 gem needs it; otherwise it throws an <code>AWS::Errors::MissingRegionError</code> error. And we do not want a 500 in production. It is the usage of <code>endpoint</code> that will give us the right endpoint generated by the gem.</p>
<h2 id="creating-our-storage-on-clever-cloud">Creating our storage on Clever Cloud</h2>
<p>Under the organization where your Rails application is deployed, select <strong>Create</strong>, <strong>an add-on</strong>, <strong>Cellar S3 storage</strong>. When prompted <strong>Select the applications that will use this add-on:</strong> select your Rails application. Name it and let it be deployed. Once this is done, in your <strong>addon dashboard</strong>, create a bucket. Keep its name. Now, under <strong>Environment variables</strong> in your Rails application, add the following:</p>
<pre><code class="language-bash">CELLAR_ADDON_BUCKET_NAME=&lt;your bucket name&gt;
CELLAR_ADDON_ENDPOINT=https://cellar-c2.services.clever-cloud.com
</code></pre>
<p>You can now commit the local files we have changed and push them to your Clever Cloud remote to enjoy Active Storage in production.</p>
<p>Do not forget to edit your safe params in your controllers, forms and permissions.</p>
<p>Happy storing!</p>
]]></description>
										<content:encoded><![CDATA[<p><img width="1400" height="540" src="https://cdn.clever-cloud.com/uploads/2021/08/railsbanner-1.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="railsbanner 1" decoding="async" loading="lazy" srcset="https://cdn.clever-cloud.com/uploads/2021/08/railsbanner-1.png 1400w, https://cdn.clever-cloud.com/uploads/2021/08/railsbanner-1-300x116.png 300w, https://cdn.clever-cloud.com/uploads/2021/08/railsbanner-1-1024x395.png 1024w, https://cdn.clever-cloud.com/uploads/2021/08/railsbanner-1-768x296.png 768w, https://cdn.clever-cloud.com/uploads/2021/08/railsbanner-1-1368x528.png 1368w" sizes="auto, (max-width: 1400px) 100vw, 1400px" /></p><p>Introduced with the release of Rails 5.2 , Active Storage replaces previous solutions for storing user videos, images, PDF, etc..</p>
<p>In the documentation only three implementations are demonstrated and they all rely on cloud services. Today I am going to show you how to use it to be Clever Cloud compatible.</p>
<span id="more-2827"></span>
<p>To follow this tutorial you must already have a Rails &gt;= 5.2 application running on Clever Cloud with a PostgreSQL database. You can <a href="https://www.clever.cloud/blog/engineering/2019/05/07/setup-your-ruby-on-rails-online-dev-environment/">read this</a> if you need a basic setup.</p>
<h2 id="tell-rails-you-want-to-use-active-storage">Tell Rails you want to use Active Storage</h2>
<p>In your console, at the root of your rails project repository, type in <code>$ rails active_storage:install</code>. This will create two migration files under <code>./db/migrate</code>. These migrations will create two new tables: <code>active_storage_blobs</code> and <code>active_storage_attachments</code>, which is everything we need to start storing user attachments without adding new columns to our already existent models. Let&#39;s run them with <code>$ rake db:migrate</code> to have a local database up to date. You can now use <code>has_one_attached :&lt;the name you want to give&gt;</code> on any of your models to add an attachment on it.</p>
<h2 id="setting-up-the-application-for-clever-cloud">Setting up the application for Clever Cloud</h2>
<p>As we do provide AWS S3 like storage at Clever Cloud, we will use AWS gem and define custom endpoints. Add <code>gem &quot;aws-sdk-s3&quot;, require: false</code> to your Gemfile. Run <code>$ bundle install</code>. Then in <code>config/environments/production.yml</code> add <code>config.active_storage.service = :clevercloud</code>. Now in <code>config/storage.yml</code> add the following lines:</p>
<pre><code class="language-yaml">clevercloud:
  service: S3
  access_key_id: &lt;%= ENV[&#39;CELLAR_ADDON_KEY_ID&#39;] %&gt;
  secret_access_key: &lt;%= ENV[&#39;CELLAR_ADDON_KEY_SECRET&#39;] %&gt;
  region: us-east-1
  bucket: &lt;%= ENV[&#39;CELLAR_ADDON_BUCKET_NAME&#39;] %&gt;
  endpoint: &lt;%= ENV[&#39;CELLAR_ADDON_ENDPOINT&#39;] %&gt;
</code></pre>
<p>I must make clear here that we do not use regions at Clever Cloud, but the aws-sdk-s3 gem needs it; otherwise it throws an <code>AWS::Errors::MissingRegionError</code> error. And we do not want a 500 in production. It is the usage of <code>endpoint</code> that will give us the right endpoint generated by the gem.</p>
<h2 id="creating-our-storage-on-clever-cloud">Creating our storage on Clever Cloud</h2>
<p>Under the organization where your Rails application is deployed, select <strong>Create</strong>, <strong>an add-on</strong>, <strong>Cellar S3 storage</strong>. When prompted <strong>Select the applications that will use this add-on:</strong> select your Rails application. Name it and let it be deployed. Once this is done, in your <strong>addon dashboard</strong>, create a bucket. Keep its name. Now, under <strong>Environment variables</strong> in your Rails application, add the following:</p>
<pre><code class="language-bash">CELLAR_ADDON_BUCKET_NAME=&lt;your bucket name&gt;
CELLAR_ADDON_ENDPOINT=https://cellar-c2.services.clever-cloud.com
</code></pre>
<p>You can now commit the local files we have changed and push them to your Clever Cloud remote to enjoy Active Storage in production.</p>
<p>Do not forget to edit your safe params in your controllers, forms and permissions.</p>
<p>Happy storing!</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
