<?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>Firebase &#8211; Digitaldocblog</title>
	<atom:link href="https://digitaldocblog.com/tag/firebase/feed/" rel="self" type="application/rss+xml" />
	<link>https://digitaldocblog.com</link>
	<description>Various digital documentation</description>
	<lastBuildDate>Fri, 12 Aug 2022 18:08:11 +0000</lastBuildDate>
	<language>de</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>

<image>
	<url>https://digitaldocblog.com/wp-content/uploads/2022/08/cropped-website-icon-star-500-x-452-transparent-32x32.png</url>
	<title>Firebase &#8211; Digitaldocblog</title>
	<link>https://digitaldocblog.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Initialization and Deployment of a firebase project</title>
		<link>https://digitaldocblog.com/webserver/initialization-and-deployment-of-a-firebase-project/</link>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Thu, 19 Dec 2019 19:00:00 +0000</pubDate>
				<category><![CDATA[Webserver]]></category>
		<category><![CDATA[Firebase]]></category>
		<category><![CDATA[Google]]></category>
		<guid isPermaLink="false">https://digitaldocblog.com/?p=94</guid>

					<description><![CDATA[The use of Firebase Services requires the global installation of the Firebase Command Line Tools (Firebase CLI) on your computer. Note: I will not go into the installation of the&#8230;]]></description>
										<content:encoded><![CDATA[
<p>The use of Firebase Services requires the global installation of the Firebase Command Line Tools (Firebase CLI) on your computer.<br></p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>Note: I will not go into the installation of the Firebase CLI here. How this is installed on the computer is well described in <a href="https://www.fullstackfirebase.com/firebase-console/walkthrough">Full-Stack Firebase</a> and in the <a href="https://firebase.google.com/docs/cli">Google documentation</a>.</p></blockquote>



<h4 class="wp-block-heading">Overview</h4>



<p>Before I start a firebase project, I first think of a suitable name for the project and create one project for development <em>(Firebase Project Dev)</em> and another different one for production <em>(Firebase Project Prod)</em> in the <a href="https://console.firebase.google.com/">Firebase Console</a>. As a result, 2 projects with the following names are created in the Firebase Console <em>(see the Browser side chapter below)</em>.</p>



<ul class="wp-block-list"><li>myproject-Dev</li><li>myproject-Prod<br></li></ul>



<p>In addition, 2 directories must be created on the computer. One directory as <em>Directory Dev</em> and another as <em>Directory Prod</em>. Ideally, these directories have the same names as the projects in the Firebase Console <em>(see the Command line side chapter below)</em>.</p>



<ul class="wp-block-list"><li>myproject-Dev</li><li>myproject-Prod<br></li></ul>



<p>As shown in the figure above, the directories on the computer and the Firebase projects logically each represent a system. So in my example I have a <em>Dev System</em> and a <em>Prod System</em>. The two systems Prod and Dev are completely separated from each other.</p>



<p>The system development takes place on the computer. The files and directories for development are located on the computer directly in the <code>myproject-Dev</code> directory. The public subdirectory in the myproject-Dev directory contains all the files and directories relevant to the dev depolyment. The <em>Dev deploy</em> process copies these relevant files and directories for dev deployment there <em>(see the Dev deployment chapter below)</em>.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>Note: The system development is not part of this tutorial.</p></blockquote>



<p>The files and directories for production are in the public subdirectory in the <code>myproject-Prod</code> directory. The process <em>Prod deploy</em> copies these relevant files and directories for the Prod deployment there <em>(see the chapter Prod deployment below)</em>.</p>



<p>The directories and files for Firebase hosting are copied from the relevant public directory and are performed by the Firebase CLI function <code>firebase deploy</code>. In our example here we have hosting of the <em>Dev System</em> and hosting of the <em>Prod System</em>. The <em>Dev System</em> is used for testing under production conditions. The <em>Prod System</em> represents the actual live system on the web.</p>



<h4 class="wp-block-heading">Browser side</h4>



<p>The following activities are carried out in the browser.</p>



<p>How a Firebase project is created in the firebase console can be read in detail very well on <a href="https://www.fullstackfirebase.com/firebase-console/walkthrough">Full-Stack Firebase</a>. I will only go into the basic steps of creating a project here.</p>



<p>First we go to the <a href="https://console.firebase.google.com/">Firebase Console</a> in the browser. When initially creating a firebase project in the Firebase Console, the following steps are carried out. With this procedure we create the two projects <code>myproject-Dev</code> and <code>myproject-Prod</code> in the Firebase Console.</p>



<ol class="wp-block-list"><li>Click Add Project</li><li>Assign a project name</li><li>Switch on Google Analytics (default) and configure Analytics account<br></li></ol>



<p>After the initial creation of the project in the Firebase Console, you go directly to the project overview in the project console of the newly created project. Here a Firebase app must be added to the project. In order to fully understand this tutorial, a web app is added to the project to create a website (iOS or Android mobile apps can also be added here later).</p>



<ol class="wp-block-list"><li>Click Add Web-App</li><li>Register the Alias name for the Web-App <code>myproject-Dev-WebApp</code></li><li>Firebase hosting is to be set up for this web app</li><li>Then follow 3 steps for information that are simply noted (add Firebase SDK, install Firebase CLI, provide Firebase hosting)</li><li>Then go back to the project console project overview<br></li></ol>



<p>In the project overview, click on the settings of the web app <code>myproject-Dev-WebApp</code> in the top left of the main window. The following configurations must be made here in the General area:</p>



<ol class="wp-block-list"><li>Google Cloud Platform (GCP) resource location</li><li>Support Email Address<br></li></ol>



<p>When setting the default location for the cloud resources, it is important to know that this can only be done once here at this point. I choose here as the location of the cloud resources <code>europe-west3</code>. At this point, of course, any other location can be selected depending on which is meaningful or necessary for the developer.</p>



<p>This process must also be repeated for <code>myproject-Prod</code>.</p>



<h4 class="wp-block-heading">Command line side</h4>



<p>The following activities are carried out in the terminal or on the command line of the computer. The computer I use is a Mac. As mentioned above these steps require the installation of the Firebase CLI.</p>



<p>First you log on to the Firebase Console. To do this, the <code>firebase login</code> command must be entered in the command line. Then all other commands can be entered in the command line.</p>



<p>With the command <code>firebase projects:list</code> in the command line the projects created in the firebase console can now be listed.</p>



<p>|Project Display Name   |Project ID            |Resource Location ID |</p>



<p>|&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;|&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-|&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;|</p>



<p>|myproject-Prod 	      | myproject-prod-19842 | europe-west3        |<br>|myproject-Dev 	  	    | myproject-dev-ace74  | europe-west3        |<br></p>



<p>Then I create two folders locally on my computer, one for development and one for production and initialize firebase in each of the folders.</p>



<p>Later in this article I&#8217;ll go into how depolyment from development to production takes place.</p>



<p>In order to initialize the Firebase project on the computer the following steps have to be followed.</p>



<p><strong>Step 0</strong>: Create Folders on the computer</p>



<p>In the initial situation, I have already created 2 folders on my computer: One for development and a different one for production. These folders are:</p>



<ul class="wp-block-list"><li>myproject-Dev</li><li>myproject-Prod<br></li></ul>



<pre class="wp-block-code"><code>Patricks-MBP:firebase-test patrick$ ls -l
total 0
drwxr-xr-x  2 patrick  staff  64 17 Dez 17:26 myproject-Dev
drwxr-xr-x  2 patrick  staff  64 17 Dez 17:25 myproject-Prod
Patricks-MBP:firebase-test patrick$

</code></pre>



<p>First I initialize firebase for <code>myproject-Dev</code>. The Steps 1 to the final step must be repeated in the same way for <code>myproject-Prod</code>.</p>



<p>To do this, I change to the myproject-Dev directory on my computer and enter the command <code>firebase init</code> on the command line of my computer.</p>



<pre class="wp-block-code"><code>Patricks-MBP:firebase-test patrick$ cd myproject-Dev
Patricks-MBP:myproject-Dev patrick$ firebase init

</code></pre>



<p><em>firebase init</em>: The command <code>firebase-init</code> links the development project previously created in the Firebase Console to the <code>myproject-Dev</code> directory. After entering the command, the developer has to complete different stepts to setup the project. Once the process has been completed, various files are created in <code>myproject-Dev</code>, which I will explain in parts below.</p>



<p>The first step to be completed by the developer relates to the Firebase services to be used. I will use firestore, hosting and storage in this example.</p>



<p><strong>Step 1</strong>: Initialize a Firebase project</p>



<pre class="wp-block-code"><code>Patricks-MBP:myproject-Dev patrick$ firebase init

     ######## #### ########  ######## ########     ###     ######  ########
     ##        ##  ##     ## ##       ##     ##  ##   ##  ##       ##
     ######    ##  ########  ######   ########  #########  ######  ######
     ##        ##  ##    ##  ##       ##     ## ##     ##       ## ##
     ##       #### ##     ## ######## ########  ##     ##  ######  ########

You're about to initialize a Firebase project in this directory:

  /Users/patrick/Sites/dev/tutorials/firebase-test/myproject-Dev

? Which Firebase CLI features do you want to set up for this folder? Press Space to select features, then Enter to confirm your choices.
 ◯ Database: Deploy Firebase Realtime Database Rules
 ◉ Firestore: Deploy rules and create indexes for Firestore
 ◯ Functions: Configure and deploy Cloud Functions
 ◉ Hosting: Configure and deploy Firebase Hosting sites
❯◉ Storage: Deploy Cloud Storage security rules
 ◯ Emulators: Set up local emulators for Firebase features

</code></pre>



<p><em>Firestore</em>: Modern <code>json</code> database. This database can be accessed via the JavaScript SDK offered by Google in the JavaScript of the application. Access rights to the database are controlled via security rules that can be configured locally and loaded into the project using the deployment process.</p>



<p><em>Hosting</em>: Self-explanatory. The project can be hosted on a Google webserver.</p>



<p><em>Storage</em>: File server that can also be accessed via the JavaScript SDK in the application&#8217;s JavaScript. Access rights to the cloud storage are controlled via security rules that can be configured locally and loaded into the project using the deployment process.</p>



<p>After step 1 has been completed, the project is connected to the current folder on the computer (the directory <code>myproject-Dev</code> we are in).</p>



<p>After the first step has been completed with Enter, the second step is to connect the project directory we are in on the computer <code>myproject-Dev</code> to the Firebase Project <code>myproject-Dev</code>, which was previously created in the Firebase Console.</p>



<p><strong>Step 2</strong>: Project Setup</p>



<pre class="wp-block-code"><code>=== Project Setup

First, let's associate this project directory with a Firebase project.
You can create multiple project aliases by running firebase use --add,
but for now we'll just set up a default project.

? Please select an option: Use an existing project
? Select a default Firebase project for this directory:  
❯ myproject-dev-ace74 (myproject-Dev)
  myproject-prod-19842 (myproject-Prod)

</code></pre>



<p>Steps 3 to 5 configure the services previously selected in Step 1.</p>



<p><strong>Step 3</strong>: Firestore Setup</p>



<pre class="wp-block-code"><code>=== Firestore Setup

Firestore Security Rules allow you to define how and when to allow
requests. You can keep these rules in your project directory
and publish them with firebase deploy.

? What file should be used for Firestore Rules? firestore.rules

Firestore indexes allow you to perform complex queries while
maintaining performance that scales with the size of the result
set. You can keep index definitions in your project directory
and publish them with firebase deploy.

? What file should be used for Firestore indexes? firestore.indexes.json

</code></pre>



<p><strong>Step 4</strong> Hosting Setup</p>



<pre class="wp-block-code"><code>=== Hosting Setup

Your public directory is the folder (relative to your project directory) that
will contain Hosting assets to be uploaded with firebase deploy. If you
have a build process for your assets, use your build's output directory.

? What do you want to use as your public directory? public
? Configure as a single-page app (rewrite all urls to /index.html)? Yes
&#x2714;  Wrote public/index.html

</code></pre>



<p><strong>Step 5</strong>: Storage Setup</p>



<pre class="wp-block-code"><code>=== Storage Setup

Firebase Storage Security Rules allow you to define how and when to allow
uploads and downloads. You can keep these rules in your project directory
and publish them with firebase deploy.

? What file should be used for Storage Rules? storage.rules

</code></pre>



<p><strong>Final Step</strong>: Writing Files</p>



<pre class="wp-block-code"><code>i  Writing configuration info to firebase.json...
i  Writing project information to .firebaserc...
i  Writing gitignore file to .gitignore...

&#x2714;  Firebase initialization complete!

</code></pre>



<p>The directory <code>myproject-Dev</code> now has the following content.</p>



<pre class="wp-block-code"><code>Patricks-MBP:myproject-Dev patrick$ ls -l
total 32
-rw-r--r--  1 patrick  staff  379 18 Dez 07:30 firebase.json
-rw-r--r--  1 patrick  staff  563 18 Dez 07:27 firestore.indexes.json
-rw-r--r--  1 patrick  staff  132 18 Dez 07:27 firestore.rules
drwxr-xr-x  3 patrick  staff   96 18 Dez 07:29 public
-rw-r--r--  1 patrick  staff  138 18 Dez 07:30 storage.rules

</code></pre>



<p>Here you can see that the files for controlling access and indexes to the firestore and the files for controlling access to storage were created. Rules and indexes are transferred with the <code>firebase deploy</code> command. It is therefore important to enter any changes to the rules that may have been made during development in the Firebase Console here.</p>



<p>In addition, the public directory was created. The application is deployed from this directory with the <code>firebase deploy</code> command.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>Note: I use a local apache web server for development on my Mac. This web server is configured so that websites in a local directory within my user directory are displayed as private websites (localhost). The directory <code>myproject-Dev</code> is created under localhost. In this respect, html files, css and Javascript files etc. can be created in <code>myproject-Dev</code> directory and displayed from there via the local web server in the browser by entering the url <em>localhost/~user/myproject-Dev</em>. This helps the developer to see his results and to do some debugging where necessary. A very good description of how to set up a local web server on a Mac can be found at <a href="https://websitebeaver.com/set-up-localhost-on-macos-high-sierra-apache-mysql-and-php-7-with-sslhttps">Website Beaver</a>.</p></blockquote>



<p>As an example for a typical web application, the following directories and files must be created in the <code>myproject-Dev</code> directory.</p>



<ul class="wp-block-list"><li>css Directory<br><ul>
			<li>mystyles.css File</li>
		</ul></li><li>script Directotry<br><ul>
			<li>main.js File</li>
		</ul></li><li>images Directory<br><ul>
			<li>.png or jpg. Files</li>
		</ul></li><li>dev-versions Directory</li><li>index.html File</li><li>deploy-dev File</li><li>deploy-prod File<br></li></ul>



<p>The directories <code>css</code>, <code>script</code> and <code>images</code> and their files are created for web application development. The <code>dev-versions</code> directory is is used for versioning the web application development results.</p>



<p>The files <code>deploy-dev</code> and <code>deploy-prod</code> each contain a script for performing the respective deployment either in the Dev or Prod.</p>



<p>A typical directory structure in <code>myproject-Dev</code> looks like this.</p>



<pre class="wp-block-code"><code>Patricks-MBP:myproject-Dev patrick$ ls -l
total 48
drwxr-xr-x  3 patrick  staff   96 18 Dez 11:09 css
-rwxr--r--  1 patrick  staff  251 18 Dez 15:00 deploy-dev
-rwxr--r--  1 patrick  staff  240 18 Dez 14:54 deploy-prod
drwxr-xr-x  3 patrick  staff   96 18 Dez 15:01 dev-versions
-rw-r--r--  1 patrick  staff  379 18 Dez 07:30 firebase.json
-rw-r--r--  1 patrick  staff   10 18 Dez 12:31 firestore.indexes.json
-rw-r--r--  1 patrick  staff   31 18 Dez 11:05 firestore.rules
drwxr-xr-x  4 patrick  staff  128 18 Dez 12:32 images
-rw-r--r--  1 patrick  staff  386 18 Dez 11:31 index.html
drwxr-xr-x  8 patrick  staff  256 18 Dez 15:01 public
drwxr-xr-x  3 patrick  staff   96 18 Dez 11:10 script
-rw-r--r--  1 patrick  staff   31 18 Dez 11:05 storage.rules

</code></pre>



<p>The Firebase initialization for the development system is then completed.</p>



<p>As already mentioned above, this process must be repeated for <code>myproject-Prod</code> from step 1 in order to also initialize the production system accordingly. After initialization, only the <code>prod-versions</code> directory has to be created as subdirectory of the <code>myproject-Prod</code> directory. This directory is is used for versioning the web application.</p>



<p>A typical directory structure in <code>myproject-Prod</code> looks like this.</p>



<pre class="wp-block-code"><code>
Patricks-MBP:myproject-Prod patrick$ ls -l
total 32
-rw-r--r--  1 patrick  staff  27 18 Dez 18:45 firebase.json
-rw-r--r--  1 patrick  staff  28 18 Dez 18:45 firestore.indexes.json
-rw-r--r--  1 patrick  staff  21 18 Dez 18:46 firestore.rules
drwxr-xr-x  2 patrick  staff  64 18 Dez 15:15 prod-versions
drwxr-xr-x  2 patrick  staff  64 18 Dez 18:35 public
-rw-r--r--  1 patrick  staff  19 18 Dez 18:46 storage.rules

</code></pre>



<h4 class="wp-block-heading">Dev-Deployment</h4>



<p>To deploy the application to the Dev-System in Firebase, all the necessary files must  be copied to the public directory under <code>myproject-Dev</code>. The bash script <code>deploy-dev</code> does this.</p>



<pre class="wp-block-code"><code>Patricks-MBP:myproject-Dev patrick$ cat deploy-dev
#!/bin/bash

date=$(date +"%Y.%m.%d_%H.%M.%S")

mkdir dev-versions/dev-ver_$date

cp -Rip public dev-versions/dev-ver_$date

rm -R public/*

cp -ip index.html public
cp -Rip css public
cp -Rip script public
cp -Rip images public

</code></pre>



<p><code>deploy-dev</code> stores the current date and time in the variable <code>date</code>. Then a subdirectory named like <code>dev-ver_$date</code> is created under the directory <code>dev-versions</code> and the entire <code>public</code> directory is copied there. The <code>public</code> directory is then emptied and the new application files are copied to the <code>public</code> directory.</p>



<p>Then the command <code>firestore deploy</code> must be called on the command line and the deployment from the current public directory to the dev system is started.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>Note: The command <code>firestore deploy</code> could also be added to the deploy-dev script. I prefer to run this command separately afterwards.</p></blockquote>



<p>After the Firebase Deployment is complete, you get a project url in the command line with which you can access via the web the Dev-System that has just been published. Now the tests can be performed using the Dev-System url.</p>



<h3 class="wp-block-heading">Prod-Deployment</h3>



<p>After the tests have all been successfully completed, the application can be published in the Prod system.</p>



<p>We are still in the <code>myproject-Dev</code> directory.</p>



<p>The goal is to copy all files from the <code>public</code> directory in <code>myproject-Dev</code> into the <code>public</code> directory of <code>myproject-Prod</code>. The bash script <code>deploy-prod</code> does this.</p>



<pre class="wp-block-code"><code>Patricks-MBP:myproject-Dev patrick$ cat deploy-prod
#!/bin/bash

date=$(date +"%Y.%m.%d_%H.%M.%S")

mkdir ../myproject-Prod/prod-versions/prod-ver_$date

cp -Rip ../myproject-Prod/public ../myproject-Prod/prod-versions/prod-ver_$date

rm -R ../myproject-Prod/public/*

cp -Rip public/* ../myproject-Prod/public

</code></pre>



<p><code>deploy-prod</code> stores the current date and time in the variable <code>date</code>. Then on <code>myproject-Prod</code> a subdirectory named like <code>prod-ver_$date</code> is created under the directory <code>prod-versions</code> and the entire directory public is copied there. The public directory on myproject-Prod is then emptied.</p>



<p>The new application files are copied from the <code>public</code>directory in <code>myproject-Dev</code>to the <code>public</code> directory of <code>myproject-Prod</code>.</p>



<p>Then the command <code>firestore deploy</code> must be called on the command line and the deployment from the public directory to the prod system is started.</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>Note: The command <code>firestore deploy</code> could also be added to the deploy-prod script. I prefer to run this command separately afterwards.</p></blockquote>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
