Running your own CodePush server

Peter Wong
3 min readMar 23, 2022

--

CodePush being retired for Cordova was a huge problem for us as there weren’t other alternatives that were budget-friendly. Thankfully, there are solutions for running your own (fully legal) CodePush server.

While these seem to mainly be used in China, GitHub user byronigoe has done some work to translate and test out these solutions. Building upon his work, I’ve documented my own process in setting up a CodePush server specifically for Cordova, on Amazon AWS.

Step 1: Set up EC2

This is a good tutorial to get an EC2 instance up and running. You can follow it up till you get Express running — while not necessary, it is a good and quick test to make sure you can access the EC2 public URL (e.g. http://ec2–12–255–34–56.ap-southeast-1.compute.amazonaws.com:3000)

Install PM2 and MySQL, redis:

sudo apt update
sudo apt-get install mysql-server -y
sudo npm i -g pm2
sudo apt install redis-server

Configure redis by following Step 3 of this article.

You will also want to change the MySQL root password:

sudo mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'newpassword';

Step 2: Configure PM2

You can use either https://github.com/shm-open/code-push-server or https://github.com/byronigoe/code-push-server here — they should be the same as byronigoe has committed to maintaining the latter as an English translation of the former.

He also maintains some installation notes, which my following instructions is adapted from.

config.js

Save config.js and edit the following:

  • db.password— to the MySQL password you set earlier.
  • db.database— to 'codepush'
  • local.storageDir — to a folder of your choice, e.g. /home/ubuntu/code-push-binaries. Be sure to mkdir the folder.
  • local.downloadUrl — to your EC2 public URL with /download appended, e.g. http://ec2-12-255-34-56.ap-southeast-1.compute.amazonaws.com:3000/download Note the port 3000 and /download folder, these are important.
  • Change the jwt.tokenSecret by following the instructions in the line above

process.json

Save process.json and edit CONFIG_FILE to reference the above config.js path.

Step 3: Prepare MySQL

sudo npm install byronigoe/code-push-server -gcode-push-server-db init --dbpassword "your new mysql password"

It should return Success and create the MySQL database. You can verify it:

mysql -u root -p 
// Enter your password
SHOW DATABASES;
USE codepush;
SHOW TABLES;

You will probably want to rename the admin user. Continuing in the MySQL terminal:

UPDATE users SET email=your@email.com WHERE id=1;
quit;

Step 4: Start the server

pm2 start process.json

This should start PM2, and you should be able to access your EC2 public URL at port 3000:

curl -I http://ec2-12-255-34-56.ap-southeast-1.compute.amazonaws.com:3000

It should return a 200 OK HTTP status. You can also visit the URL in your browser, where you can log in with admin/123456

Upon doing so, you will get a token, which you can use to change the password. Replace mytoken below with this token, and 654321 with your desired password:

curl -X PATCH -H "Authorization: Bearer mytoken" -H "Accept: application/json" -H "Content-Type:application/json" -d '{"oldPassword":"123456","newPassword":"654321"}' http://127.0.0.1:3000/users/password

Step 5: Code Push CLI

npm install code-push-cli@2.1.9 -g

This is where my experience differed from the instructions. Newer code-push-cli versions would return a Not found error in the following step, so I had to fix to 2.1.9:

code-push login http://ec2-12-255-34-56.ap-southeast-1.compute.amazonaws.com:3000

This will open the browser window, where you can get the token again and paste it into the CLI. It should tell you that you are now authenticated.

Congratulations! You can now use code-push as normal:

code-push app add my-app-ios ios cordova
code-push app add my-app-android android cordova

To view the deployments:

code-push deployment list --displayKeys

To release:

code-push release-cordova my-app-ios ios --deploymentName Staging --description "Hooray" --targetBinaryVersion "1.0.0 - 1.0.1"

Congrats!

You’re now running your own CodePush server! This has worked well for me so far in testing and I will be using this in a production app soon. Do let me know if you encounter any issues or experience anything differently from what I’ve written.

Unlisted

--

--