Uploading Android APKs to Firebase App Distribution from a Node.js Application — Part 2

Jorge Luis Castro Medina
4 min readApr 29, 2024

Welcome back! 👋🏻 In this installment of the series on uploading APKs with Firebase CLI from Node.js, we’ll enhance our example project with some automation. But first, if you missed the initial part, catch up here:

Before continuing, make sure you have Docker installed on your machine. If you don’t have it yet, I will show you how to do it here

Backend Side

From the server side, we will add the following Docker files to the root directory of the project: Dockerfile, compose.yaml, and .dockerignore.

  • Dockerfile: A file with instructions to build a Docker container image.
  • compose.yaml: A file describing the Docker services configuration for a multi-container application.
  • .dockerignore: A file to specify which files and directories Docker should ignore when building a container image.

Dockerfile

FROM ubuntu:latest

# Set working directory (optional, adjust as needed)
WORKDIR /app

# Update package lists
RUN apt-get update

RUN apt-get install -y curl
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash
RUN apt-get install -y nodejs


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

# Copy the files to the Docker image
COPY package*.json ./
RUN npm install

COPY . .


RUN mkdir -p temp

EXPOSE 3000
CMD ["node", "app.js"]

Briefly, this Dockerfile builds a Docker image based on Ubuntu. It installs Node.js and Firebase CLI, copies project files, creates a temporary directory, and exposes port 3000 to run a Node.js application named app.js.

compose.yaml

version: '3.8'

services:
app:
build:
context: .
ports:
- "3000:3000"
volumes:
- /Users/my-user/shared-data/keys/:/app/keys

environment:
- NODE_ENV=production
- GOOGLE_APPLICATION_CREDENTIALS=${GOOGLE_APPLICATION_CREDENTIALS}
- APP_ID=${APP_ID}
  • Services: Defines a service named app
  • Build: Uses the current context to build the container image, assuming that the necessary files for the application are located there.
  • Ports: Maps port 3000 of the container to port 3000 of the host, allowing the application to be accessible from the outside.
  • Volumes: Mounts the /app/keys/ folder from the host into the container to share the file.json file, which contains the necessary Google service account credentials for the application.
  • Environment: Sets environment variables for the container, such as the path to the file.json file and the application ID. These values come from the .env file, where specific paths and configurations for the application are specified.

.env

GOOGLE_APPLICATION_CREDENTIALS=/app/keys/file.json
APP_ID=1:123456789300:android:12345abcdefghijk12abc9

.dockerignore

node_modules
npm-debug.log
Dockerfile
compose.yaml
.dockerignore
.env

Our root directory should look similar to the following

It’s time to bring up our container to expose the endpoint with which we can send our APK to be uploaded to App Distribution. For that, we will use Docker Compose.

docker compose up

Android Side

Now we will create a bash script inside the root directory of our Android project, which will be responsible for building it for us and uploading it. Additionally, we will be able to add parameters such as the group and the release notes.

upload_to_firebase.sh

#!/bin/bash

group=""
release_notes=""

# Process command line options
while getopts ":g:n" opt; do
case ${opt} in
g )
group="$OPTARG"
;;
n )
release_notes="$OPTARG"
;;
\? )
echo "Invalid option: -$OPTARG" 1>&2
;;
: )
echo "Option -$OPTARG requires an argument." 1>&2
display_help
;;
esac
done
shift $((OPTIND -1))

# Check if the required argument is provided

if [ -z "$group" ]; then
echo "Missing required argument."
echo "Usage: $0 -g <group>"
exit 1
fi


echo -e "Building..."
./gradlew assembleDebug

echo -e "\n\nUploading version..."

curl -X POST \
-F "file=@app/build/outputs/apk/debug/app-debug.apk" \
-F "group=$group" \
-F "releaseNotes=$release_notes" \
https://your-domain:3000/upload

We give execution permission to our script.

chmod +x nombre_del_script.sh

Finally, we execute our script.

 ./upload_to_firebase.sh -g "qa-testers" -n "Version uploaded from Firebase CLI"

If you like my content and want to support my work, you can give me a cup of coffee ☕️ 🥰

Follow me in

--

--

Jorge Luis Castro Medina

I'm a Software Engineer passionate about mobile technologies, and I like everything related to software design and architecture