Skip to content

Commit

Permalink
New Firebase Emulator
Browse files Browse the repository at this point in the history
  • Loading branch information
goat-io committed Apr 9, 2024
1 parent a26a48e commit eb85736
Show file tree
Hide file tree
Showing 13 changed files with 1,180 additions and 266 deletions.
7 changes: 4 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"makefile.extensionOutputFolder": "./.vscode",
"typescript.tsdk": "node_modules/typescript/lib"
}
"makefile.extensionOutputFolder": "./.vscode",
"typescript.tsdk": "node_modules/typescript/lib",
"CodeGPT.apiKey": "CodeGPT Plus Beta"
}
78 changes: 37 additions & 41 deletions packages/dev/Database/Firebase/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,56 +1,52 @@
FROM python:3.7-slim-buster
################################################################################
# Original Source
# https://github.com/eHealthAfrica/firebase-emulator/blob/master/Dockerfile
# https://github.com/firebase/emulators-codelab/tree/master/codelab-final-state/functions
################################################################################

# The Firebase install scripts use sudo so we need to add it.
RUN apt update && apt install -y sudo

RUN adduser --disabled-password --gecos '' docker
RUN adduser docker sudo
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
USER docker
FROM python:3.8-slim-buster

# Update and install required packages
RUN apt-get update && \
apt-get install -y --no-install-recommends sudo curl git openjdk-11-jre-headless && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Add a non-root user
RUN useradd -m -s /bin/bash docker

RUN sudo apt update && sudo apt install -y curl git xz-utils curl
RUN sudo mkdir /app
RUN sudo chown -R docker:docker /app
# Fix issue with JRE installation
RUN sudo mkdir -p /usr/share/man/man1
RUN sudo apt install -y openjdk-11-jre-headless
# Add the user to the sudo group without password prompt
RUN echo "docker ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/nopasswd

USER docker

# Install NodeJS
RUN sudo apt-get install -y gcc g++ make node-gyp
RUN curl -sL https://deb.nodesource.com/setup_20.x 565 | sudo -E bash -
RUN sudo apt-get install -y nodejs
# Install base tools
RUN curl -sL https://deb.nodesource.com/setup_20.x | sudo -E bash - && \
sudo apt-get install -y nodejs

# Install Firebase tools
RUN sudo npm install -g firebase-tools

# Install gcloud commmand utilities to use default login
RUN curl -sSL https://sdk.cloud.google.com > /tmp/gcl && bash /tmp/gcl --install-dir=/root/gcloud --disable-prompts
# Install gcloud command utilities
RUN curl -sSL https://sdk.cloud.google.com > /tmp/gcl && \
bash /tmp/gcl --install-dir=/home/docker/google-cloud-sdk --disable-prompts

# Set Python version for Google Cloud SDK
ENV CLOUDSDK_PYTHON=python3

ENV PATH $PATH:~/gcloud/google-cloud-sdk/bin
ENV PATH $PATH:/home/docker/google-cloud-sdk/bin

WORKDIR /app
COPY ./firebase.json /app/firebase.json
COPY ./.firebaserc /app/.firebaserc

# Copy Firebase configuration files
COPY firebase.json .firebaserc startfirebase.json firestore.indexes.json firestore.rules database.rules.json storage.rules /app/

# First run will download the current .jar files for firebase
RUN firebase emulators:exec --project test ls >> /dev/null

# Only install packages if package.json has changed
RUN mkdir /app/functions
COPY ./functions/package.json /app/functions/package.json
RUN cd /app/functions && sudo npm install
# Install npm packages for functions
COPY functions/package.json /app/functions/
RUN cd functions && sudo npm install

COPY ./startfirebase.json /app/firebase.json
COPY ./firestore.indexes.json /app/firestore.indexes.json
COPY ./firestore.rules /app/firestore.rules
COPY ./firestore.rules /app/database.rules.json
COPY ./storage.rules /app/storage.rules
COPY ./functions /app/functions
COPY ./public /app/public
# Copy remaining files
COPY functions /app/functions
COPY public /app/public

EXPOSE 4000 8080 8085 4400 4500 9000 5001 9099

CMD firebase emulators:start --only auth,functions,firestore,pubsub,storage,hosting,database --project ${FIRESTORE_PROJECT_NAME:-test}
# Set default command to start Firebase emulators
CMD ["firebase", "emulators:start", "--only", "auth,functions,firestore,pubsub,storage,hosting,database,hub,logging", "--project", "demo-local-test-emulator"]
21 changes: 21 additions & 0 deletions packages/dev/Database/Firebase/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
build: SHELL:=/bin/bash

