{"componentChunkName":"component---src-templates-lesson-js","path":"/phoenix-chat/continuous-integration-and-deployment","result":{"data":{"mdx":{"body":"function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }\n\nfunction _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }\n\nfunction _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }\n\n/* @jsx mdx */\nvar _frontmatter = {\n  \"title\": \"Continuous Integration and Deployment\",\n  \"order\": 51,\n  \"free\": false,\n  \"active\": true,\n  \"tech\": [\"circleci\"]\n};\n\nvar makeShortcode = function makeShortcode(name) {\n  return function MDXDefaultShortcode(props) {\n    console.warn(\"Component \" + name + \" was not imported, exported, or provided by MDXProvider as global scope\");\n    return mdx(\"div\", props);\n  };\n};\n\nvar layoutProps = {\n  _frontmatter: _frontmatter\n};\nvar MDXLayout = \"wrapper\";\nreturn function MDXContent(_ref) {\n  var components = _ref.components,\n      props = _objectWithoutProperties(_ref, [\"components\"]);\n\n  return mdx(MDXLayout, _extends({}, layoutProps, props, {\n    components: components,\n    mdxType: \"MDXLayout\"\n  }), mdx(\"h1\", null, \"Continuous Integration and Deployment\"), mdx(\"ul\", null, mdx(\"li\", {\n    \"parentName\": \"ul\"\n  }, \"Automated deployment\"), mdx(\"li\", {\n    \"parentName\": \"ul\"\n  }, \"Continuous integration with CircleCI\"), mdx(\"li\", {\n    \"parentName\": \"ul\"\n  }, \"Continuous deployment\")), mdx(\"p\", null, \"We now have a (mostly) functional app that has been uploaded to S3 and is live for the world to see. But opening up AWS and dragging files after a manual build is tedious and prone to error. To remedy this situation, we're going to write an automated deployment script that will run a series of commands to send our newly created site to S3.\"), mdx(\"p\", null, \"Once we have our automated deployment set up, we'll create an account with \", mdx(\"a\", {\n    \"href\": \"circleci.com\",\n    \"parentName\": \"p\"\n  }, \"CircleCI\"), \" for continuous integration. If you're not familiar with continuous integration, it's a service that will automatically build your app, run your tests, and if everything seems to work, it will automatically deploy the current version.\"), mdx(\"p\", null, \"Continuous integration is extremely useful for large organizations that have many developers pushing code to the same codebase at the same time while in production. That said, it requires rigorous testing or you might find yourself in a position where you deployed an update that broke something.\"), mdx(\"h2\", null, \"Automated deployment\"), mdx(\"p\", null, \"We're first going to set up automated deployment on our local environment, then we'll worry about continuous integration. We're going to need to install the AWS command line tool.\"), mdx(\"pre\", null, mdx(\"code\", {\n    \"className\": \"language-bash\",\n    \"parentName\": \"pre\"\n  }, \"$ brew install awscli\\n\")), mdx(\"p\", null, \"Then we need to configure our AWS credentials so we can deploy. You can do this one piece at a time, but I recommend writing a shell script so you can execute these the same way every time. Let's go ahead and create a new file called \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"deploy.sh\"), \".\"), mdx(\"pre\", null, mdx(\"code\", {\n    \"className\": \"language-bash\",\n    \"parentName\": \"pre\"\n  }, \"$ touch deploy.sh\\n\")), mdx(\"p\", null, \"Within this file, we should add all of the necessary commands to deploy to S3. Remember from a previous lesson that we need to \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"export\"), \" all of our environment variables so we can access them later. This is what the \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"source .env.sh\"), \" command was for.\"), mdx(\"pre\", null, mdx(\"code\", {\n    \"className\": \"language-bash\",\n    \"parentName\": \"pre\"\n  }, \"echo \\\"Version number...\\\"\\naws --version\\n\\necho \\\"Configuring access id...\\\"\\naws configure set aws_access_key_id $AWS_ACCESS_KEY_ID\\n\\necho \\\"Configuring secret key...\\\"\\naws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY\\n\\necho \\\"Syncing with $BUCKET\\\"\\naws s3 sync ./dist s3://$BUCKET\\n\")), mdx(\"p\", null, \"If you do not know your bucket location, you can run the following to find out your default region.\"), mdx(\"pre\", null, mdx(\"code\", {\n    \"className\": \"language-bash\",\n    \"parentName\": \"pre\"\n  }, \"$ aws s3api get-bucket-location --bucket $BUCKET\\n\")), mdx(\"p\", null, \"We're also including \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"echo\"), \" commands so we can see in our terminal what step in the process our configuration has reached. This is basically just a \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"console.log\"), \" to let us know if and where we run into issues.\"), mdx(\"p\", null, \"Now we should be ready to deploy. Make sure your terminal is in the root of \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"phoenix-chat-frontend\"), \" and simply run the commands in our \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"deploy.sh\"), \" script.\"), mdx(\"pre\", null, mdx(\"code\", {\n    \"className\": \"language-bash\",\n    \"parentName\": \"pre\"\n  }, \"$ sh deploy.sh\\n\")), mdx(\"p\", null, \"And like magic, all of your files are uploaded. If you want to run a test to make sure your \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"deploy.sh\"), \" script is working, try changing the background to \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"red\"), \" or something obvious and re-deploy. You should see the changes immediately propagate when you refresh the page.\"), mdx(\"h2\", null, \"Continuous integration\"), mdx(\"p\", null, \"The next step is to set up continuous integration. Go ahead and sign up with \", mdx(\"a\", {\n    \"href\": \"circleci.com\",\n    \"parentName\": \"p\"\n  }, \"CircleCI\"), \" and link your Github account. If you have a preference for another continuous integration company, feel free to use them--they're mostly all the same, but the files will be different.\"), mdx(\"p\", null, \"Go ahead and click on \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"Add project\"), \" from the menu on the left, then \", mdx(\"strong\", {\n    \"parentName\": \"p\"\n  }, \"add those environment variables we have stored in our \", mdx(\"inlineCode\", {\n    \"parentName\": \"strong\"\n  }, \".env.sh\"), \" file\"), \" and \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"API_HOST\"), \" and \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"SOCKET_HOST\"), \" as environment variables to CircleCI.\"), mdx(\"p\", null, \"Create a \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"circle.yml\"), \" file at the root of your project. This is required for CircleCI and it gives a series of instructions for CircleCI to execute in order to properly run your code.\"), mdx(\"pre\", null, mdx(\"code\", {\n    \"className\": \"language-bash\",\n    \"parentName\": \"pre\"\n  }, \"$ touch circle.yml\\n\")), mdx(\"p\", null, \"Then add the following code to configure CircleCI. We will go over each line, but there are many more configuration options available. It might be worth your time to skim through the \", mdx(\"a\", {\n    \"href\": \"https://circleci.com/docs/configuration/\",\n    \"parentName\": \"p\"\n  }, \"configuration docs\"), \" to get a sense of how much you can do with CircleCI and the various continuous integration environments.\"), mdx(\"pre\", null, mdx(\"code\", {\n    \"className\": \"language-yml\",\n    \"parentName\": \"pre\"\n  }, \"machine:\\n  node:\\n    version: 6.3.0 # React CSS Loader does not work with 0.X versions of node\\n\\ndependencies:\\n  override:\\n    - npm install\\n    - npm install -g webpack # Need access to webpack cli to build the project\\n    - sudo pip install awscli # Need access to AWS CLI to deploy the project\\n\\ndeployment:\\n  aws:\\n    branch: master\\n    commands:\\n      - chmod +x deploy.sh\\n      - webpack --config webpack.prod.config.js\\n      - ./deploy.sh\\n\")), mdx(\"p\", null, \"The first line sets the version of Node to something we want to use. This is not strictly necessary, but it's good to know what version you're using rather than just accepting the default.\"), mdx(\"p\", null, \"Next we set our dependencies. In this case, we are running \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"npm install\"), \" (which it will run by default anyway, but we're being safe), and two additional installations for the \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"webpack\"), \" command line tool that will allow CircleCI to compile our code and \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"awscli\"), \" which is the AWS command line tool we need to run our \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"deploy.sh\"), \" script.\"), mdx(\"p\", null, \"Finally, we have our deployment to AWS. CircleCI has a special configuration for AWS since so many people use it. We are telling CircleCI to only use these commands for our \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"master\"), \" branch. If you wanted, you could set up special deploy configurations for other branches. It's not uncommon to deploy to \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"beta\"), \" or \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"develop\"), \" to make sure the site works on other branches as you go along.\"), mdx(\"p\", null, \"The only tricky thing here is the \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"chmod +x deploy.sh\"), \", which changes the permissions of our container to allow us to execute the deploy script. \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"chmod\"), \" is one of those things that is rarely covered and used often. If you ever run into errors related to permissions, it's probably an issue with \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"chmod\"), \".\"), mdx(\"p\", null, \"Save this file, git add, git commit, and git push, and you should see CircleCI create a container, build the project, run the tests, then deploy to AWS. Pretty cool!\"));\n}\n;\nMDXContent.isMDXComponent = true;","excerpt":"Continuous Integration and Deployment Automated deployment Continuous integration with CircleCI Continuous deployment We now have a (mostly…","frontmatter":{"title":"Continuous Integration and Deployment","order":51,"active":true,"free":false,"tech":["circleci"]}}},"pageContext":{"slug":"continuous-integration-and-deployment","prevNode":{"frontmatter":{"title":"Deploying the Frontend to S3","active":true,"free":false,"order":50,"tech":["react","webpack","aws"]},"fields":{"slug":"deploying-the-frontend-to-s3"}},"nextNode":{"frontmatter":{"title":"ESLint and Airbnb Style Guide","active":true,"free":false,"order":52,"tech":["react","eslint"]},"fields":{"slug":"eslint-and-airbnb-style-guide"}}}},"staticQueryHashes":["1723017916"]}