IllusionVK / ReplaceAppCenter

A place to discuss alternatives for CodePush and maybe also the distribution of apps.
30 stars 0 forks source link

Solved! #3

Open byronigoe opened 2 years ago

byronigoe commented 2 years ago

Great news! I've got an alternative working!

Cordova Plugin

The official cordova-plugin-code-push supports pointing to a different server: <preference name="CodePushServerUrl" value="http://your-server.com/" /> Just in case I will need to fix bugs, I will maintain my own fork: https://github.com/byronigoe/cordova-plugin-code-push

CodePush Server

@shm-open created https://github.com/shm-open/code-push-server With the help of Google Translate and the documentation for Pug and Redis, I was able to get it working. I will continue to maintain this English version, and submit PRs to upstream when possible: https://github.com/byronigoe/code-push-server

CodePush CLI

I have not needed to modify the CLI yet, but in order to guarantee interoperability with future backend changes, I'm using my fork: https://github.com/byronigoe/code-push-cli

josiahbryan commented 2 years ago

AWESOME!!!! Thank you SO MUCH for doing this - I will try it out right now. My company was about to launch two Apps that depend on CodePush - and we were crushed to find it going way. Hope this works!! Will help however I can!

raphjutras commented 2 years ago

Wow, good job @byronigoe . A lot of commit to fix things and translate..! I will be following your fork closely!

IllusionVK commented 2 years ago

Hey @byronigoe thanks for posting this and spending the time to share with us all.. its great news and what I was hoping for... i'm not a developer myself and all of my team have been heavily tied up on Covid-19 responses, so we haven't been able to spend the time like you have so far... but its great news and just what I thought/hoped might be possible. I think the most work for the future will actually be on making sure that the clients for iOS and Android are kept up to date, as they will be the most likely to break in the future I think.

Legally I think everything is MIT, so I think we are all good there to be able to keep using everything.

hey and @josiahbryan have you been able to setup your own server and try things out ? I'm very keen to document things well to help other people easily adopt things, so it would be good to hear your experience. And @byronigoe will you be open for PRs to your forks if I were to submit some changes to readme files, wikis etc ? I'm also wondering if others like @dylanvdmerwe have seen this post ?

byronigoe commented 2 years ago

Yes, I welcome PRs. I'm still setting up my production deployment, and have continued improving the documentation as I go.

raphjutras commented 2 years ago

@byronigoe I've tried installing it, it's running and listening on port 3000 (fine). Although, I haven't found any way to access a dashboard/admin panel. I've tried login-in with "admin / 123456", it works fine but it only leads me to a page to generate a Token. Token gets generated and I can copy it and then it says that we must use it in the command window?

