hosting-on-firebase.md (2476B)
1 --- 2 title: Host on Firebase 3 linktitle: Host on Firebase 4 description: You can use Firebase's free tier to host your static website; this also gives you access to Firebase's NOSQL API. 5 date: 2017-03-12 6 publishdate: 2017-03-12 7 lastmod: 2017-03-15 8 categories: [hosting and deployment] 9 keywords: [hosting,firebase] 10 authors: [Michel Racic] 11 menu: 12 docs: 13 parent: "hosting-and-deployment" 14 weight: 20 15 weight: 20 16 sections_weight: 20 17 draft: false 18 toc: true 19 aliases: [] 20 --- 21 22 ## Assumptions 23 24 1. You have an account with [Firebase][signup]. (If you don't, you can sign up for free using your Google account.) 25 2. You have completed the [Quick Start][] or have a completed Hugo website ready for deployment. 26 27 ## Initial setup 28 29 Go to the [Firebase console][console] and create a new project (unless you already have a project). You will need to globally install `firebase-tools` (node.js): 30 31 ``` 32 npm install -g firebase-tools 33 ``` 34 35 Log in to Firebase (setup on your local machine) using `firebase login`, which opens a browser where you can select your account. Use `firebase logout` in case you are already logged in but to the wrong account. 36 37 38 ``` 39 firebase login 40 ``` 41 In the root of your Hugo project, initialize the Firebase project with the `firebase init` command: 42 43 ``` 44 firebase init 45 ``` 46 From here: 47 48 1. Choose Hosting in the feature question 49 2. Choose the project you just set up 50 3. Accept the default for your database rules file 51 4. Accept the default for the publish directory, which is `public` 52 5. Choose "No" in the question if you are deploying a single-page app 53 54 ## Deploy 55 56 To deploy your Hugo site, execute the `firebase deploy` command, and your site will be up in no time: 57 58 ``` 59 hugo && firebase deploy 60 ``` 61 62 ## CI Setup 63 64 You can generate a deploy token using 65 66 67 ``` 68 firebase login:ci 69 ``` 70 71 You can also set up your CI (e.g., with [Wercker][]) and add the token to a private variable like `$FIREBASE_DEPLOY_TOKEN`. 72 73 {{% note %}} 74 This is a private secret and it should not appear in a public repository. Make sure you understand your chosen CI and that it's not visible to others. 75 {{% /note %}} 76 77 You can then add a step in your build to do the deployment using the token: 78 79 ``` 80 firebase deploy --token $FIREBASE_DEPLOY_TOKEN 81 ``` 82 83 ## Reference links 84 85 * [Firebase CLI Reference](https://firebase.google.com/docs/cli/#administrative_commands) 86 87 [console]: https://console.firebase.google.com 88 [Quick Start]: /getting-started/quick-start/ 89 [signup]: https://console.firebase.google.com/