define GetFromPkg
$(shell node -p "require('./package.json').$(1)")
endef
CURRENT_VERSION:= $(call GetFromPkg,version)
BRANCH:="$(shell git rev-parse --abbrev-ref HEAD)"
NOW := $(shell date '+%Y%m%d')

publish:
@if [ ${BRANCH} != "master" ]; then\
echo "Not in branch master, nothing to do" && exit 0;\
else\
git pull origin master;\
echo "version ${CURRENT_VERSION}";\
docker-compose build firestore;\
docker tag goatlab/firebase-emulator goatlab/firebase-emulator:latest;\
docker tag goatlab/firebase-emulator goatlab/firebase-emulator:${CURRENT_VERSION};\
docker push goatlab/firebase-emulator:latest;\
docker push goatlab/firebase-emulator:${CURRENT_VERSION};\
fi
1 change: 1 addition & 0 deletions packages/dev/Database/Firebase/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ services:
# FireStore
#######################################################
firestore:
image: goatlab/firebase-emulator
build:
context: .
dockerfile: ./Dockerfile
Expand Down
37 changes: 23 additions & 14 deletions packages/dev/Database/Firebase/firebase.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
{
"emulators": {
"firestore": {
"port": 8080,
"host": "0.0.0.0"
"auth": {
"port": 9099
},
"database": {
"port": 9000,
"host": "0.0.0.0"
},
"ui": {
"enabled": true,
"host": "0.0.0.0",
"port": 4000
"port": 9000
},
"pubsub": {
"port": "8085",
"host": "0.0.0.0"
"firestore": {
"host": "0.0.0.0",
"port": 8080
},
"functions": {
"port": 5001
},
"auth": {
"port": 9099
"hub": {
"host": "0.0.0.0",
"port": 4400
},
"logging": {
"host": "0.0.0.0",
"port": 4500
},
"pubsub": {
"host": "0.0.0.0",
"port": "8085"
},
"singleProjectMode": false,
"ui": {
"enabled": true,
"host": "0.0.0.0",
"port": 4000
}
}
}
42 changes: 21 additions & 21 deletions packages/dev/Database/Firebase/functions/package.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
{
"name": "functions",
"dependencies": {
"file-system": "^2.2.2",
"firebase-admin": "^12.0.0",
"firebase-functions": "^4.8.2"
},
"description": "Cloud Functions for Firebase",
"devDependencies": {
"@firebase/rules-unit-testing": "^3.0.2",
"eslint": "^8.57.0",
"eslint-plugin-promise": "^6.1.1",
"firebase": "^10.10.0",
"firebase-functions-test": "^3.1.1",
"mocha": "^10.4.0"
},
"engines": {
"node": "20"
},
"name": "functions",
"private": true,
"scripts": {
"deploy": "firebase deploy --only functions",
"lint": "eslint .",
"logs": "firebase functions:log",
"serve": "firebase emulators:start",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log",
"test": "mocha --timeout 5000 --exit"
},
"engines": {
"node": "16"
},
"dependencies": {
"file-system": "^2.2.2",
"firebase-admin": "^9.5.0",
"firebase-functions": "^3.13.2"
},
"devDependencies": {
"@firebase/rules-unit-testing": "^1.2.3",
"eslint": "^5.12.0",
"eslint-plugin-promise": "^4.0.1",
"firebase": "^8.2.10",
"firebase-functions-test": "^0.2.3",
"mocha": "^6.1.4"
},
"private": true
}
}
4 changes: 4 additions & 0 deletions packages/dev/Database/Firebase/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "goatlab/firebase-emulator",
"version": "1.2"
}
99 changes: 99 additions & 0 deletions packages/dev/github/ci-runner/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
FROM myoung34/github-runner:latest

USER root

# NODE JS
RUN curl -sL https://deb.nodesource.com/setup_14.x -o nodesource_setup.sh \
&& bash nodesource_setup.sh \
&& apt-get install -y -q nodejs

RUN npm install -g yarn netlify-cli

# PYTHON
RUN apt-get update \
&& apt-get install -y -q libffi-dev python3-dev python3-pip python3-setuptools

RUN apt install curl g++ gcc autoconf automake bison libc6-dev \
libffi-dev libgdbm-dev libncurses5-dev libsqlite3-dev libtool \
libyaml-dev make pkg-config sqlite3 zlib1g-dev libgmp-dev \
libreadline-dev libssl-dev jq -y

# RUBY
RUN wget http://ftp.ruby-lang.org/pub/ruby/2.6/ruby-2.6.3.tar.gz
RUN tar -xzvf ruby-2.6.3.tar.gz

RUN cd ruby-2.6.3 && ./configure && make && make install

RUN gem install bundler:1.17.2 && gem install fastlane && gem install cocoapods

#JAVA installation

RUN wget -qO - "https://adoptopenjdk.jfrog.io/adoptopenjdk/api/gpg/key/public" | apt-key add -
RUN add-apt-repository --yes https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/
RUN apt-get update
RUN apt-get -y install adoptopenjdk-8-hotspot=\*
ENV JAVA_HOME=/usr/lib/jvm/adoptopenjdk-8-hotspot-amd64
ENV JAVA_HOME_8_X64=/usr/lib/jvm/adoptopenjdk-8-hotspot-amd64
RUN update-java-alternatives -s /usr/lib/jvm/adoptopenjdk-8-hotspot-amd64

# INSTALL ANT
RUN apt-get install -y --no-install-recommends ant ant-optional
ENV ANT_HOME=/usr/share/ant

# INSTALL MAVEN
RUN curl -sL https://www-eu.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.zip -o maven.zip
RUN unzip -d /usr/share maven.zip
RUN rm maven.zip
RUN ln -s /usr/share/apache-maven-3.6.3/bin/mvn /usr/bin/mvn
ENV ANT_HOME=/usr/share/apache-maven-3.6.3
# INSTALL GRADLE

RUN curl -sL https://services.gradle.org/distributions/gradle-6.2-all.zip -o gradleLatest.zip
RUN unzip -d /usr/share gradleLatest.zip
RUN rm gradleLatest.zip
RUN ln -s /usr/share/gradle-6.2-all/bin/gradle /usr/bin/gradle
ENV GRADLE_HOME=/usr/share/gradle
# Android Installation
RUN apt update && sudo apt install android-sdk -y
ENV ANDROID_HOME=/usr/lib/android-sdk

RUN wget -O android-sdk.zip https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip
RUN mkdir /usr/local/lib/android && mkdir /usr/local/lib/android/sdk
RUN unzip android-sdk.zip -d /usr/local/lib/android/sdk
RUN rm -f android-sdk.zip
ENV ANDROID_HOME=/usr/local/lib/android/sdk

RUN sed -i "2i export JAVA_HOME=${JAVA_HOME_8_X64}" /usr/local/lib/android/sdk/tools/bin/sdkmanager
RUN /usr/local/lib/android/sdk/tools/bin/sdkmanager --list
RUN chmod -R a+rwx /usr/local/lib/android/sdk
ENV ANDROID_SDK_ROOT=/usr/local/lib/android/sdk
ENV ANDROID_HOME=/usr/local/lib/android/sdk
# Install NDK
RUN mkdir /usr/local/lib/android/ndk-bundle
RUN echo "y" | sudo /usr/local/lib/android/sdk/tools/bin/sdkmanager --install "ndk;21.0.6113669" --sdk_root=/usr/local/lib/android/sdk

RUN wget https://dl.google.com/android/repository/platform-tools-latest-linux.zip
RUN unzip \platform-tools-latest-linux.zip
RUN cp platform-tools/adb /usr/bin/adb
RUN cp platform-tools/fastboot /usr/bin/fastboot
RUN adb --version

RUN apt-get clean \
&& rm -rf /var/lib/apt/lists/*

ENV PATH="$PATH:$ANDROID_HOME/emulator"
ENV PATH="$PATH:$ANDROID_HOME/tools"
ENV PATH="$PATH:$ANDROID_HOME/tools/bin"
ENV PATH="$PATH:$ANDROID_HOME/platform-tools"

FROM debian:stretch-slim as itms_transporter

RUN apt-get update \
&& apt-get install --yes \
p7zip-full \
curl \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& curl https://itunesconnect.apple.com/transporter/1.9.8/iTMSTransporterToolInstaller_1.9.8.exe > installer.exe \
&& 7z x installer.exe -oitms \
&& chmod +x itms/bin/iTMSTransporter
Loading

0 comments on commit eb85736

Please sign in to comment.