Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3042: Refactor client applications into a monorepo with turborepo, extract fides-js into a standalone package, and improve privacy-center to load configuration at runtime #3105

Merged
merged 78 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from 70 commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
03001ab
initial integration with turborepo
eastandwestwind Apr 7, 2023
d1e611b
hoist fides consent as shared package
eastandwestwind Apr 9, 2023
7a2d12c
updates github and docker workflows to use turbo
eastandwestwind Apr 10, 2023
ef31735
progress on dockerfile, still failing
eastandwestwind Apr 10, 2023
bdbe958
adds turbo globally in clients
eastandwestwind Apr 13, 2023
bd7a906
adjust rollup config
eastandwestwind Apr 14, 2023
0d70867
package-lock
eastandwestwind Apr 14, 2023
624f83e
moves pc into same docker container as base fides image, when in dev …
eastandwestwind Apr 19, 2023
46d6f9f
fix some bugs with running test env
eastandwestwind Apr 19, 2023
6e7a4af
Gets pc running using test env. PC config is currently not being boun…
eastandwestwind Apr 19, 2023
ad8250c
cleanup and docs clarification
eastandwestwind Apr 20, 2023
b0389b6
add back user for security in PC docker, adjust dockerignore
eastandwestwind Apr 20, 2023
e51c624
remove unneeded dockerfile in PC
eastandwestwind Apr 20, 2023
5d2ae82
eliminate extra spaces in github workflow
eastandwestwind Apr 20, 2023
2907291
move cypress config up a level, fix lint issue with PC
eastandwestwind Apr 20, 2023
6a049d6
turn off unsafe-to-chain-command rule for eslint
eastandwestwind Apr 20, 2023
d956bf6
disable cypress/unsafe-to-chain-command across admin-ui and pc
eastandwestwind Apr 20, 2023
e7e4035
split out pc vs admin-ui cypress
eastandwestwind Apr 20, 2023
4f79763
remove unneeded cypress config file, remove ability to call cypress g…
eastandwestwind Apr 20, 2023
889da9f
remove other cy commands from root package.json
eastandwestwind Apr 20, 2023
991f9e2
cleanup, remove package-lock.json from within each workspace, turbo i…
eastandwestwind Apr 21, 2023
5b0f1f2
rename export-ui to export-admin-ui
eastandwestwind Apr 21, 2023
405e957
remove fides-consent build from getting copied into root fides
eastandwestwind Apr 21, 2023
399a679
remove unneeded turbo commands, adds README to clients, minor naming …
eastandwestwind Apr 21, 2023
7bcdc86
fixes cypress upload on failure, adds specific step for both admin-ui…
eastandwestwind Apr 21, 2023
ac78106
remove unneeded files
eastandwestwind Apr 22, 2023
f4ed02d
Refactor `fides-consent ` and `privacy-center` to support loading con…
NevilleS Apr 25, 2023
ae21bfe
Add a few more TODOs, for my notes
NevilleS Apr 25, 2023
fb8d12f
Fix naming of fides.global.js -> fides.js
NevilleS Apr 25, 2023
7569d62
Remove duplicate test page in fides-js package
NevilleS Apr 25, 2023
eea9bde
Fix frontend_checks.yml
NevilleS Apr 25, 2023
fe45154
Add file-level docs comment to fides.ts and adjust _Fides var scoping
NevilleS Apr 25, 2023
5775971
Fix lint errors
NevilleS Apr 25, 2023
b0c2b24
Format with prettier
NevilleS Apr 26, 2023
31f0f7a
Get privacy center cypress tests building (but failing)
NevilleS Apr 26, 2023
50d5a6a
Fix privacy-center Docker build
NevilleS Apr 26, 2023
cb16c6a
Update Cypress CI workflows for admin-ui and privacy-center
NevilleS Apr 26, 2023
eede348
Add npm build to Cypress CI
NevilleS Apr 26, 2023
bfed8ac
Tidy up unnecessary jest hacks
NevilleS Apr 26, 2023
1d62386
Update typescript-cookie
NevilleS Apr 26, 2023
18eaa63
Add placeholder jest suite to fides-js
NevilleS Apr 26, 2023
4724da6
Merge branch 'main' of github.com:ethyca/fides into 771-turborepo-poc
NevilleS Apr 29, 2023
f189cd2
Finish merging in main and cleanup fides-js & sample-app projects a bit
NevilleS Apr 30, 2023
cae0933
Add cypress-e2e to turborepo
NevilleS Apr 30, 2023
4b03b79
Remove cypress-e2e and sample-app from turborepo (for now)
NevilleS Apr 30, 2023
fdf22aa
Fix sample-app build
NevilleS Apr 30, 2023
c7767dd
Add Cypress.loadConfigFixture that dynamically loads privacy center c…
NevilleS Apr 30, 2023
6f9989e
Fix privacy center cypress tests to use loadConfigFixture
NevilleS Apr 30, 2023
34a087e
Add details unit tests for lib/cookie
NevilleS Apr 30, 2023
b58915b
Format & lint
NevilleS Apr 30, 2023
aabe0fa
Continue linting & cleaning up
NevilleS Apr 30, 2023
a86fecc
Fix formatting
NevilleS Apr 30, 2023
3242ebf
Fix admin-ui cy:start to run a test build to disable proxy rewrites
NevilleS Apr 30, 2023
84c92e7
Try to run client unit & cypress tests in parallel per package
NevilleS Apr 30, 2023
4b62776
Fix workflow syntax
NevilleS Apr 30, 2023
a3f91ae
Add test:ci script to fides-js
NevilleS Apr 30, 2023
361d1d1
Add explicit jest-environment-jsdom to fides-js package
NevilleS Apr 30, 2023
b13c30a
Change jsDom -> jsdom... hope that works in CI
NevilleS Apr 30, 2023
faab9e7
Fix typo in dockerignore
NevilleS May 1, 2023
3dfe42f
Merge branch 'main' of github.com:ethyca/fides into 771-turborepo-poc
NevilleS May 3, 2023
73f7126
Copy rollup.config.js back from main
NevilleS May 3, 2023
b9b931d
Use rollup to bundle fides.js instead
NevilleS May 3, 2023
afbfbef
Remove tsup dependency
NevilleS May 3, 2023
3137010
Attempt to target es5 again using rollup
NevilleS May 3, 2023
10ca455
Explicitly target es2015, remove tsup entirely
NevilleS May 3, 2023
b551303
Fail fides-js build if the bundle size becomes too large
NevilleS May 3, 2023
f7c750e
Fix log for bundle size check
NevilleS May 3, 2023
7c0962e
remove unneeded build dependencies in turbo pipelines
eastandwestwind May 3, 2023
3fbe2c4
removing some todos and unneeded code, adding comments
eastandwestwind May 3, 2023
cc0d6de
pull latest main, fix conflicts
eastandwestwind May 3, 2023
2212575
Add a .prettierignore file to sample app (so I don't forget)
NevilleS May 3, 2023
6b295f8
Run prettier on fides-js files
NevilleS May 3, 2023
12788ea
Remove TODO, link to a follow-up issue
NevilleS May 3, 2023
e1961db
Update additional TODOs for follow-up work on this
NevilleS May 3, 2023
c41e7b6
Final (?) linting and formatting
NevilleS May 3, 2023
603629d
Fix some lint & build warnings
NevilleS May 3, 2023
0c1bb27
Fix volume mounts for `nox -s dev -- ui pc`
NevilleS May 4, 2023
9149f2f
Update turbo dev & test pipelines to be "persistent" and depend on "^…
NevilleS May 4, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ src/ui-build/
# Frontend
**/node_modules
**/.next

**/.eslintrc.json
**/.jest.config.js
**/jest.config.jest
**/.prettierignore
**/.prettierrc.json
**/__tests__
**/npm-debug.log
**/*__mocks__

# Ignore Python-Specific Files
**/.mypy_cache/
Expand Down Expand Up @@ -38,6 +45,7 @@ src/ui-build/
# docs/

# Ignore dev files
.gitignore
.github/
.devcontainer/

Expand Down
88 changes: 33 additions & 55 deletions .github/workflows/frontend_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@ env:
CI: true

jobs:
Admin-UI-Unit:
Clients-Unit:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
clients:
- "admin-ui"
- "privacy-center"
- "fides-js"
defaults:
run:
working-directory: clients/admin-ui
working-directory: clients
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -39,17 +43,24 @@ jobs:
- name: Format
run: npm run format:ci

- name: Jest test
run: npm run test:ci

- name: Build
run: npm run build

Admin-UI-Cypress:
- name: Unit test (${{ matrix.clients }})
working-directory: clients/${{ matrix.clients }}
run: npm run test:ci

Clients-Cypress:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
clients:
- "admin-ui"
- "privacy-center"
defaults:
run:
working-directory: clients
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -60,14 +71,15 @@ jobs:
node-version: ${{ matrix.node-version }}

- name: Install dependencies
run: |
cd clients/admin-ui
npm install
run: npm install

- name: Cypress E2E tests
- name: Build
run: npm run build

- name: Cypress E2E Tests (${{ matrix.clients }})
uses: cypress-io/github-action@v4
with:
working-directory: clients/admin-ui
working-directory: clients/${{ matrix.clients }}
install: false
start: npm run cy:start
wait-on: "http://localhost:3000"
Expand All @@ -76,24 +88,19 @@ jobs:
- uses: actions/upload-artifact@v3
if: failure()
with:
name: cypress-videos
path: /home/runner/work/fides/fides/clients/admin-ui/cypress/videos/*.mp4
name: cypress-videos-${{ matrix.clients }}
path: /home/runner/work/fides/fides/clients/${{ matrix.clients }}/cypress/videos/*.mp4

- name: Cypress component tests
uses: cypress-io/github-action@v4
with:
working-directory: clients/admin-ui
install: false
component: true

Privacy-Center-Unit:
Clients-Cypress-Component:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
clients:
- "admin-ui"
defaults:
run:
working-directory: clients/privacy-center
working-directory: clients
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -106,42 +113,13 @@ jobs:
- name: Install dependencies
run: npm install

- name: Lint
run: npm run lint

- name: Format
run: npm run format:ci

- name: Build
run: npm run build

- name: Jest test
run: npm run test:ci

Privacy-Center-Cypress:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies
run: |
cd clients/privacy-center
npm install

- name: Cypress E2E tests
- name: Cypress Component Tests (${{ matrix.clients }})
uses: cypress-io/github-action@v4
with:
working-directory: clients/privacy-center
working-directory: clients/${{ matrix.clients }}
install: false
start: npm run cy:start
wait-on: "http://localhost:3000"
wait-on-timeout: 120
component: true

6 changes: 3 additions & 3 deletions .github/workflows/publish_package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ jobs:

- name: Install node modules
run: |
cd clients/admin-ui
cd clients
npm install

- name: Build and export frontend files
run: |
cd clients/admin-ui
npm run prod-export
cd clients
npm run prod-export-admin-ui

- name: Install Twine and wheel
run: pip install twine wheel
Expand Down
47 changes: 39 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,54 @@ RUN pip install -e . --no-deps
###################
## Frontend Base ##
###################
FROM node:16-slim as frontend
FROM node:16-alpine as frontend

RUN apk add --no-cache libc6-compat
# Build the frontend clients
WORKDIR /fides/clients
COPY clients/package.json clients/package-lock.json ./
COPY clients/fides-js/package.json ./fides-js/package.json
COPY clients/admin-ui/package.json ./admin-ui/package.json
COPY clients/privacy-center/package.json ./privacy-center/package.json

# Build the admin-ui frontend
WORKDIR /fides/clients/admin-ui
COPY clients/admin-ui/package.json clients/admin-ui/package-lock.json ./
RUN npm install
COPY clients/admin-ui/ .

COPY clients/ .

####################
## Built frontend ##
####################
FROM frontend as built_frontend
RUN npm run export

#############################
# Builds and exports admin-ui
RUN npm run export-admin-ui
# Builds privacy-center
RUN npm run build-privacy-center

###############################
## Production Privacy Center ##
###############################
FROM node:16-alpine as prod_pc

WORKDIR /fides/clients

ENV NODE_ENV production
ENV NEXT_TELEMETRY_DISABLED 1

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
USER nextjs

COPY --from=built_frontend --chown=nextjs:nodejs /fides/clients .
WORKDIR /fides/clients/privacy-center

EXPOSE 3000

CMD ["npm", "run", "start"]

############################
## Production Application ##
#############################
############################
FROM backend as prod

# Copy frontend build over
Expand Down
1 change: 1 addition & 0 deletions clients/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.turbo
51 changes: 51 additions & 0 deletions clients/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Clients

The clients directory houses all front-end packages and shared code amongst clients, and also includes e2e tests.

## Prerequisites

Dependencies within this directory are managed by Turborepo. Our root `package.json` file defines 3 workspaces (or packages) that are part of the Turbo ecosystem:
1. admin-ui
2. privacy-center
3. fides-js

To run any or all workspaces, you'll have to complete the following setup:

1. Install Turborepo globally so that you can use it on the command line `npm install turbo --global`
2. In `clients` folder, run `npm install`. This will install the dev dependency `turbo`. This will also install the appropriate dependencies in `clients` and in each client within `clients` folder. You may need to first remove all `node_modules` in each of the clients (admin-ui, privacy-center, etc)

## Running Locally

To run the project use `turbo` instead of `npm`.

Incorrect:
```
npm run dev
```

Correct:
```
turbo run dev
```

Running this in the root `clients` folder will result in every workspace being run.

Running this command within `admin-ui` will result in only admin-ui being run.

Available commands that exist for every workspace are defined in the root `turbo.json` file, while commands unique to a specific workspace are defined in the `turbo.json` file within the workspace.

It's important to use the turbo command because, as you see in the `turbo.json` files, we've defined some dependencies and caching details on some turbo commands.



## Adding packages

To install packages in any package in `clients`, run the following from `clients`:
```
npm install <package> --workspace=<workspace>
```
Example:
```
npm install react --workspace=admin-ui
```
See https://turbo.build/repo/docs/handbook/package-installation#addingremovingupgrading-packages for more details
12 changes: 6 additions & 6 deletions clients/admin-ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Admin UI for managing Fides privacy requests. A web application built in Next.js

## Running Locally

1. In a new shell, `cd` into `clients/admin-ui`, then run `npm run dev`.
1. In a new shell, `cd` into `clients/admin-ui`, then run `turbo run dev`.
1. Nav to `http://localhost:3000/` and log in using the created user. The `email` field is simply the `user` that was created, not a valid email address.

## Unit test locations
Expand All @@ -25,16 +25,16 @@ of the page header. These changes will be saved per-browser, per-environment, un

Feature flags can be configured independently for the development, test, and production environments:

- **development** - Running `npm run dev` uses the development environment. This will include bleeding-edge features.
- **test** - Cypress runs in the tet environment via `npm run cy:start`. This will usually match production, but
- **development** - Running `turbo run dev` uses the development environment. This will include bleeding-edge features.
- **test** - Cypress runs in the tet environment via `turbo run cy:start`. This will usually match production, but
new features may be enabled in test to verify them in CI before release.
- **production** - Only features ready for release will be enabled for production. `npm run build` always produces a
- **production** - Only features ready for release will be enabled for production. `turbo run build` always produces a
build configured for production, which is then bundled into the Fides server.

You can switch between these environments manually by overriding the `NEXT_PUBLIC_APP_ENV` environment variable when
running the app, for example:

`NEXT_PUBLIC_APP_ENV=production npm run dev`
`NEXT_PUBLIC_APP_ENV=production turbo run dev`

Or you can configure the environment using `env.local` as described by the [Next.js docs](https://nextjs.org/docs/basic-features/environment-variables#loading-environment-variables).

Expand All @@ -44,7 +44,7 @@ In addition, you can mark a flag as `userCannotModify: true` in `flags.json`. Th

To view a production version of this site, including the backend:

1. Run `npm prod-export`. This will
1. Run `turbo prod-export`. This will
1. Export the static site to `out/`
1. Copy the build from `out/` to the folder in the backend which will serve static assets at `/`
1. Run `nox -s api` in the top-level `fides` directory.
Expand Down
26 changes: 13 additions & 13 deletions clients/admin-ui/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
import { defineConfig } from "cypress";

export default defineConfig({
e2e: {
baseUrl: "http://localhost:3000",
},
e2e: {
baseUrl: "http://localhost:3000",
},

defaultCommandTimeout: 5000,
defaultCommandTimeout: 5000,

retries: {
runMode: 3,
openMode: 0,
},
retries: {
runMode: 3,
openMode: 0,
},

component: {
devServer: {
framework: "next",
bundler: "webpack",
component: {
devServer: {
framework: "next",
bundler: "webpack",
},
},
},
});
5 changes: 3 additions & 2 deletions clients/admin-ui/cypress/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"extends": ["plugin:cypress/recommended"],
"plugins": ["no-only-tests"],
"plugins": ["no-only-tests", "cypress"],
"parserOptions": {
"project": "./tsconfig.json",
"tsconfigRootDir": "cypress"
},
"rules": {
"no-only-tests/no-only-tests": "error"
"no-only-tests/no-only-tests": "error",
"cypress/unsafe-to-chain-command": "off"
}
}
Loading