DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Testcontainers: From Zero To Hero [Video]
  • Scaling Salesforce Apps Using Heroku Microservices - Part 2
  • 6 of the Best API Testing Tools in the Market
  • Automatic Versioning in Mobile Apps

Trending

  • Intro to RAG: Foundations of Retrieval Augmented Generation, Part 2
  • Using Java Stream Gatherers To Improve Stateful Operations
  • A Guide to Auto-Tagging and Lineage Tracking With OpenMetadata
  • Agile’s Quarter-Century Crisis
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Scaling Android Deployment With Bitbucket Pipelines and Fastlane

Scaling Android Deployment With Bitbucket Pipelines and Fastlane

Put your Android application in the Fastlane (see what we did there?) with automated scaling using Bitbucket pipelines.

By 
Ivan Rigovsky user avatar
Ivan Rigovsky
·
Updated Sep. 12, 19 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
20.3K Views

Join the DZone community and get the full member experience.

Join For Free

Image title

For all the ways your application can grow and go

Traveler.today makes local travel guides for tourists and self-explorers. We create a different app for each location because each of our apps is made for a different partner/customer.

As our business started to grow, we needed to create multiple new apps per week and it started to take too much time away from the whole team. It interrupted our development work as we would spend most of our time supporting releases. For each new app, it took several hours to configure the server, build and deploy a new application, update the database, fill metadata, etc.

You may also enjoy:  Automating AWS Lambda Deployments Using Bitbucket

The purpose of this post is to share our experience in automating deployment of dozens of Android applications based on the same codebase. This process resulted in reducing our deployment time per app from several hours to several minutes.

What We Did

We decided to automate the most time-consuming parts of the process:

  • Building and deploying servers
  • Refreshing the application database
  • Uploading application metadata (screens, description, changelog)
  • Building and deploying applications

Here’s how we did it using Bitbucket, Git, and Fastlane.

Git Tags and Our Server Deploy Process

We use the Git-flow methodology. We have several test and production environments for each customer. To reduce manual work, we decided to deploy applications using tags with versions. The below image shows you some sample branch names.

Here are some sample branch names

Then we configured a Bitbucket route for each tag version to its environment. For each tag, we build a server instance, copy it, send it to DigitalOcean and then notify our Slack channel about success or failure.

For the test instance, we have a continuous integration process with fast deploy and start. For production, we build and manually deploy. We provide a commit ID, version, and application name into the build script to understand what version was deployed. We use the variables BITBUCKET_TAG   and BITBUCKET_COMMIT to understand which version was deployed for each instance.

Here is some detail on the process.

First, define access variables on the account variable page:

The Bitbucket account variable page

Next, build the CI process using Bitbucket Pipelines. Here is our Pipelines code in the test environment.


pipelines:
  tags:
test-*:
 - step:
     name: Build and deploy
     caches:
       - maven
     script:
       - mvn clean install -DskipTests=true -Ptest -Dapp.name=test -Dapp.version=$BITBUCKET_TAG -Dapp.commit=$BITBUCKET_COMMIT
       - scp -v -P $SSH_PORT city-webapp/target/test.war $SSH_LOGIN@$SSH_IP:$DEPLOY_FOLDER
       - scp -v -P $SSH_PORT deploy/deploy_test.sh $SSH_LOGIN@$SSH_IP:$DEPLOY_FOLDER
              - ssh -p $SSH_PORT $SSH_LOGIN@$SSH_IP 'sh $DEPLOY_FOLDER/deploy_test.sh'


Finally, for notifications, we use Slack and Bitbucket WebHooks on our #devops channel. Here’s how you do it. Go to your repo settings page and click on webhooks.

Webhooks push Bitbucket even further

Add a new webhook for each "Push" and "Build status updated" events.

Bitcuket_notifications_page
Alerts you want, none you don't

Here is how notifications look.

Bitbucket_notifications
Green, green everywhere

With this new process, building and deploying microservices for each application only takes a few minutes, including caching and copying files.

