Managing Versions and Rolling Back Deployments

Tutorial 4 of 5

1. Introduction

In this tutorial, we will delve into the process of managing different versions of your application on Firebase Hosting and how to rollback to a previous deployment if the need arises.

You will learn:
- How to deploy your app to Firebase Hosting
- How to manage different versions of your app
- How to rollback to a previous deployment

Prerequisites:
- Basic knowledge of Firebase and Firebase Hosting
- A Firebase project setup

2. Step-by-Step Guide

Initial Deployment

Before you can manage different versions of your app, you need to deploy your app to Firebase Hosting. This can be done by using the Firebase CLI and the firebase deploy command.

Version Management

Firebase Hosting stores every successful deployment of your site in a version. You can view all the versions of your site in the Firebase console.

Rolling Back Deployments

If you need to revert your site to a previous version, Firebase Hosting allows you to rollback to any previous deployment.

3. Code Examples

Deploying Your App

Here is an example of deploying your app using the Firebase CLI:

# Navigate to your project directory
cd my_project

# Deploy your app
firebase deploy

In this example, the cd command is used to navigate to your project directory. The firebase deploy command then deploys your app to Firebase Hosting.

Rolling Back a Deployment

Here is an example of rolling back a deployment:

# Rollback to a previous deployment
firebase hosting:clone myapp.com:previous-version myapp.com:live

In this example, myapp.com:previous-version is the source version that you want to rollback to and myapp.com:live is the destination version.

4. Summary

In this tutorial, you've learned how to deploy your app to Firebase Hosting, manage different versions of your app, and rollback to a previous deployment.

Next steps include exploring other features of Firebase Hosting such as custom domains and SSL configuration.

Additional resources:
- Firebase Hosting Documentation: https://firebase.google.com/docs/hosting
- Firebase CLI Reference: https://firebase.google.com/docs/cli

5. Practice Exercises

  1. Deploy a simple "Hello World" app to Firebase Hosting.
  2. Make a change to your app and deploy it again. Then, rollback to the previous version.

Solutions:

  1. Here is an example of deploying a "Hello World" app:

```bash
# Initialize Firebase in your project directory
firebase init

# Create a simple index.html file
echo "

Hello World

" > index.html

# Deploy your app
firebase deploy
```

  1. Here is an example of making a change and rolling back:

```bash
# Make a change to your app
echo "

Hello Firebase

" > index.html

# Deploy your app
firebase deploy

# Rollback to the previous version
firebase hosting:clone myapp.com:previous-version myapp.com:live
```

In the first exercise, you're initializing Firebase in your project directory, creating a simple "Hello World" app and deploying it. In the second exercise, you're making a change to your app, deploying it, and then rolling back to the previous version.