ReactAWS
A quick test of using GitHub actions for a CI build and deploy of a React scaffold to AWS S3
In this case: http://react-aws-github-integration-test.s3-website.ca-central-1.amazonaws.com
Prerequisites
- node.js installed
npm
installedcreate-react-app
installed
Create minimal react app
$ npx create-react-app minimal-react
Smoke test
$ cd minimal-react
$ npm start
This should make the app available at : http://localhost:3000/
Build
$ npm run build
Upload to S3
- Create an S3 bucket
- Upload the contents of the
build
folder to this bucket - Enable
Static website hosting
- Make a note of the URL
In this case: http://react-aws-github-integration-test.s3-website.ca-central-1.amazonaws.com
Routing
In order to test AWS S3 website hosting, we will create some stub pages.
- Login (Home) page
- Sign Up page
- Forgot Password page
- Does not exist (404) page
Test the 404 page: http://react-aws-github-integration-test.s3-website.ca-central-1.amazonaws.com/does-not-exist
Reference
Some useful references follow.
Create React App
In order to properly twelve-factor our app, we will need to use environment variables.
Adding Custom Environment Variables
TL;DR Define application variables in a .env file (which may be checked-in) and environment variables in .env.local (which can probably also be checked-in) as well as in .env.staging or .env.prod (which should definitely NOT be checked-in). The normal practice is to define production variables in .env but the React.js workflow seems to be slightly different.
GitHub Actions
These seem to be the new kid on the block in terms of Jenkins/CircleCI/TravisCI/GitLab CI integrations.
But good examples (and even documentation) seem to be scarce. GitLab has a good linter for their YAML files!
[For an example of using GitHub Actions with vue.js, check out my VueRender repo.]
Using Node.js with GitHub Actions
[Caching of dependencies removed as it did not seem to be working.]
Alternatives
There are a number of different options, both for CI/CD and for deployment targets.
CI/CD
Deployment
There are a number of deployment options (in addition to Amazon S3).
Check out this scaffold deployed on Netlify: https://compassionate-sinoussi-40e0e0.netlify.com/
For an extensive list of cloud deployment options (including some Vue.js deployments) please check out my Meatballs repo.
To Do
- Add GitHub actions build badge
- Add linting
- Add prettier code formatting
- Add some routes so we can try out routing on AWS S3
- Add logging-in processing (currently, all
submit
buttons do not do anything) - Add some React tests (also to CI workflow)
- Twelve-factor our build and CI
- Configure AWS IAM for deploying react components to S3 after the build
- Research Caching dependencies
- Amazon Route 53 for domain registration
- Amazon CloudFront for content distribution (CDN)
- AWS Certificate Manager for certification
- Add more notes on cloud deployment options
- Move cloud deployment options to a new Meatballs repo
- Remove link to deleted Heroku deployment (Heroku is no longer free)
- Run 'npm audit fix' to fix some issues