2019-05-21 00:56:11 +03:00
[![pullreminders ](https://pullreminders.com/badge.svg )](https://pullreminders.com?ref=badge)
2019-03-30 04:22:03 +03:00
## Firefox Accounts
2014-11-05 04:38:23 +03:00
2019-03-30 04:22:03 +03:00
The Firefox Accounts (fxa) monorepo
2018-02-09 03:16:29 +03:00
2020-03-10 19:05:01 +03:00
### Table of Contents
[Getting Started ](#getting-started )\
[Contributing ](#contributing )\
[Dependencies ](#dependencies )\
2020-03-18 19:26:54 +03:00
[Secrets ](#secrets )\
2020-03-10 19:05:01 +03:00
[Firefox Custom Profile ](#firefox-custom-profile )\
[Functional Tests ](#functional-tests )\
[Node debugging ](#node-debugging )\
[Android debugging ](#android-debugging )\
[FxA Email Service ](#fxa-email-service )\
[Firefox for Android ](#firefox-for-android )\
[Firefox for iOS ](#firefox-for-ios )\
[Running with MailDev ](#running-with-maildev )\
[Other tasks ](#other-tasks )\
[Documentation ](#documentation )
---
2014-11-05 04:38:23 +03:00
### Getting Started
2019-07-01 20:18:11 +03:00
1. **Manually install the system [dependencies](#dependencies) for OS X or Ubuntu.** Note that [WSL ](https://docs.microsoft.com/windows/wsl/ ) is required for development work on Windows.
2015-06-30 19:31:59 +03:00
2. Clone this repository.
```sh
2019-03-30 04:22:03 +03:00
git clone https://github.com/mozilla/fxa.git
2015-06-30 19:31:59 +03:00
```
2016-06-14 16:49:00 +03:00
3. Run:
2015-06-30 19:31:59 +03:00
```sh
2019-03-30 04:22:03 +03:00
cd fxa
2020-05-15 03:48:39 +03:00
yarn install
2019-10-28 23:34:38 +03:00
npm start
2015-06-30 19:31:59 +03:00
```
2020-05-15 03:48:39 +03:00
Note: If `yarn install` fails, ensure your `yarn -v` is at least `1.22.0` .
2020-03-04 04:59:43 +03:00
Note this starts up all required services, including Redis, MySQL, and Memcached. It is recommended that you don't run these services yourself, or occupy any of the [server ports ](https://github.com/mozilla/fxa/blob/master/mysql_servers.json ). Doing so may result in errors.
2020-04-14 23:37:11 +03:00
4. Visit [localhost:3030 ](http://localhost:3030/ ).
2015-06-30 19:31:59 +03:00
2016-04-05 01:03:36 +03:00
Use the [PM2 tool ](https://github.com/Unitech/PM2#main-features ) to stop and start the servers, and read server logs.
2015-06-30 19:31:59 +03:00
2019-10-28 23:34:38 +03:00
To start all servers:
2019-07-01 22:56:34 +03:00
2019-10-28 23:34:38 +03:00
- `npm start`
2018-04-24 04:30:10 +03:00
2019-10-02 16:01:24 +03:00
The most common commands are:
2019-07-01 22:56:34 +03:00
2019-10-28 23:34:38 +03:00
- `npm stop` ** - stop all servers.**
2015-06-30 19:31:59 +03:00
2019-10-02 16:01:24 +03:00
- `./pm2 status` - display running servers.
2015-06-30 19:31:59 +03:00
2019-10-02 16:01:24 +03:00
- `./pm2 logs` - logs for all servers (note: this must be used to verify accounts).
2015-06-30 19:31:59 +03:00
2020-04-10 21:33:30 +03:00
- `./pm2 logs auth` - display logs for service `auth` .
2015-06-30 19:31:59 +03:00
2020-04-10 21:33:30 +03:00
- `./pm2 stop content` - stop `content` service.
2015-06-30 19:31:59 +03:00
2020-04-10 21:33:30 +03:00
- `./pm2 restart mysql` - restart `mysql` process.
2015-06-30 19:31:59 +03:00
2019-10-02 16:01:24 +03:00
- More commands in the [PM2 Readme ](https://github.com/Unitech/PM2#main-features ).
2015-06-30 19:31:59 +03:00
2019-07-01 22:56:34 +03:00
---
2015-05-08 23:19:01 +03:00
2019-04-22 15:14:02 +03:00
### Contributing
See the separate [CONTRIBUTING.md ](https://github.com/mozilla/fxa/blob/master/CONTRIBUTING.md ) to learn how to contribute.
2015-03-16 18:37:33 +03:00
### Workflow
2019-07-01 22:56:34 +03:00
2019-03-30 04:22:03 +03:00
> This is an example workflow for **fxa**.
2015-03-16 18:37:33 +03:00
2019-10-28 23:34:38 +03:00
After installing **fxa** run `npm start` . Use `./pm2 status` command to check the status of the servers:
2015-03-16 18:37:33 +03:00
![](http://i.imgur.com/eqL8FiZ.png)
2019-10-28 23:34:38 +03:00
To avoid wasting computer resources while not working on FxA make sure to stop the servers using `npm stop` .
2020-02-06 21:09:30 +03:00
Once you are back working on FxA just use the `npm start` command to bring the servers back up.
2015-03-16 18:37:33 +03:00
2016-03-16 01:32:40 +03:00
#### Verifying email and viewing logs
2016-07-21 22:20:37 +03:00
Use the `./pm2 logs` command to get the logs of all servers. You may also use `./pm2 logs [id]` to just see the logs for that particular server.
2016-03-16 01:32:40 +03:00
2020-04-14 23:37:11 +03:00
When you signup for an account using the form on `localhost:3030/signup` the "inbox" logs will print out the verification code that you need to copy paste into your browser to verify your account locally:
2015-03-16 18:37:33 +03:00
2019-12-25 00:14:45 +03:00
![](https://i.imgur.com/cdh9Xrl.png)
2015-03-16 18:37:33 +03:00
2020-03-10 19:05:01 +03:00
If you get an `error` status for any of the servers please verify that you installed all required dependencies. Otherwise file an issue on this repository or [connect with the team on Firefox Accounts Riot ](https://chat.mozilla.org/#/room/#fxa:mozilla.org ).
2014-12-30 08:57:38 +03:00
2020-05-15 03:48:39 +03:00
### Managing dependencies
Use `yarn` to add dependencies. To add a dependency to a single package, which is what you'll usually want, run something like:
```sh
yarn workspace fxa-shared add --dev eslint
```
For multiple packages use [workspaces foreach ](https://yarnpkg.com/cli/workspaces/foreach ).
To update dependencies use [yarn up ](https://yarnpkg.com/cli/up ) or `yarn workspace <name> up` .
2019-07-01 22:56:34 +03:00
---
---
---
2014-11-05 04:38:23 +03:00
2015-05-08 23:19:01 +03:00
### Dependencies
2019-07-01 22:56:34 +03:00
2017-01-25 19:34:24 +03:00
> Required developer dependencies:
2019-07-01 22:56:34 +03:00
> [Git](http://git-scm.com/book/en/v2/Getting-Started-Installing-Git),
2019-12-19 19:59:20 +03:00
> [node.js **12+** with npm 6](http://nodejs.org/),
2019-07-01 22:56:34 +03:00
> [Python 2.6+](https://www.python.org/),
> [Java 8+](https://www.java.com/en/download/),
> [Rust nightly+](https://doc.rust-lang.org/1.5.0/book/nightly-rust.html),
> [libgmp](https://gmplib.org/),
> [graphicsmagick](http://www.graphicsmagick.org/),
> [docker](https://docs.docker.com/),
2020-05-15 03:48:39 +03:00
> [gcloud CLI](https://cloud.google.com/sdk/) > [Yarn 2](https://yarnpkg.com)
2014-11-05 04:38:23 +03:00
2015-06-30 19:31:59 +03:00
##### OS X (with [Brew](http://brew.sh/)):
2015-06-30 02:24:22 +03:00
[Xcode and OS X Command Line Tools are required ](https://developer.apple.com/xcode/ ), install it and verify that command line tools installed:
2019-07-01 22:56:34 +03:00
2015-06-30 02:24:22 +03:00
```
xcode-select --install
```
2019-07-01 22:56:34 +03:00
2015-06-30 02:24:22 +03:00
then:
2019-07-01 22:56:34 +03:00
2015-05-25 01:24:17 +03:00
```
sudo easy_install pip & & sudo pip install virtualenv
```
2019-07-01 22:56:34 +03:00
2018-08-21 20:39:44 +03:00
[Install Docker for Mac ](https://download.docker.com/mac/stable/Docker.dmg ) | [Docs ](https://docs.docker.com/docker-for-mac/install/ )
2014-11-05 04:38:23 +03:00
2015-06-30 19:31:59 +03:00
##### Ubuntu:
2019-07-01 22:56:34 +03:00
2015-04-22 16:54:12 +03:00
```
2019-07-01 22:56:34 +03:00
sudo apt-get install build-essential git libgmp3-dev graphicsmagick python-virtualenv python-dev pkg-config libssl-dev curl openjdk-11-jre firefox
2015-04-22 16:54:12 +03:00
```
2019-07-01 22:56:34 +03:00
Follow the [Docker CE instructions to install Docker ](https://docs.docker.com/install/linux/docker-ce/ubuntu/ ).
2019-03-30 04:22:03 +03:00
Docker commands require sudo, to avoid it, follow steps below:
2019-07-01 22:56:34 +03:00
2018-04-11 20:05:37 +03:00
1. Add the docker group if it doesn't already exist
2019-07-01 22:56:34 +03:00
2018-04-11 20:05:37 +03:00
```
sudo groupadd docker
```
2019-07-01 22:56:34 +03:00
2. Add the connected user \$USER to the docker group
2018-04-11 20:05:37 +03:00
```
sudo gpasswd -a $USER docker
```
2019-07-01 22:56:34 +03:00
2018-04-11 20:05:37 +03:00
3. Restart the docker daemon
2019-07-01 22:56:34 +03:00
2018-04-11 20:05:37 +03:00
```
sudo service docker restart
```
2019-07-01 22:56:34 +03:00
2015-05-22 20:19:12 +03:00
#### Installing Node.js
2019-07-01 22:56:34 +03:00
2019-12-19 19:59:20 +03:00
We currently use Node 12.
2019-03-30 04:22:03 +03:00
See https://nodejs.org
2016-03-13 16:43:58 +03:00
2019-05-20 17:27:16 +03:00
Alternatively, the [Node Version Manager ](https://github.com/nvm-sh/nvm ) makes working with different versions of Node easy.
```
2019-12-19 19:59:20 +03:00
nvm install 12
nvm alias default 12
2019-05-20 17:27:16 +03:00
```
2015-05-28 05:21:29 +03:00
#### Installing Java
2017-01-25 19:34:24 +03:00
> Java is used to run Selenium functional tests
2015-06-30 19:31:59 +03:00
##### OS X:
2015-05-28 05:21:29 +03:00
Download from [java.com/en/download/ ](https://www.java.com/en/download/ )
2019-06-24 14:58:00 +03:00
#### Installing Rust
> Rust Nightly is used for the fxa-email-service
2019-07-09 18:45:28 +03:00
##### Ubuntu and OS X
2019-06-24 14:58:00 +03:00
```
curl https://sh.rustup.rs -sSf | sh
```
Once the installer begins:
2019-07-01 22:56:34 +03:00
2019-06-24 14:58:00 +03:00
1. Select "2) Customize installation"
2. Leave "Default host triple" blank, hit "enter"
3. Type "nightly" for "Default toolchain"
4. Type "y" for "Modify PATH variable?"
5. Select "1) Proceed with installation"
2019-07-01 22:56:34 +03:00
---
2016-03-24 22:36:55 +03:00
2020-03-18 19:26:54 +03:00
### Secrets
When developing locally you may need to set up some secrets in order to effectively work with certain servers. These secrets are managed at the package level.
Check out the Secrets section in the following READMEs:
- [fxa-auth-server ](https://github.com/mozilla/fxa/tree/master/packages/fxa-auth-server#secrets )
- [fxa-payments-server ](https://github.com/mozilla/fxa/tree/master/packages/fxa-payments-server#secrets )
---
2020-05-06 04:56:47 +03:00
### Testing
2016-03-24 22:36:55 +03:00
2020-05-06 04:56:47 +03:00
ℹ ️ While it is possible to run the entire code base's test suite, in development you'll likely want to run specific test or a subset of tests. Please refer to [each package's README ](#documentation ) for detailed instructions on testing its respective code.
2016-03-24 22:36:55 +03:00
2020-05-06 04:56:47 +03:00
#### Test all or some packages
2016-03-24 22:36:55 +03:00
2020-05-06 04:56:47 +03:00
From the root directory you may test all or some FxA packages:
2016-03-24 22:36:55 +03:00
2020-05-06 04:56:47 +03:00
```bash
# Test only `fxa-shared`
npm test fxa-shared
2016-03-24 22:36:55 +03:00
2020-05-06 04:56:47 +03:00
# Test `fxa-auth-db-mysql` and `fxa-auth-server`
npm test fxa-auth-db-mysql fxa-auth-server
2016-03-24 22:36:55 +03:00
2020-05-06 04:56:47 +03:00
# Test all packages
npm test all
```
2020-04-10 21:33:30 +03:00
2020-05-06 04:56:47 +03:00
Note that this invokes the same test suite that CI uses, and is not necessarily the same as running `npm test` in any given package.
2019-07-09 18:45:28 +03:00
2020-05-06 04:56:47 +03:00
#### Emulating CI environment
2016-03-24 22:36:55 +03:00
2020-05-06 04:56:47 +03:00
It is possible to run various test suites (known as Jobs) acting as Circle CI. This is useful if you're encountering CI-specific failures. Please refer to [this documentation ](https://github.com/mozilla/fxa/tree/master/.circleci#local-testing ).
2019-07-09 18:45:28 +03:00
2020-05-06 04:56:47 +03:00
---
### Firefox Custom Profile
**Use `npm start firefox` to start Firefox with local server configurations.**
Available options:
2016-03-24 22:36:55 +03:00
2020-05-06 04:56:47 +03:00
- `FXA_ENV=local` or `latest` or `stable` or `stage` (NOTE: `local` is default).
- `FXA_E10S=true` - add this flag to turn on E10S. (NOTE: `false` by default).
- `FXA_DESKTOP_CONTEXT` - `context=` value. (NOTE: `fx_desktop_v2` is default).
- `FIREFOX_BIN=/Applications/FirefoxNightly.app/Contents/MacOS/firefox-bin npm start`
- `FIREFOX_DEBUGGER=true` - open [Browser Toolbox ](https://developer.mozilla.org/en-US/docs/Tools/Browser_Toolbox ) on start (NOTE: `false` by default for speed).
2020-04-01 21:00:42 +03:00
2020-04-10 21:33:30 +03:00
---
2016-09-28 01:52:39 +03:00
2019-11-06 02:53:38 +03:00
### Node debugging
It's possible to debug a running node process using a variety of debuggers (see the [node debugging docs ](https://nodejs.org/en/docs/guides/debugging-getting-started/ ) for details).
2020-03-06 04:42:18 +03:00
We have also extensively documented working with the [FxA code-base using VS Code ](https://mozilla.github.io/ecosystem-platform/docs/fxa-engineering/vscode-development ).
2019-11-06 02:53:38 +03:00
#### Debugging a server
2020-04-13 02:54:49 +03:00
`npm start` runs some of the services with the debugger enabled by default.
2019-11-06 02:53:38 +03:00
1. Start the whole server as usual (`npm install && npm start` from top-level in the monorepo)
2020-04-13 02:54:49 +03:00
2. To see which debug port each service is listening on check `.vscode/launch.json` or the `pm2.config.js` file of the package you're interested in.
3. Connect to the process to debug it:
2019-11-06 02:53:38 +03:00
- Using Google Chrome, go to `chrome://inspect` , then click the process to connect to devtools.
2020-04-13 02:54:49 +03:00
- you may need to add a new target in the "Configure..." menu with the correct debug port
2019-11-06 02:53:38 +03:00
- VSCode requires setting up a `.vscode/launch.json` file; see the [VSCode docs ](https://code.visualstudio.com/docs/nodejs/nodejs-debugging ) for details.
2020-03-06 04:42:18 +03:00
##### Default Debug Ports
2020-04-13 02:54:49 +03:00
If you're using `npm start` , the following ports are used for `--inspect` :
2020-03-06 04:42:18 +03:00
| Port | Service |
| ---- | --------------- |
2020-04-13 02:54:49 +03:00
| 9130 | content-server |
| 9140 | admin-panel |
2020-03-06 04:42:18 +03:00
| 9150 | admin-server |
| 9160 | auth-server |
| 9170 | payments-server |
| 9180 | event-broker |
2020-04-29 20:22:20 +03:00
| 9190 | support-panel |
| 9200 | graphql-api |
2020-03-06 04:42:18 +03:00
2019-11-06 02:53:38 +03:00
#### Debugging tests
The node debugger can also be attached to a running test process. Firefox Accounts uses a variety of test frameworks, so the steps vary for the different servers. The `--inspect` argument is used in the examples below, but `--inspect-brk` can also be used to pause the process as soon as it starts.
##### mocha tests (fxa-shared)
For mocha, pass the `--timeout 0` option, otherwise the test will fail if you step through it and exceed the default timeout (currently 2 seconds on `fxa-shared` ):
`node --inspect ./node_modules/.bin/mocha --timeout 0 path/to/file`
In `fxa-shared` , this incantation works for some directories, but not yet others.
##### jest tests (fxa-payments-server)
For jest, pass the `--runInBand` argument, so it doesn't fork off the test runner to a separate process that isn't available to the inspector:
`node --inspect ./node_modules/.bin/jest --runInBand --config server/jest.config.js filematcher`
where `filematcher` is a regex that matches against test file paths. If you omit `filematcher` , Jest will run all tests (but you have to hit Enter a second time to trigger the test run).
---
2019-01-14 22:02:59 +03:00
### Android debugging
2020-03-12 23:52:09 +03:00
The following technique works with any Android application and can also be used for Firefox for Android.
2019-01-14 22:02:59 +03:00
Simply forward the following ports from the host machine to the Android device:
2019-07-01 22:56:34 +03:00
2020-03-12 23:52:09 +03:00
```
npm run adb-reverse
```
or
2019-01-14 22:02:59 +03:00
```
adb reverse tcp:3030 tcp:3030 # Content server
adb reverse tcp:9000 tcp:9000 # Auth server
adb reverse tcp:9010 tcp:9010 # OAuth server
adb reverse tcp:1111 tcp:1111 # Profile server
adb reverse tcp:5000 tcp:5000 # Sync server
```
2019-10-28 23:34:38 +03:00
Then run `npm start` and get to work!
2019-01-14 22:02:59 +03:00
2019-07-01 22:56:34 +03:00
---
2019-01-14 22:02:59 +03:00
2019-10-02 17:01:40 +03:00
### FxA Email Service
> Skip this if you are not working on the [fxa-email-service](packages/fxa-email-service).
The pm2 scripts run the `latest` docker version of the email service by default. If you want to
start making changes to the email service then do the following:
1. Stop the email-service using `./pm2 stop <email_service_id>`
2019-10-28 23:34:38 +03:00
1. Build the service: `cd packages/fxa-email-service; cargo build --bin fxa_email_send`
2019-10-02 17:01:40 +03:00
1. Run the service: `cd packages/fxa-email-service; ./scripts/run_send.sh`
2019-07-01 22:56:34 +03:00
---
2015-10-20 23:48:59 +03:00
### Firefox for iOS
2016-02-17 08:40:00 +03:00
> Skip this if you are not working on Firefox for iOS and FxA.
2015-10-20 23:48:59 +03:00
You can test sync locally in Firefox iOS using the XCode simulator.
2019-07-01 22:56:34 +03:00
[Follow the steps at github.com/mozilla/firefox-ios and setup _firefox-ios_ ](https://github.com/mozilla/firefox-ios ) build locally.
2015-10-20 23:48:59 +03:00
Currently there is no way to dynamically switch servers in Firefox for iOS, to use **local** servers you need to run the script below:
```
FIREFOX_IOS_HOME=< path_to_firefox_ios_project > npm run config-fxios
```
2019-07-01 22:56:34 +03:00
After the script you need to rebuild _firefox-ios_ .
2015-12-22 22:29:51 +03:00
2019-07-01 22:56:34 +03:00
---
2015-12-22 22:29:51 +03:00
2016-07-21 22:20:37 +03:00
### Running with MailDev
2019-03-30 04:22:03 +03:00
If you want to inspect emails, you can run fxa with [MailDev ](https://www.npmjs.com/package/maildev ).
2016-07-21 22:20:37 +03:00
#### Install
2019-07-01 22:56:34 +03:00
2016-07-21 22:20:37 +03:00
```bash
npm install maildev -g
```
#### Run
2019-07-01 22:56:34 +03:00
2016-07-21 22:20:37 +03:00
```bash
2019-10-28 23:34:38 +03:00
npm start
2020-04-10 21:33:30 +03:00
./pm2 stop inbox
2016-07-21 22:20:37 +03:00
```
Once services have started, you can start MailDev on port 9999. You might have to start MailDev with sudo permissions.
```bash
sudo maildev -s 9999
```
2019-07-15 18:51:43 +03:00
All emails sent can be viewed from [http://localhost:1080 ](http://localhost:1080 ).
2016-07-25 22:14:18 +03:00
2019-07-01 22:56:34 +03:00
---
2016-07-25 22:14:18 +03:00
2020-03-10 19:05:01 +03:00
### Documentation
The [Firefox Ecosystem Platform ](https://mozilla.github.io/ecosystem-platform/ ) serves as a documentation hub for Firefox Accounts, Services, Synced Client Integrations, and Subscription Platform.
2019-10-29 22:00:52 +03:00
2020-03-10 19:05:01 +03:00
In addition to the ecosystem docs, each package has it's own README.md and `docs/` directory with info specific to that project.
2019-10-29 22:00:52 +03:00
- 123done [README ](./packages/123done/README.md )
- browserid-verifier [README ](./packages/browserid-verifier/README.md )
- fortress [README ](./packages/fortress/README.md )
- fxa-auth-db-mysql [README ](./packages/fxa-auth-db-mysql/README.md ) / [docs/ ](./packages/fxa-auth-db-mysql/docs )
- fxa-auth-server [README ](./packages/fxa-auth-server/README.md ) / [docs/ ](./packages/fxa-auth-server/docs )
- fxa-content-server [README ](./packages/fxa-content-server/README.md ) / [docs/ ](./packages/fxa-content-server/docs )
- fxa-email-event-proxy [README ](./packages/fxa-email-event-proxy/README.md )
- fxa-email-service [README ](./packages/fxa-email-service/README.md ) / [docs/ ](./packages/fxa-email-service/docs )
- fxa-event-broker [README ](./packages/fxa-event-broker/README.md ) / [docs/ ](./packages/fxa-event-broker/docs )
- fxa-geodb [README ](./packages/fxa-geodb/README.md )
- fxa-js-client [README ](./packages/fxa-js-client/README.md )
- fxa-payments-server [README ](./packages/fxa-payments-server/README.md )
- fxa-profile-server [README ](./packages/fxa-profile-server/README.md ) / [docs/ ](./packages/fxa-profile-server/docs )
- fxa-shared [README ](./packages/fxa-shared/README.md )
- fxa-support-panel [README ](./packages/fxa-support-panel/README.md )