Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

402 automate firebase resources creation v2 #449

Merged
merged 74 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
1551160
Create enable-firebase.sh
lpinon Nov 15, 2022
a23ea6c
Enable APIs
lpinon Nov 15, 2022
1d900ce
Create Firestore DB
lpinon Nov 15, 2022
79fdc96
Create Service Account Key
lpinon Nov 15, 2022
a158ab8
Create APPs
lpinon Nov 15, 2022
44fc2ff
Merge branch 'master' into feature/sp4-346-automate-firebase-resource…
lpinon Nov 15, 2022
9bec9a5
Unused green color !int
lpinon Nov 15, 2022
485c9f2
Merge branch 'master' into feature/sp4-346-automate-firebase-resource…
lpinon Nov 15, 2022
18b0ff2
Fixed typo !int
lpinon Nov 15, 2022
7a9418f
Merge branch 'feature/sp4-346-automate-firebase-resources-creation' o…
lpinon Nov 15, 2022
96294a1
Added Firebase service enabling !int
lpinon Nov 15, 2022
09d5a08
Merge branch 'master' into feature/sp4-346-automate-firebase-resource…
lpinon Nov 16, 2022
53328ad
Added extra roles needed for firebase
lpinon Nov 16, 2022
ea3b994
Extra APIs for firebase
lpinon Nov 16, 2022
723ee4b
Parametrization
lpinon Nov 17, 2022
4c9ee36
Merge branch 'master' into feature/sp4-346-automate-firebase-resource…
lpinon Nov 17, 2022
8c44f72
Update enable-firebase.sh
capf4bbo Nov 18, 2022
1266f6c
Update enable-firebase.sh
capf4bbo Nov 21, 2022
4513538
Docs added
capf4bbo Nov 21, 2022
b6b4c1e
Automatic generation of documentation
capf4bbo Nov 21, 2022
91a2701
Update setup-firebase.sh
capf4bbo Nov 21, 2022
ab73621
Merge branch 'feature/sp4-346-automate-firebase-resources-creation' o…
capf4bbo Nov 21, 2022
d4a946f
Update setup-firebase.asciidoc
capf4bbo Nov 21, 2022
97d9f89
Automatic generation of documentation
capf4bbo Nov 21, 2022
16cd958
Update setup-firebase.sh
capf4bbo Nov 21, 2022
c6960fe
Merge branch 'feature/sp4-346-automate-firebase-resources-creation' o…
capf4bbo Nov 21, 2022
126a21a
Update setup-firebase.asciidoc
capf4bbo Nov 21, 2022
56d5596
Automatic generation of documentation
capf4bbo Nov 21, 2022
f7ac1d2
Keystore, sha keys and web map api service
capf4bbo Nov 22, 2022
7263758
Merge branch 'master' into feature/sp4-346-automate-firebase-resource…
capf4bbo Nov 22, 2022
85d1ff5
Update setup-firebase.sh
capf4bbo Nov 22, 2022
9e59db5
Update scripts/accounts/gcloud/create-project.sh
lpinon Nov 23, 2022
7954a77
Update scripts/accounts/gcloud/setup-firebase.sh
lpinon Nov 23, 2022
4b847a0
Update documentation/src/firebase/setup-firebase.asciidoc
lpinon Nov 23, 2022
10974d5
Automatic generation of documentation
lpinon Nov 23, 2022
d82cab8
Update scripts/accounts/gcloud/setup-firebase.sh
lpinon Nov 23, 2022
8962ce3
errors fix
capf4bbo Nov 24, 2022
daa4af0
Merge branch 'master' into 402-automate-firebase-resources-creation-v2
lpinon Nov 25, 2022
ba2225d
Set default project
lpinon Nov 25, 2022
77f4549
Hotfix disable not working steps !int
lpinon Nov 28, 2022
8950229
Rename firebase.json to disable conflicts
lpinon Nov 28, 2022
37d5026
Merge branch 'master' into 402-automate-firebase-resources-creation-v2
capf4bbo Nov 28, 2022
0019d5f
Fix for sha keys
capf4bbo Nov 28, 2022
c2dc6f6
Merge branch 'master' into 402-automate-firebase-resources-creation-v2
lpinon Nov 29, 2022
d0ea861
Automatic generation of documentation
lpinon Nov 29, 2022
0c350d5
Merge branch 'master' into 402-automate-firebase-resources-creation-v2
capf4bbo Nov 29, 2022
e5abfa2
Merge branch '402-automate-firebase-resources-creation-v2' of https:/…
capf4bbo Nov 29, 2022
4a901a2
Update setup-firebase.sh
capf4bbo Nov 29, 2022
a960e6d
Refactor Flags Parsing
lpinon Nov 29, 2022
4ec0763
Update setup-firebase.sh
capf4bbo Nov 29, 2022
e19daa9
Merge branch '402-automate-firebase-resources-creation-v2' of https:/…
lpinon Nov 29, 2022
b870f26
Check Firebase CLI if Firebase Project
lpinon Nov 29, 2022
ba697fd
Create Firebase Project using Firebase CLI
lpinon Nov 29, 2022
eb00b68
Create Firebase Project using Firebase CLI
lpinon Nov 29, 2022
64a49a5
Delete setup-firebase.asciidoc
lpinon Nov 29, 2022
d6bfed8
Firebase Documentation
lpinon Nov 29, 2022
62077e9
Add Firebase Project flag
lpinon Nov 29, 2022
0288082
Merge branch 'master' into 402-automate-firebase-resources-creation-v2
lpinon Nov 30, 2022
74132ab
Merge branch '402-automate-firebase-resources-creation-v2' of https:/…
capf4bbo Nov 30, 2022
c7cdf39
Update setup-firebase.asciidoc
lpinon Nov 30, 2022
8f0baae
Merge branch 'master' into 402-automate-firebase-resources-creation-v2
lpinon Nov 30, 2022
10f7295
!int
lpinon Nov 30, 2022
e203c99
Update scripts/accounts/gcloud/create-project.sh
capf4bbo Dec 1, 2022
ff0e2b4
Update scripts/accounts/gcloud/setup-firebase.sh
capf4bbo Dec 1, 2022
8f50447
Update scripts/accounts/gcloud/setup-firebase.sh
capf4bbo Dec 1, 2022
3369f38
Update scripts/accounts/gcloud/create-project.sh
capf4bbo Dec 1, 2022
99e9d26
Update setup-firebase.asciidoc
capf4bbo Dec 1, 2022
6e6a36b
Merge branch 'master' into 402-automate-firebase-resources-creation-v2
capf4bbo Dec 1, 2022
65cb677
Merge branch 'master' into 402-automate-firebase-resources-creation-v2
capf4bbo Dec 1, 2022
d0eeee8
Fix package name
lpinon Dec 2, 2022
4c4a014
Update setup-firebase.sh
capf4bbo Dec 2, 2022
3ea4c17
Merge branch 'master' into 402-automate-firebase-resources-creation-v2
capf4bbo Dec 13, 2022
a3913ea
Merge branch 'master' into 402-automate-firebase-resources-creation-v2
capf4bbo Dec 15, 2022
3b0cc38
Merge branch 'master' into 402-automate-firebase-resources-creation-v2
lpinon Dec 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions documentation/firebase/setup-firebase.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ setup-firebase.sh \
```
-n [Required] Name of the project.
-o, --output [Required] Output path to store credentials.
-r Region where to create Firestore Database.
-r [Required] Region where to create Firestore Database.
--enable-maps Enables APIs related to Maps services.
--setup-ios Enables IOS APIs and creates IOS App.
--setup-android Enables Android APIs and creates Android App.
Expand All @@ -45,8 +45,8 @@ TIP: This is non-exhaustive list. Make your own combination of flags if all of t

==== Creating a project and enable Maps SDK
[subs="attributes"]
./setup-firebase.sh -n <project name> -o ./output --enable-maps
./setup-firebase.sh -n <project name> -o ./output -r europe-west2 --enable-maps

==== Creating a project with ANDROID, IOS and WEB applications
[subs="attributes"]
./setup-firebase.sh -n <project name> -o ./output --setup-android --setup-ios --setup-web
./setup-firebase.sh -n <project name> -o ./output -r europe-west2 --setup-android --setup-ios --setup-web
2 changes: 2 additions & 0 deletions documentation/gcloud/setup-project.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ create-project.sh \
[-d <description>] \
[-f <folder>] \
[-o <organization>]
[--firebase]

```