Microservices hard at work

Using Fastlane to Build and Deploy Mobile Apps

You can read about how to set up Fastlane in this blog.

In this section, I will describe our build and deploy process. We need to build and deploy several apps for the same code base, but with a different database and metadata like images, descriptions, titles, and changelogs.

Here’s the command to build the app name with the current profile.

fastlane build app:test


Then we start the process of updating the database, building and deploying the application. Step by step.

platform :android do
  desc "Build apps: 'sudo fastlane build app:altay' for instance"
  lane :build do |options|
    update_data(app: options[:app])    #1. update database
    build_android(app: options[:app])  #2. build from src
   deploy(app: options[:app])              #3. deploy app
end


Step 1: Update Database

We would often forget to update the database or to synchronize API versions. Now, we just run this script to get access to the API:

sudo fastlane update_data app:altay


We have an external API on the server with fresh data in JSON format. Because all new users must have offline access to the data (travelers often don’t have internet), we will provide it for each new release. Then save the downloaded file to the mobile app directory before the build starts. The build script in the next step will fetch this data from the file and save it into the database.

desc "Update database"
lane :update_data do |options|
    objects = download(url: $API_URL + options[:app])
    objectFile = "../mobile/src/" + options[:app] + "/assets/json/database.json"
    File.open(objectFile, 'w') { |file| file.write(database.to_json) }
end


Step 2: Build

To start build, provide key variables into the script:  $PATH_TO_KEY ,  $STORE_PASSWORD,  $KEY_ALIAS ,  $KEY_PASSWORD.

platform :android do
  desc "Build android app from src”
  lane :build_android do |options|
    gradle(
      task: "assemble",
      flavor: options[:app],
      build_type: "Release",
      print_command: false,
      properties: {
        "android.injected.signing.store.file" => $PATH_TO_KEY,
        "android.injected.signing.store.password" => $STORE_PASSWORD,
        "android.injected.signing.key.alias" => $KEY_ALIAS,
        "android.injected.signing.key.password" => $KEY_PASSWORD,
      }
  )
  end


In the result, we have new APK file, and now we are ready to deploy.

Step 3: Deploy

Manually deploying an application in the App Store and Google Play is a challenge when we want to optimize screenshots, video, or keywords. To deploy the APK, set up the folder with metadata from the source and start the supply Fastlane task. You can also put all these variables into Bitbucket.

desc "Deploy a new version to the Google Play.
  lane :deploy do |options|
    supply(
      track: options[:track],
      package_name: "today.traveler." + options[:app],
      metadata_path: "$APP_PATH/fastlane/" + options[:app] + "_metadata",
      apk: "mobile/build/outputs/apk/" + options[:app] + "/release/guide-" + options[:app] + ".apk"
    )
  end


The next step for us is to add CI for iOS applications and build a separate server architecture for more micro-services to improve deployment flexibility.

Conclusion

Now the entire application and server deploy process only takes half an hour with all tests and checks. Before automation, it had taken about 1 hour for each app or each server deploy. For 10 apps we’ve saved an entire day in time. For 50 apps, we save an entire week!

Here’s how our new process helped us:

  • No more manually uploading data, database updates and deploys.
  • No more human errors in the workflow.
  • Reduced onboarding time for new team members.
  • And now we always know the version of the product and when it was delivered without a lot of documentation.

We can add any number of new applications to our deployment process and it won’t decrease our speed. That means that we can allocate resources to improve our core product.

As your startup grows, it’s important to think about scaling your development process. I hope this post helped you think about your processes and gave you ideas on you can scale.

mobile app Continuous Integration/Deployment Android (robot) Pipeline (software) Database Scaling (geometry)

Published at DZone with permission of Ivan Rigovsky. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Testcontainers: From Zero To Hero [Video]
  • Scaling Salesforce Apps Using Heroku Microservices - Part 2
  • 6 of the Best API Testing Tools in the Market
  • Automatic Versioning in Mobile Apps

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!