Is the administration CLI-only or there is a web dashboard to manage the app and releases? (can't find how to access it)

Thanks

byronigoe commented 2 years ago

For now it's CLI-only, but the web services are simple enough that you could make web pages if you prefer. However, the services are RESTful, and the authentication token needs to be included in the header of all requests. Therefore, for administration web pages it might be better to either create a Single-Page Application (e.g. Angular or React), or to use cookies.

raphjutras commented 2 years ago

Okay, thanks for the answer @byronigoe ! I'm currently playing with the CLI, not very user-friendly but it works..!

I thought there was an admin UI like Appcenter.. maybe it was a dream 😅

raphjutras commented 2 years ago

I was looking for a UI, this might be worth checking: https://adtmag.com/articles/2016/11/01/react-native-ota.aspx electrode_ota 1

https://github.com/electrode-io/electrode-ota-server

gwhenne commented 2 years ago

@byronigoe , I'm experimenting with integrating this with VoltBuilder. It would help if there was a npm entry for cordova-plugin-code-push. Is that on your list, or can we help with a PR?

byronigoe commented 2 years ago

@gwhenne Thus far I have not needed to modify the Cordova plugin, so for now you can use the existing NPM listing: https://www.npmjs.com/package/cordova-plugin-code-push

VaibhavFuke commented 2 years ago

I am also trying this out. Can you please make a video of setting this whole up. If data is being exposed via. cli. I could help build the UI panel just like appcenter using angular

byronigoe commented 2 years ago

@VaibhavFuke I have improved the documentation in my forks, and that should be sufficient.

shadowfish07 commented 2 years ago

Hi guys,have you managed to deploy the code push server and implement hot updates ? I have deployed the code push server, but it doesn't work on my android device, it says An error has occurred while installing the package.

byronigoe commented 2 years ago

Yes, I have it working. Use Chrome debugging to see what URL it is using, and any further console messages.

vesper8 commented 2 years ago

Would be awesome if someone who's managed to get a self-hosted Codepush server fully up and running would write a tutorial on how to do it from scratch and post it on Medium or anywhere.

Serg-Mois commented 2 years ago

Getting - [CodePush] Could not get binary hash.Error: Could not get binary hash. while calling sync() method , after CHECKING_FOR_UPDATE and before UP_TO_DATE events.

IllusionVK commented 2 years ago

Would be awesome if someone who's managed to get a self-hosted Codepush server fully up and running would write a tutorial on how to do it from scratch and post it on Medium or anywhere.

Hey @vesper8 that was actually the exact reason for this repo... I have been a bit tied up with covid but I need to spend some time to write up all of the pieces of how people can now self host, which of course will point to some of the excellent work that @byronigoe has done... and then yes, a full readme/tutorial written for people non-familiar with all of the components needs to be part of it as well. Of course PRs will be welcome. I havn't run @byronigoe's work yet but hope to in the next few weeks. If anyone gets it setup and working before then and can start the readme then we can share with the wider community

Serg-Mois commented 2 years ago

@byronigoe how do you use cli?

npm i -g https://github.com/byronigoe/code-push-cli After install i don't see cli.js , so can't use code-push commands.

image

But npm install -g @shm-open/code-push-cli - installed correctly.

Serg-Mois commented 2 years ago

By the way, after switching to @shm-open/code-push-cli On android: The system sees the update but fails during download.

 [CodePush] Could not get binary hash.Error: Could not get binary hash. 
(anonymous) @ 
 [CodePush] Checking for update.
 [CodePush] Reported status: {"status":0,"appVersion":"feat-live-pipeline","deploymentKey":"FFhcMmkzWcPICeU9nr2rSXFx0QKy4ksvOXqog"}
 [CodePush] An update is available. {"isDownloading":false,"appVersion":"feat-live-pipeline","deploymentKey":"FFhcMmkzWcPICeU9nr2rSXFx0QKy4ksvOXqog","description":"","downloadUrl":"myurl.../download/lq/lqRDQtNZ2YW7mJyQLwxl4E2RXwOK","isMandatory":true,"label":"v8","packageHash":"608fcbc7fe00be2836ca03b78e9e20662b3922123158869d96203adc84337efc","packageSize":14600658,"failedInstall":false}
 [CodePush] Downloading update
 [CodePush]  Could not access local package. Stage:undefinedError code: undefined. StackTrace: Error: Could not access local package. Stage:undefinedError code: undefined
    at n (http://localhost:8020/plugins/cordova-plugin-code-push/bin/www/remotePackage.js:1:906)
    at http://localhost:8020/plugins/cordova-plugin-advanced-http/www/helpers.js:1:3633
    at Object.callbackFromNative (http://localhost:8020/cordova.js:1:3511)
    at <anonymous>:1:9
(anonymous) @ 
 [CodePush] An error occurred during sync. Could not access local package. Stage:undefinedError code: undefined. StackTrace: Error: Could not access local package. Stage:undefinedError code: undefined
    at n (http://localhost:8020/plugins/cordova-plugin-code-push/bin/www/remotePackage.js:1:906)
    at http://localhost:8020/plugins/cordova-plugin-advanced-http/www/helpers.js:1:3633
    at Object.callbackFromNative (http://localhost:8020/cordova.js:1:3511)
    at <anonymous>:1:9
(anonymous) @ 
 [CodePush] undefined:[object Object]

on iPhone - it downloads and installs the update, but fails on app reload, and finally rollbacks

 [Log] [CodePush] Checking for update. 
[Log] [CodePush] An update is available. {"isDownloading":false,"appVersion":"feat-live-pipeline","deploymentKey":"udNBbaWCysGlbYUiXfdm8tkfZyya4ksvOXqog","description":"","downloadUrl":"https://my.url/download/lm/lm1d0X68KX3H5NP1ar2S4mXtM03X","isMandatory":true,"label":"v8","packageHash":"dfbe92a4845c95939e34a9b36c5540eb2fa6f741216a9e121d793063c3323322","packageSize":14615872,"failedInstall":false} 
[Log] [CodePush] Downloading update 
[Log] [CodePush] Package download success: {"deploymentKey":"udNBbaWCysGlbYUiXfdm8tkfZyya4ksvOXqog","description":"","label":"v8","appVersion":"feat-live-pipeline","isMandatory":true,"packageHash":"dfbe92a4845c95939e34a9b36c5540eb2fa6f741216a9e121d793063c3323322","isFirstRun":false,"failedInstall":false,"localPath":"cdvfile://localhost/library-nosync/codepush/download/update.zip"} 
[Log] [CodePush] Installing update 
[Log] [CodePush] Applying full update 
[Log] [CodePush] Install succeeded. 

After reload white screen and the error: ReferenceError: Can't find variable: cordova

After one more reload.

[Log] [CodePush] Checking for update. 
[Log] [CodePush] Reported status: {"status":2,"label":"v8","appVersion":"feat-live-pipeline","deploymentKey":"udNBbaWCysGlbYUiXfdm8tkfZyya4ksvOXqog","previousLabelOrAppVersion":"feat-live-pipeline","previousDeploymentKey":"udNBbaWCysGlbYUiXfdm8tkfZyya4ksvOXqog"} 
[Log] [CodePush] An update is available. {"isDownloading":false,"appVersion":"feat-live-pipeline","deploymentKey":"udNBbaWCysGlbYUiXfdm8tkfZyya4ksvOXqog","description":"","downloadUrl":"https://my-url/download/lm/lm1d0X68KX3H5NP1ar2S4mXtM03X","isMandatory":true,"label":"v8","packageHash":"dfbe92a4845c95939e34a9b36c5540eb2fa6f741216a9e121d793063c3323322","packageSize":14615872,"failedInstall":true} 
[Log] [CodePush] An update is available, but it is being ignored due to have been previously rolled back. 
taufpate commented 2 years ago

@Serg-Mois i'm having same problem in Android, did you find any solution?   😔

Serg-Mois commented 2 years ago

@Serg-Mois i'm having same problem in Android, did you find any solution?   😔

no, I stopped the investigation, since all these solutions are an unstable mix of crutches and duct tapes/

byronigoe commented 2 years ago

I have everything fully working in production. I never encountered that error (@Serg-Mois @taufpate), but I can tell you my config.

byronigoe commented 2 years ago
<?xml version='1.0' encoding='utf-8'?>
<widget id="..." version="..." android-versionCode="..." xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
  <name short="...">...</name>
  <description>
      ...
  </description>
  <author email="..." href="...">
      ...
  </author>
  <content src="index.html" />
  <access origin="*" />
  <allow-navigation href="*" />
  <icon src="icon.png" />

  <preference name="scheme" value="..." />
  <preference name="hostname" value="localhost" />
  <preference name="DisallowOverscroll" value="true" />
  <preference name="CodePushServerUrl" value="...instance of @byronigoe/code-push-server..." />
  <platform name="ios">
    <preference name="iosPersistentFileLocation" value="Library" />
    <preference name="iosExtraFilesystems" value="library,library-nosync,documents,documents-nosync,cache,bundle,root" />
    <preference name="BackupWebStorage" value="none" />
    <preference name="CodePushDeploymentKey" value="..." />
  </platform>
  <platform name="android">
    <preference name="android-build-tool" value="gradle" />
    <preference name="AndroidPersistentFileLocation" value="Internal" />
    <preference name="CodePushDeploymentKey" value="..." />
    <preference name="android-targetSdkVersion" value="30" />
    <preference name="AndroidInsecureFileModeEnabled" value="true" />
  </platform>
</widget>

I'm using cordova-android@10.1.1 and cordova-plugin-code-push@2.0.0, and I'm still using @shm-open/code-push-cli to deploy, since I haven't had to modify it yet.

I had to add these lines to get around various issues on Android:

  <preference name="scheme" value="..." />
  <preference name="hostname" value="localhost" />
  <preference name="AndroidInsecureFileModeEnabled" value="true" />
byronigoe commented 2 years ago

After reload white screen and the error: ReferenceError: Can't find variable: cordova

@Serg-Mois You need to copy your cordova files into your www directory before you deploy the code-push package. This was true with AppCenter too.

Specifically, include:

These can be found in the build's platform_www folder.

taufpate commented 2 years ago

@Serg-Mois Eureka I was able to get it work! The error was my fault! in server configuration specifically in the DOWNLOAD_URL variable it had http and should be https (I use cloudflare as ssl because i dont know how to configure ssl in codepush server), in the config.xml it was making the call to https correctly.

The origin of issue its because cordova-plugin-code-push use cordova-plugin-advanced-http to connect to your defined CodePushServerUrl, an then the codePush server send a response with the url of latest update available, but the codePush server take DOWNLOAD_URL to construct the url for update package and send it back to the app and cordova-plugin-advanced-http begins download of that url ... and in android fails if the url its not using (SSL)

i took a few hours to figure it out, debugging line by line the codepush plugin but it wat worth it!

@byronigoe was right! the plugin works like a charm, tks!

riderx commented 2 years ago

Hey guys just in case you didn't see my issue here : https://github.com/IllusionVK/ReplaceAppCenter/issues/7#issue-1175870240 i made an alternative plugin fully open source in December. i love the solution of @byronigoe, but for me keeping the old solution in cordova and open source version of code push was too many unknow future.

What i have made so far :

In the future, i plan to release:

And many more, hope this message is not seen as spammy, i saw many persons a bit lost about this Microsoft announcement i and try to help

byronigoe commented 2 years ago

FYI, I also have Code Push working in a Capacitor project on Android using: https://github.com/byronigoe/capacitor-codepush and the same self-hosted back-end.

byronigoe commented 2 years ago

And now I have the Capacitor plugin working on iOS too! The Capacitor plugin is a wrapper around the Cordova plugin, so I will have to maintain very little.

wongpeiyi commented 2 years ago

Hey everyone, I spent most of today setting up a CodePush server for Cordova on EC2 and documented my experience here: https://medium.com/@wongpeiyi_75194/running-your-own-codepush-server-836f3aa92922

Thanks @byronigoe for your work.

While I've gotten it working, there's still a lot I'm unsure about, so appreciate any feedback.

vesper8 commented 2 years ago

Hey everyone, I spent most of today setting up a CodePush server for Cordova on EC2 and documented my experience here: https://medium.com/@wongpeiyi_75194/running-your-own-codepush-server-836f3aa92922

Thanks @byronigoe for your work.

While I've gotten it working, there's still a lot I'm unsure about, so appreciate any feedback.

@wongpeiyi That's a great writeup and is super useful! Thanks a lot for putting the solution to the test and sharing your experience!!

IllusionVK commented 2 years ago

Thanks for the writeup @wongpeiyi. We also have the solution running and we also have a PR that we need to commit soon that allows for the solution to use MS SQL as the only database that is needed (so that redis and mysql are not needed) (we did this 1 month ago and need to push this incase it helps anyone else). We needed this so that we could use our normal database to help reduce the stack that is used.

wongpeiyi commented 2 years ago

@byronigoe @IllusionVK there is one thing I can't figure out. It appears using ranges for the targetBinaryVersion doesn't work like AppCenter's code push did. For example:

Label  |  Target
---------------------
 v2    |  1.0.0-1.0.2
 v1    |  1.0.0-1.0.1

It will update to v1, but will not apply v2. Even if I disable v1, no update is done. The only thing I can do is update v1 to some other target, like 1.0.00

It appears this was an open issue in the original repo. How are you all handling this?

byronigoe commented 2 years ago

How are you all handling this?

@wongpeiyi I use semantic versioning (e.g. ~1.0.0), which is the "right" way.

If you make changes to your app such that future code-push deployments must be different, then you should bump the minor or major version.

byronigoe commented 2 years ago

@wongpeiyi I looked into this some more, and now I understand the problem. There is code to find all applicable deployments, then to choose the one with the narrowest scope. So, if the client has 1.0.0 or 1.0.1, then both v1 and v2 are applicable, and v1 will be chosen because it has a smaller scope. I think this is wrong, and I'm working to address it.

IllusionVK commented 2 years ago

Hey @byronigoe thanks for looking into this. You will see that I commented on the other repo, and i agree with you that it needs to be fixed. We haven't seen this problem ourselves due to our versions numbers I guess, but thanks for highlighting it @wongpeiyi

wongpeiyi commented 2 years ago

@byronigoe actually I already solved it last week. I'm using my own fork instead of your repo. Sorry I didn't update here, I'll submit a PR now

I also submitted another PR last week to fix isDisabled not showing properly. Not sure if you saw that

If you think the PRs should be merged further upstream, I can possibly submit them to shm-open, but I think lisong is not actively maintained. Let me know if you only intend your fork to be a translation and nothing more

byronigoe commented 2 years ago

Thanks! I merged it, and submitted a PR to shm-open

pilz97 commented 2 years ago

Hi @byronigoe

thank you for your awesome work.

We successfully set up our own code push server with your fork. I have only one problem with the code push update in my cordova app, the download/sync fails with An error has occurred while installing the package. Could not get the package start page

I now downgraded from cordova-android 10.1.1 to 9.1.0. With the downgrade the sync works fine.

Do you have any idea why it won't work with cordova-android 10.x? At the moment it's no problem for us to keep your app on version 9.1.0, but it would be nice if we could upgrade it again in the future.

byronigoe commented 2 years ago

@pilz97 I'm using cordova-android 10.1.1. You may just need to upgrade to the latest code-push:

Here's an excerpt from my package.json devDependencies:

    "code-push": "^3.0.1",
    "cordova-android": "^10.1.1",
    "cordova-plugin-advanced-http": "^3.2.2",
    "cordova-plugin-androidx-adapter": "^1.1.3",
    "cordova-plugin-code-push": "^2.0.0",
    "cordova-plugin-file": "^6.0.2",
    "cordova-plugin-zip": "github:SunPower/cordova-plugin-zip",
kbrownlees commented 1 year ago

For anyone interested, there are also some fixes to the code push plugin in our branch: https://github.com/cloudscapelabs/cordova-plugin-code-push/commits/master

We recently updated to the latest cordova-android & cordova-ios (including WkWebView) and everything seems to be working well.

tewnut commented 1 year ago

For me Capgo looks like a good solution, you can use Capgo server (cost is more reasonable than appflow), or you can host your own server https://docs.capgo.app/self-hosted/manual

Pigsnuck commented 1 year ago

<?xml version='1.0' encoding='utf-8'?>

... ... ...

I'm using cordova-android@10.1.1 and cordova-plugin-code-push@2.0.0, and I'm still using @shm-open/code-push-cli to deploy, since I haven't had to modify it yet.
I had to add these lines to get around various issues on Android:

Thanks for the info. I am also experiencing this error.

What is the value you used for "scheme"?

byronigoe commented 1 year ago

What is the value you used for "scheme"?

Whatever you want the deep-links to be. For example, "foo" would mean deep-link URLs are of the form "foo://...".

Pigsnuck commented 1 year ago

Hi byronigoe. I need some assistance to set this up. Can you please contact me directly on cyphers-squeak-0a@icloud.com and let me know your hourly rate? Thanks.

byronigoe commented 1 year ago

Hi byronigoe. I need some assistance to set this up. Can you please contact me directly on cyphers-squeak-0a@icloud.com and let me know your hourly rate? Thanks.

@Pigsnuck I emailed you over 3 weeks ago, but haven't heard back.

Pigsnuck commented 1 year ago

Hi byronigoe. I need some assistance to set this up. Can you please contact me directly on cyphers-squeak-0a@icloud.com and let me know your hourly rate? Thanks.

@Pigsnuck I emailed you over 3 weeks ago, but haven't heard back.

That's weird, I wrote back immediately. I am still looking for help.

I just tried replying to your email again and it was rejected. Can you try writing me using a different return email address, please?

Thanks!