Expand All @@ -42,6 +43,7 @@ create-project.sh \
-d Description for the new project.
-f Numeric ID of the folder for which the project will be configured.
-o Numeric ID of the organization for which the project will be configured.
--firebase Creates the project as a Firebase project.


```
Expand Down
55 changes: 40 additions & 15 deletions scripts/accounts/gcloud/create-project.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
#!/bin/bash

set -e
FLAGS=$(getopt -a --options n:d:f:o:b:h --long "help,firebase" -- "$@")

eval set -- "$FLAGS"

while true; do
case "$1" in
-h | --help ) help="true"; shift 1;;
-n ) projectName=$2; shift 2;;
-d ) description=$2; shift 2;;
-f ) folder=$2; shift 2;;
-o ) organization=$2; shift 2;;
-b ) billing=$2; shift 2;;
--firebase ) firebase="true"; shift 1;;
--) shift; break;;
esac
done


helpFunction()
{
echo "Creates a new project and enables billing and required APIs"
Expand All @@ -10,25 +29,15 @@ helpFunction()
echo -e "\t-d Description for the new project. If not specified, name will be used as description"
echo -e "\t-f Numeric ID of the folder for which the project will be configured."
echo -e "\t-o Numeric ID of the organization for which the project will be configured."
echo -e "\t--firebase Creates the project as a Firebase project."
}

while getopts "n:d:f:o:b:h" opt
do
case "$opt" in
n ) projectName="$OPTARG" ;;
d ) description="$OPTARG" ;;
f ) folder="$OPTARG" ;;
o ) organization="$OPTARG" ;;
b ) billing="$OPTARG" ;;
h ) helpFunction; exit ;;
? ) helpFunction ;; # Print helpFunction in case parameter is non-existent.
esac
done

white='\e[1;37m'
green='\e[1;32m'
red='\e[0;31m'

if [[ "$help" == "true" ]]; then helpFunction; exit; fi

# Mandatory argument check
if [ -z "$projectName" ] || [ -z "$billing" ];
then
Expand All @@ -44,17 +53,33 @@ if ! [ -x "$(command -v gcloud)" ]; then
echo -ne "${white}" >&2
exit 127
fi

# Check if Firebase CLI is installed
if [ "$firebase" == "true" ] && ! [ -x "$(command -v firebase)" ]; then
echo -e "${red}Error: Firebase CLI is not installed." >&2
echo -ne "${white}" >&2
exit 127
fi

# Check if exists a Google Cloud project with that project ID.
if gcloud projects describe "$projectName" &>/dev/null ; then
echo "Project ID already exists."
else
# Create the Google Cloud project.
echo -e "${green}Creating project..."
echo -ne "${white}"
command="gcloud projects create $projectName"
if [ "$firebase" == "true" ]; then
command="firebase projects:create $projectName --non-interactive"
else
command="gcloud projects create $projectName"
fi

if [ -n "$description" ]; then
command=$command" --name=\"$description\""
if [ "$firebase" == "true" ]; then
command=$command" --display-name=\"$description\""
else
command=$command" --name=\"$description\""
fi
fi
if [ -n "$folder" ]; then
command=$command" --folder=$folder"
Expand Down
39 changes: 26 additions & 13 deletions scripts/accounts/gcloud/setup-firebase.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ helpFunction() {
echo "Arguments:"
echo -e "\t-n [Required] Name of the project."
echo -e "\t-o, --output [Required] Output path to store credentials."
echo -e "\t-r Region where to create Firestore Database."
echo -e "\t-r [Required] Region where to create Firestore Database."
echo -e "\t--enable-maps Enables APIs related to Maps services."
echo -e "\t--setup-ios Enables IOS APIs and creates IOS App."
echo -e "\t--setup-android Enables Android APIs and creates Android App."
Expand All @@ -41,15 +41,23 @@ checkMandatoryArguments() {
# Project name check
if [ -z "$projectName" ];
then
echo -e "${red}Error: Missing paramenters, -n is mandatory." >&2
echo -e "${red}Error: Missing parameters, -n is mandatory." >&2
echo -e "${red}Use -h flag to display help." >&2
echo -ne "${white}" >&2
exit 2
fi
# Firestore region
if [ -z "$firestoreRegion" ];
then
echo -e "${red}Error: Missing parameters, -r is mandatory." >&2
echo -e "${red}Use -h flag to display help." >&2
echo -ne "${white}" >&2
exit 2
fi
# Output path check
if [ -z "$outputPath" ];
then
echo -e "${red}Error: Missing paramenters, -o is mandatory." >&2
echo -e "${red}Error: Missing parameters, -o is mandatory." >&2
echo -e "${red}Use -h flag to display help." >&2
echo -ne "${white}" >&2
exit 2
Expand Down Expand Up @@ -173,13 +181,10 @@ addFirebaseToGcloudProject() {

createFirestoreDB() {
echo "Creating Firestore Database..."
if [[ "$firestoreRegion" == "" ]]; then
firestoreRegion="europe-west6"
fi
if ! gcloud app create --region=$firestoreRegion &> /dev/null ; then
if ! gcloud app create --project=$projectName --region=$firestoreRegion &> /dev/null ; then
echo -e "App Engine already created"
fi
if ! gcloud firestore databases create --project $projectName --region=$firestoreRegion; then
if ! gcloud firestore databases create --project=$projectName --region=$firestoreRegion; then
echo -e "${red}Error: Cannot Create Firestore Database" >&2
echo -ne "${white}" >&2
exit 230
Expand All @@ -188,8 +193,8 @@ createFirestoreDB() {

createFirebaseSDKAccount() {
echo "Creating Firebase SDK Service Account..."
service_email=$(gcloud iam service-accounts list | grep firebase-adminsdk | tr -s ' ' | cut -d ' ' -f2)
if ! gcloud iam service-accounts keys create $outputPath"/firebase.json" --iam-account "$service_email" --project "$projectName"; then
service_email=$(gcloud iam service-accounts list --project=$projectName | grep firebase-adminsdk | tr -s ' ' | cut -d ' ' -f2)
if ! gcloud iam service-accounts keys create $outputPath"/firebase-key.json" --iam-account "$service_email" --project="$projectName"; then
echo -e "${red}Error: Cannot create Firebase Service Account" >&2
echo -ne "${white}" >&2
exit 240
Expand All @@ -212,7 +217,7 @@ setupAndroidKeystore() {
}

registerShaKeys() {
appId="${projectName}_android"
appId=$(firebase apps:list --project ${projectName} | grep ANDROID | awk '{print $4}')
sha1Key=$(echo -e "android\n" | keytool -list -v -alias upload -keystore $outputPath"/keystore.jks" 2> /dev/null | grep SHA1 -m 1 | cut -d' ' -f3)
sha256Key=$(echo -e "android\n" | keytool -list -v -alias upload -keystore $outputPath"/keystore.jks" 2> /dev/null | grep SHA256 -m 1 | cut -d' ' -f3)
if ! firebase apps:android:sha:create $appId $sha1Key --project ${projectName} ; then
Expand All @@ -233,7 +238,7 @@ createPlatformApps() {
# Remove '-' character
packageName="com.takeoff.${projectName//-/}"
# Remove '_' character
packageName="com.takeoff.${packageName//_/}"
packageName="${packageName//_/}"
# ANDROID setup:
if [[ "$setupAndroid" == "true" ]]
then
Expand Down Expand Up @@ -294,6 +299,12 @@ createPlatformApps() {
fi
}

nextSteps() {
echo "Next steps:"
echo "1. Accept consent screen: https://console.cloud.google.com/apis/credentials/consent?project=$projectName"
echo "2. If you want to execute quickstart frontend's script, go to https://console.cloud.google.com/google/maps-apis/api-list?project=$projectName, choose Maps Static API, then go to Credentials and copy the current secret because it will be required for next steps."
}

#==============================================================
# SCRIPT EXECUTION:

Expand All @@ -319,4 +330,6 @@ if [[ "$setupWeb" == "true" ]] || [[ "$setupIOS" == "true" ]] || [[ "$setupAndro
then
echo "Creating APPs"
createPlatformApps
fi
fi

nextSteps