Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 9aafc2a

Browse files
committed
Adding multi-deplyoment docs
1 parent ba8d528 commit 9aafc2a

File tree

1 file changed

+106
-1
lines changed

1 file changed

+106
-1
lines changed

README.md

Lines changed: 106 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ This plugin provides client-side integration for the [CodePush service](http://c
1717
* [Java API Reference (Android)](#java-api-reference-android)
1818
* [Debugging / Troubleshooting](#debugging--troubleshooting)
1919
* [Example Apps / Starters](#example-apps--starters)
20+
* [Multi-Deployment Releases](#multi-deplyoment-releases)
2021
* [Continuous Integration / Delivery](#continuous-integration--delivery)
2122

2223
## How does it work?
@@ -980,9 +981,113 @@ Now you'll be able to see CodePush logs in either debug or release mode, on both
980981
| Images dissappear after installing CodePush update | If your app is using the React Native assets system to load images (i.e. the `require(./foo.png)` syntax), then you **MUST** release your assets along with your JS bundle to CodePush. Follow [these instructions](#releasing-updates-javascript--images) to see how to do this. |
981982
| No JS bundle is being found when running your app against the iOS simulator | By default, React Native doesn't generate your JS bundle when running against the simulator. Therefore, if you're using `[CodePush bundleURL]`, and targetting the iOS simulator, you may be getting a `nil` result. This issue will be fixed in RN 0.22.0, but only for release builds. You can unblock this scenario right now by making [this change](https://github.com/facebook/react-native/commit/9ae3714f4bebdd2bcab4d7fdbf23acebdc5ed2ba) locally.
982983
984+
## Multi-Deployment Releases
985+
986+
In our [getting started](#getting-started) docs, we illustrated how to configure the CodePush plugin, using a specific deployment key. However, in order to effectively test your releases, it is critical that you leverage the `Staging` and `Production` deployments that are auto-generated when you first created your CodePush app. This way, you never release an update to your end users that you haven't been able to validate yourself.
987+
988+
*NOTE: Our client-side rollback feature can help mitigate releases which result in an app crash, and server-side rollbacks (e.g. `code-push rollback`) allow you to prevent additional users from installing a bad release, however, it's obviously better if you can prevent an erroneous update from being broadly released in the first place.*
989+
990+
Setting this up requires unique steps for each platform, so refer to the following sections for an example of how this can be achieved in your React Native app, depending on the platform(s) you are targeting.
991+
992+
### Android
993+
994+
The [Android Gradle plugin](http://google.github.io/android-gradle-dsl/current/index.html) allows you to define custom config settings for each "build type" (e.g. debug, release), which in turn are generated as properties on the `BuildConfig` class that you can reference from your Java code. This mechanism allows you to easily configure your debug builds to use your CodePush staging deployment key, and your release builds to use your CodePush production deployment key.
995+
996+
To set this up, perform the following steps:
997+
998+
1. Open your app's `build.gradle` file (e.g. `android/app/build.gradle`)
999+
1000+
2. Find the `android { buildTypes }` section and define [`buildConfigField`](http://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.BuildType.html#com.android.build.gradle.internal.dsl.BuildType:buildConfigField(java.lang.String,%20java.lang.String,%20java.lang.String) entries for both your `debug` and `release` build types, which reference your `Staging` and `Production` deployment keys respectively.
1001+
1002+
```groovy
1003+
android {
1004+
...
1005+
buildTypes {
1006+
debug {
1007+
...
1008+
buildConfigField "String", "CODEPUSH_KEY", "<INSERT_STAGING_KEY>"
1009+
...
1010+
}
1011+
1012+
release {
1013+
...
1014+
buildConfigField "String", "CODEPUSH_KEY", "<INSERT_PRODUCTION_KEY>"
1015+
...
1016+
}
1017+
}
1018+
...
1019+
}
1020+
```
1021+
1022+
*NOTE: As a reminder, you can retrieve these keys by running `code-push deployment ls <APP_NAME> -k` from your terminal.*
1023+
1024+
4. Open up your `MainAtivity.java` file and change the `CodePush` constructor to pass the deployment key in via the build config you just defined, as opposed to a string literal.
1025+
1026+
```java
1027+
new CodePush(BuildConfig.CODEPUSH_KEY, this, BuildConfig.DEBUG);
1028+
```
1029+
1030+
*Note: If you gave your build setting a different name in your Gradle file, simply make sure to reflect that in your Java code.*
1031+
1032+
And that's it! Now when you run or build your app, your debug builds will automatically be configured to sync with your `Staging` deployment, and your release builds will be configured to sync with your `Production` deployment.
1033+
1034+
If you want to be able to install both debug and release builds simultaneously on the same device, then you can also specify an [`applicationIdSuffix`](http://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.BuildType.html#com.android.build.gradle.internal.dsl.BuildType:applicationIdSuffix) field for your debug build type, so that the OS sees them as seperate apps (e.g. `com.foo` and `com.foo.debug`).
1035+
1036+
```groovy
1037+
buildTypes {
1038+
debug {
1039+
applicationIdSuffix ".debug"
1040+
}
1041+
}
1042+
```
1043+
1044+
Additionally, if you want to give them seperate names and/or icons, you can define new resource files (`strings.xml` and drawables) for your debug build by creating a `app/src/debug` directory. View [here](http://tools.android.com/tech-docs/new-build-system/resource-merging) for more details on how resource merging works in Android.
1045+
1046+
Finally, refer to the [React Native docs](http://facebook.github.io/react-native/docs/signed-apk-android.html#content) for details about how to configure and create release builds for your Android apps.
1047+
1048+
### iOS
1049+
1050+
Xcode allows you to define custom build settings for each "configuration" (e.g. debug, release), which can then be referenced as the value of keys within the `Info.plist` file. This mechanism allows you to easily configure your debug builds to use your CodePush staging deployment key, and your release builds to use your CodePush production deployment key.
1051+
1052+
To set this up, perform the following steps:
1053+
1054+
1. Open up your Xcode project and select your project in the `Project navigator` window
1055+
1056+
2. Select the `Build Settings` tab
1057+
1058+
3. Click the `+` button on the toolbar and select `Add User-Defined Setting`
1059+
1060+
![Setting](https://cloud.githubusercontent.com/assets/116461/15764165/a16dbe30-28dd-11e6-94f2-fa3b7eb0c7de.png)
1061+
1062+
4. Name this new setting something like `CODEPUSH_KEY`, expand it, and specify your `Staging` deployment key for the `Debug` config and your `Production` deployment key for the `Production` config.
1063+
1064+
![Setting Keys](https://cloud.githubusercontent.com/assets/116461/15764230/106c245c-28de-11e6-96fe-2615f9220b07.png)
1065+
1066+
*NOTE: As a reminder, you can retrieve these keys by running `code-push deployment ls <APP_NAME> -k` from your terminal.*
1067+
1068+
5. Open your project's `Info.plist` file and change the value of your `CodePushDeploymentKey` entry to `$(CODEPUSH_KEY)`
1069+
1070+
![Infoplist](https://cloud.githubusercontent.com/assets/116461/15764252/3ac8aed2-28de-11e6-8c19-2270ae9857a7.png)
1071+
1072+
And that's it! Now when you run or build your app, your debug builds will automatically be configured to sync with your `Staging` deployment, and your release builds will be configured to sync with your `Production` deployment.
1073+
1074+
If you want to be able to install both debug and release builds simultaneously on the same device, then you can also specify an [`applicationIdSuffix`](http://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.BuildType.html#com.android.build.gradle.internal.dsl.BuildType:applicationIdSuffix) field for your debug build type, so that the OS sees them as seperate apps (e.g. `com.foo` and `com.foo.debug`).
1075+
1076+
```groovy
1077+
buildTypes {
1078+
debug {
1079+
applicationIdSuffix ".debug"
1080+
}
1081+
}
1082+
```
1083+
1084+
Additionally, if you want to give them seperate names and/or icons, you can modify the `Product Name` and `Asset Catalog App Icon Set Name` build settings, so that the debug configuration has a unique value.
1085+
1086+
![Product name](https://cloud.githubusercontent.com/assets/116461/15764314/b3a4cfac-28de-11e6-9e8c-b1cbd8ac7c6c.png)
1087+
9831088
## Continuous Integration / Delivery
9841089
9851090
In addition to being able to use the CodePush CLI to "manually" release updates, we believe that it's important to create a repeatable and sustainable solution for contiously delivering updates to your app. That way, it's simple enough for you and/or your team to create and maintain the rhythm of performing agile deployments. In order to assist with seting up a CodePush-based CD pipeline, refer to the following integrations with various CI servers:
9861091
9871092
* [Visual Studio Team Services](https://marketplace.visualstudio.com/items?itemName=ms-vsclient.code-push) - *NOTE: VSTS also has extensions for publishing to [HockeyApp](https://marketplace.visualstudio.com/items?itemName=ms.hockeyapp) and the [Google Play](https://github.com/Microsoft/google-play-vsts-extension) store, so it provides a pretty great mobile CD solution in general.*
988-
* [Travis CI](https://github.com/mondora/code-push-travis-cli)
1093+
* [Travis CI](https://github.com/mondora/code-push-travis-cli)

0 commit comments

Comments
 (0)