{"componentChunkName":"component---src-pages-tutorial-react-step-5-mdx","path":"/tutorial/react/step-5/","result":{"pageContext":{"isCreatedByStatefulCreatePages":true,"frontmatter":{"title":"5. Deploying to IBM Cloud","description":"Welcome to Carbon! This tutorial will guide you in creating a React app with the Carbon Design System.","tabs":["Overview","Step 1","Step 2","Step 3","Step 4","Step 5","Wrapping up"]},"relativePagePath":"/tutorial/react/step-5.mdx","titleType":"prepend","MdxNode":{"id":"4a43028c-4632-5ca3-b016-0acb8f6b05b8","children":[],"parent":"8f3330b6-0041-51a7-b077-be810cc04f7f","internal":{"content":"---\ntitle: 5. Deploying to IBM Cloud\ndescription: Welcome to Carbon! This tutorial will guide you in creating a React app with the Carbon Design System.\ntabs:\n  ['Overview', 'Step 1', 'Step 2', 'Step 3', 'Step 4', 'Step 5', 'Wrapping up']\n---\n\nimport Preview from 'components/Preview';\n\n### This step takes what we've built so far and optimizes the app for a production environment. We'll be deploying the production build to IBM Cloud.\n\n<AnchorLinks>\n\n<AnchorLink>Fork, clone and branch</AnchorLink>\n<AnchorLink>Create IBM Cloud account</AnchorLink>\n<AnchorLink>Optimize Sass</AnchorLink>\n<AnchorLink>Build for production</AnchorLink>\n<AnchorLink>Create manifest file</AnchorLink>\n<AnchorLink>Create static file</AnchorLink>\n<AnchorLink>Deploy app</AnchorLink>\n<AnchorLink>Submit pull request</AnchorLink>\n\n</AnchorLinks>\n\n## Preview\n\nA [preview](https://react-step-6--carbon-tutorial.netlify.com) of what you'll build (visually no different, but built for production):\n\n<Preview\n  height=\"400\"\n  title=\"Carbon Tutorial Step 5\"\n  src=\"https://react-step-6--carbon-tutorial.netlify.com\"\n  frameborder=\"no\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n  class=\"bx--iframe bx--iframe--border\"\n/>\n\n## Fork, clone and branch\n\nThis tutorial has an accompanying GitHub repository called [carbon-tutorial](https://github.com/carbon-design-system/carbon-tutorial) that we'll use as a starting point for each step. If you haven't forked and cloned that repository yet, and haven't added the upstream remote, go ahead and do so by following the [step 1 instructions](/tutorial/react/step-1#fork-clone--branch).\n\n### Branch\n\nWith your repository all set up, let's check out the branch for this tutorial step's starting point.\n\n```bash\n$ git fetch upstream\n$ git checkout -b react-step-5 upstream/react-step-5\n```\n\n_Note: This builds on top of step 4, but be sure to check out the upstream step 5 branch because it includes the static assets required to get through this step._\n\n### Build and start app\n\nInstall the app's dependencies (in case you're starting fresh in your current directory and not continuing from the previous step):\n\n```bash\n$ yarn\n```\n\nThen, start the app:\n\n```bash\n$ yarn start\n```\n\nYou should see something similar to where the [previous step](/tutorial/react/step-4) left off.\n\n## Create IBM Cloud account\n\nBefore we get started, [create an IBM Cloud account](https://cloud.ibm.com/registration) if you don't already have one, as we'll be deploying there in a bit.\n\n## Optimize Sass\n\nSo far we've been developing in a, well, development environment where static asset optimization hasn't been a priority. If you reference `/src/index.scss`, you'll see one `@import` that is pulling in Carbon's full Sass build.\n\n```scss path=src/index.scss\n$feature-flags: (\n  ui-shell: true,\n  grid-columns-16: true,\n);\n\n@import 'carbon-components/scss/globals/scss/styles.scss';\n```\n\nTo give you an idea of what's all included, open up `node_modules/carbon-components/scss/globals/scss/styles.scss`. You'll see imports for components like accordion, slider, tooltip, etc. Since we aren't using those components, let's exclude them from our built stylesheets. Keeping the `$feature-flags` Sass map, replace the `styles.scss` import with:\n\n```scss path=src/index.scss\n// Feature flags\n$css--font-face: true;\n$css--plex: true;\n\n// Global styles\n@import 'carbon-components/scss/globals/scss/css--font-face';\n@import 'carbon-components/scss/globals/grid/grid';\n\n// Carbon components\n@import 'carbon-components/scss/components/breadcrumb/breadcrumb';\n@import 'carbon-components/scss/components/button/button';\n@import 'carbon-components/scss/components/data-table/data-table';\n@import 'carbon-components/scss/components/link/link';\n@import 'carbon-components/scss/components/pagination/pagination';\n@import 'carbon-components/scss/components/tabs/tabs';\n@import 'carbon-components/scss/components/ui-shell/ui-shell';\n```\n\nIn comparing to the included `carbon-components/scss/globals/scss/styles.scss`, you may be asking what happened to importing `_vars.scss`, `_colors.scss`, `_theme.scss`, etc.?\n\nMany of those global Sass partials get imported through the components. For example, open `node_modules/carbon-components/scss/components/button/_button.scss` to see its dependencies. No harm in importing them as `carbon-components/scss/globals/scss/styles.scss` does, but for simplicity here, we'll let the components pull them in.\n\nYou can read more about optimizing Carbon's Sass in the [Carbon Design System publication](https://medium.com/carbondesign/minimal-css-with-carbon-b0c089ccfa71) on Medium.\n\n## Build for production\n\nBefore we deploy our app, we need to create an optimized production build with this command. You may need to `CTRL-C` to stop the development environment first.\n\n```bash\n$ yarn build\n```\n\nLooking at `package.json`, you'll find `yarn build` to run `react-scripts build`. This builds the app for production to the `build` folder. It bundles React in production mode and optimizes the build for the best performance. It even goes so far to minify files and include hashes in filenames for caching.\n\nAs a lot of this may seem like magic since the build configuration came from Create React App, go ahead and check out their [production build guidelines](https://facebook.github.io/create-react-app/docs/production-build) for a full description of what's happening.\n\n## Create manifest file\n\nNow that we have a production build, let's get it on the cloud. We're going to use [staticfile-buildpack](https://github.com/cloudfoundry/staticfile-buildpack.git) to deploy our webapp. Since this is a Cloud Foundry buildpack, we'll be using the `cf` command line interface (CLI). If running `cf --help` doesn't work for you, chances are you need to [install the CLI](https://docs.cloudfoundry.org/cf-cli/install-go-cli.html).\n\n_Note: If unfamiliar with buildpacks, the [staticfile buildpack docs](https://docs.cloudfoundry.org/buildpacks/staticfile/index.html) has good definitions and configuration documentation._\n\nWith the Cloud Foundry CLI installed, next, we need to create a `manifest.yml` file in the root of the project. To prevent multiple apps trying to use the `carbon-tutorial` name, replace `USERNAME` with your GitHub username below to make sure our apps are uniquely named.\n\n```bash path=manifest.yml\n---\napplications:\n  - name: carbon-tutorial-USERNAME\n    memory: 64M\n    buildpack: https://github.com/cloudfoundry/staticfile-buildpack.git\n```\n\n_Note: With this set-up we're still using a GitHub personal access token saved in _`.env.local`_. If you haven't created a GitHub access token yet, see [step 3](/tutorial/react/step-3#create-access-token). You can put the environment variable in the manifest file, or manually add it in the IBM Cloud dashboard, but since we're building off previous tutorial steps nothing more is needed._\n\n## Create static file\n\nCreate a new static file in the root of the project named `Staticfile`. This tells the app to deploy from the `build` folder and not the root of the project.\n\n```bash path=Staticfile\nroot: build\n```\n\n### Cloud Foundry ignore\n\nAfter telling Cloud Foundry what to include, we can also specify what to ignore. Create a top-level `.cfignore` file. Cloud Foundry doesn't let you push read-only files (specifically, files with permissions <`400`), so to prevent issues with the deploy, add:\n\n```bash path=.cfignore\nnode_modules/.cache\n```\n\nYou can speed up deploys by decreasing the files uploaded through cloud foundry. To accomplish this, ignore any folder not required by the production application on IBM Cloud. For example, in the case of serving static files, you can ignore `node_modules/` and `src/` because the only folder being served is `build/`.\n\n## Deploy app\n\nLogin to IBM Cloud with:\n\n```bash\n$ cf login -a https://api.ng.bluemix.net -sso\n```\n\nDeploy app using the `cf push` command. Since `manifest.yml` is in our root directory, we don't need to specify it in the push command. But, if you have multiple manifest files that target different environments, it's good practice to specify the file.\n\n```bash\n$ cf push -f manifest.yml\n```\n\nTo make it easy on ourselves by not needing to remember that command, let's add a script in `package.json`. We can combine the build and deploy steps to make sure we only deploy immediately after running the build. In the `\"scripts\"` object in `package.json`, add:\n\n```bash path=package.json\n\"deploy\": \"rm -rf ./build && yarn build && cf push -f manifest.yml\"\n```\n\nNext time you want to deploy, you can simply run `yarn deploy`.\n\n## Submit pull request\n\nThat does it! We're going to submit a pull request to verify completion of this tutorial step. In doing so, **please include the mybluemix.net URL for your deployed app in your pull request description**.\n\n### Continuous integration (CI) check\n\nRun the CI check to make sure we're all set to submit a pull request.\n\n```bash\n$ yarn ci-check\n```\n\n_Note: Having issues running the CI check? [Step 1](</tutorial/react/step-1#continuous-integration-(ci)-check>) has troubleshooting notes that may help._\n\n### Git commit and push\n\nBefore we can create a pull request, stage and commit all of your changes:\n\n```bash\n$ git add --all && git commit -m \"feat(tutorial): complete step 5\"\n```\n\nThen, push to your repository:\n\n```bash\n$ git push origin react-step-5\n```\n\n_Note: Having issues pushing your changes? [Step 1](/tutorial/react/step-1#git-commit-and-push) has troubleshooting notes that may help._\n\n### Pull request (PR)\n\nFinally, visit [carbon-tutorial](https://github.com/carbon-design-system/carbon-tutorial) to \"Compare & pull request\". In doing so, make sure that you are comparing to `react-step-5` into `base: react-step-5`.\n\n_Note: Expect your tutorial step PRs to be reviewed by the Carbon team but not merged. We'll close your PR so we can keep the repository's remote branches pristine and ready for the next person!_\n","type":"Mdx","contentDigest":"a2c1a2f6922b1692aad65219e7004903","counter":1512,"owner":"gatsby-plugin-mdx"},"frontmatter":{"title":"5. Deploying to IBM Cloud","description":"Welcome to Carbon! This tutorial will guide you in creating a React app with the Carbon Design System.","tabs":["Overview","Step 1","Step 2","Step 3","Step 4","Step 5","Wrapping up"]},"exports":{},"rawBody":"---\ntitle: 5. Deploying to IBM Cloud\ndescription: Welcome to Carbon! This tutorial will guide you in creating a React app with the Carbon Design System.\ntabs:\n  ['Overview', 'Step 1', 'Step 2', 'Step 3', 'Step 4', 'Step 5', 'Wrapping up']\n---\n\nimport Preview from 'components/Preview';\n\n### This step takes what we've built so far and optimizes the app for a production environment. We'll be deploying the production build to IBM Cloud.\n\n<AnchorLinks>\n\n<AnchorLink>Fork, clone and branch</AnchorLink>\n<AnchorLink>Create IBM Cloud account</AnchorLink>\n<AnchorLink>Optimize Sass</AnchorLink>\n<AnchorLink>Build for production</AnchorLink>\n<AnchorLink>Create manifest file</AnchorLink>\n<AnchorLink>Create static file</AnchorLink>\n<AnchorLink>Deploy app</AnchorLink>\n<AnchorLink>Submit pull request</AnchorLink>\n\n</AnchorLinks>\n\n## Preview\n\nA [preview](https://react-step-6--carbon-tutorial.netlify.com) of what you'll build (visually no different, but built for production):\n\n<Preview\n  height=\"400\"\n  title=\"Carbon Tutorial Step 5\"\n  src=\"https://react-step-6--carbon-tutorial.netlify.com\"\n  frameborder=\"no\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n  class=\"bx--iframe bx--iframe--border\"\n/>\n\n## Fork, clone and branch\n\nThis tutorial has an accompanying GitHub repository called [carbon-tutorial](https://github.com/carbon-design-system/carbon-tutorial) that we'll use as a starting point for each step. If you haven't forked and cloned that repository yet, and haven't added the upstream remote, go ahead and do so by following the [step 1 instructions](/tutorial/react/step-1#fork-clone--branch).\n\n### Branch\n\nWith your repository all set up, let's check out the branch for this tutorial step's starting point.\n\n```bash\n$ git fetch upstream\n$ git checkout -b react-step-5 upstream/react-step-5\n```\n\n_Note: This builds on top of step 4, but be sure to check out the upstream step 5 branch because it includes the static assets required to get through this step._\n\n### Build and start app\n\nInstall the app's dependencies (in case you're starting fresh in your current directory and not continuing from the previous step):\n\n```bash\n$ yarn\n```\n\nThen, start the app:\n\n```bash\n$ yarn start\n```\n\nYou should see something similar to where the [previous step](/tutorial/react/step-4) left off.\n\n## Create IBM Cloud account\n\nBefore we get started, [create an IBM Cloud account](https://cloud.ibm.com/registration) if you don't already have one, as we'll be deploying there in a bit.\n\n## Optimize Sass\n\nSo far we've been developing in a, well, development environment where static asset optimization hasn't been a priority. If you reference `/src/index.scss`, you'll see one `@import` that is pulling in Carbon's full Sass build.\n\n```scss path=src/index.scss\n$feature-flags: (\n  ui-shell: true,\n  grid-columns-16: true,\n);\n\n@import 'carbon-components/scss/globals/scss/styles.scss';\n```\n\nTo give you an idea of what's all included, open up `node_modules/carbon-components/scss/globals/scss/styles.scss`. You'll see imports for components like accordion, slider, tooltip, etc. Since we aren't using those components, let's exclude them from our built stylesheets. Keeping the `$feature-flags` Sass map, replace the `styles.scss` import with:\n\n```scss path=src/index.scss\n// Feature flags\n$css--font-face: true;\n$css--plex: true;\n\n// Global styles\n@import 'carbon-components/scss/globals/scss/css--font-face';\n@import 'carbon-components/scss/globals/grid/grid';\n\n// Carbon components\n@import 'carbon-components/scss/components/breadcrumb/breadcrumb';\n@import 'carbon-components/scss/components/button/button';\n@import 'carbon-components/scss/components/data-table/data-table';\n@import 'carbon-components/scss/components/link/link';\n@import 'carbon-components/scss/components/pagination/pagination';\n@import 'carbon-components/scss/components/tabs/tabs';\n@import 'carbon-components/scss/components/ui-shell/ui-shell';\n```\n\nIn comparing to the included `carbon-components/scss/globals/scss/styles.scss`, you may be asking what happened to importing `_vars.scss`, `_colors.scss`, `_theme.scss`, etc.?\n\nMany of those global Sass partials get imported through the components. For example, open `node_modules/carbon-components/scss/components/button/_button.scss` to see its dependencies. No harm in importing them as `carbon-components/scss/globals/scss/styles.scss` does, but for simplicity here, we'll let the components pull them in.\n\nYou can read more about optimizing Carbon's Sass in the [Carbon Design System publication](https://medium.com/carbondesign/minimal-css-with-carbon-b0c089ccfa71) on Medium.\n\n## Build for production\n\nBefore we deploy our app, we need to create an optimized production build with this command. You may need to `CTRL-C` to stop the development environment first.\n\n```bash\n$ yarn build\n```\n\nLooking at `package.json`, you'll find `yarn build` to run `react-scripts build`. This builds the app for production to the `build` folder. It bundles React in production mode and optimizes the build for the best performance. It even goes so far to minify files and include hashes in filenames for caching.\n\nAs a lot of this may seem like magic since the build configuration came from Create React App, go ahead and check out their [production build guidelines](https://facebook.github.io/create-react-app/docs/production-build) for a full description of what's happening.\n\n## Create manifest file\n\nNow that we have a production build, let's get it on the cloud. We're going to use [staticfile-buildpack](https://github.com/cloudfoundry/staticfile-buildpack.git) to deploy our webapp. Since this is a Cloud Foundry buildpack, we'll be using the `cf` command line interface (CLI). If running `cf --help` doesn't work for you, chances are you need to [install the CLI](https://docs.cloudfoundry.org/cf-cli/install-go-cli.html).\n\n_Note: If unfamiliar with buildpacks, the [staticfile buildpack docs](https://docs.cloudfoundry.org/buildpacks/staticfile/index.html) has good definitions and configuration documentation._\n\nWith the Cloud Foundry CLI installed, next, we need to create a `manifest.yml` file in the root of the project. To prevent multiple apps trying to use the `carbon-tutorial` name, replace `USERNAME` with your GitHub username below to make sure our apps are uniquely named.\n\n```bash path=manifest.yml\n---\napplications:\n  - name: carbon-tutorial-USERNAME\n    memory: 64M\n    buildpack: https://github.com/cloudfoundry/staticfile-buildpack.git\n```\n\n_Note: With this set-up we're still using a GitHub personal access token saved in _`.env.local`_. If you haven't created a GitHub access token yet, see [step 3](/tutorial/react/step-3#create-access-token). You can put the environment variable in the manifest file, or manually add it in the IBM Cloud dashboard, but since we're building off previous tutorial steps nothing more is needed._\n\n## Create static file\n\nCreate a new static file in the root of the project named `Staticfile`. This tells the app to deploy from the `build` folder and not the root of the project.\n\n```bash path=Staticfile\nroot: build\n```\n\n### Cloud Foundry ignore\n\nAfter telling Cloud Foundry what to include, we can also specify what to ignore. Create a top-level `.cfignore` file. Cloud Foundry doesn't let you push read-only files (specifically, files with permissions <`400`), so to prevent issues with the deploy, add:\n\n```bash path=.cfignore\nnode_modules/.cache\n```\n\nYou can speed up deploys by decreasing the files uploaded through cloud foundry. To accomplish this, ignore any folder not required by the production application on IBM Cloud. For example, in the case of serving static files, you can ignore `node_modules/` and `src/` because the only folder being served is `build/`.\n\n## Deploy app\n\nLogin to IBM Cloud with:\n\n```bash\n$ cf login -a https://api.ng.bluemix.net -sso\n```\n\nDeploy app using the `cf push` command. Since `manifest.yml` is in our root directory, we don't need to specify it in the push command. But, if you have multiple manifest files that target different environments, it's good practice to specify the file.\n\n```bash\n$ cf push -f manifest.yml\n```\n\nTo make it easy on ourselves by not needing to remember that command, let's add a script in `package.json`. We can combine the build and deploy steps to make sure we only deploy immediately after running the build. In the `\"scripts\"` object in `package.json`, add:\n\n```bash path=package.json\n\"deploy\": \"rm -rf ./build && yarn build && cf push -f manifest.yml\"\n```\n\nNext time you want to deploy, you can simply run `yarn deploy`.\n\n## Submit pull request\n\nThat does it! We're going to submit a pull request to verify completion of this tutorial step. In doing so, **please include the mybluemix.net URL for your deployed app in your pull request description**.\n\n### Continuous integration (CI) check\n\nRun the CI check to make sure we're all set to submit a pull request.\n\n```bash\n$ yarn ci-check\n```\n\n_Note: Having issues running the CI check? [Step 1](</tutorial/react/step-1#continuous-integration-(ci)-check>) has troubleshooting notes that may help._\n\n### Git commit and push\n\nBefore we can create a pull request, stage and commit all of your changes:\n\n```bash\n$ git add --all && git commit -m \"feat(tutorial): complete step 5\"\n```\n\nThen, push to your repository:\n\n```bash\n$ git push origin react-step-5\n```\n\n_Note: Having issues pushing your changes? [Step 1](/tutorial/react/step-1#git-commit-and-push) has troubleshooting notes that may help._\n\n### Pull request (PR)\n\nFinally, visit [carbon-tutorial](https://github.com/carbon-design-system/carbon-tutorial) to \"Compare & pull request\". In doing so, make sure that you are comparing to `react-step-5` into `base: react-step-5`.\n\n_Note: Expect your tutorial step PRs to be reviewed by the Carbon team but not merged. We'll close your PR so we can keep the repository's remote branches pristine and ready for the next person!_\n","fileAbsolutePath":"/zeit/3eb073a4/src/pages/tutorial/react/step-5.mdx"}}}}