Skip to content

Commit

Permalink
Add "Cookie House" sample app to fides deploy project 🍪 (#1609)
Browse files Browse the repository at this point in the history
* Update Postgres sample data for products & customers

* Reorganize test_env project data into src/fides/data for consistency

* Reorganize sample project privacy center config

* Add Cookie House privacy center styling

* Use SERIAL type in sample postgres db for ids

* Integrate working version of Cookie House sample app

* Make privacy center logo bigger and don't constraint width

* Finish setting up sample app

* Minor styling tweaks to match PC header

* Pin sample app node version

* Fix formatting on privacy center

* Update cookie house build for CI

* Temporarily disable analytics on fides deploy

* Fix gitignore for sample project

* Update sample project types & deps

* Update package-lock for sample_project

* Set default build args to satisfy next build

* Remove legacy root_user.analytics_opt_out value

* Fix integration tests

* Add link to sample privacy center in footer

* Build fides-sample-app during build(sample) and build(prod)
  • Loading branch information
NevilleS authored Oct 31, 2022
1 parent b879eda commit 297a14d
Show file tree
Hide file tree
Showing 49 changed files with 7,330 additions and 85 deletions.
8 changes: 1 addition & 7 deletions clients/privacy-center/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,7 @@ const Home: NextPage = () => {
justifyContent="center"
alignItems="center"
>
<Image
src={config.logo_path}
margin="8px"
height="56px"
width="304px"
alt="Logo"
/>
<Image src={config.logo_path} margin="8px" height="68px" alt="Logo" />
</Flex>
</header>

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ services:
- "3001:3000"
volumes:
- type: bind
source: ./data/config/privacy_center_config
source: ./src/fides/data/test_env/privacy_center_config
target: /app/config
read_only: False

Expand Down
2 changes: 1 addition & 1 deletion docs/fides/docs/development/testing_environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ To facilitate thorough manual testing of the application, there is a comprehensi

## Configuration

The environment will configure the `fides` server and CLI using the TOML configuration set in `data/config/fides.test_env.toml`. To test out other configurations, you can edit this file and reload the test env; however, don't commit these changes unless you are sure that the default configuration for testing should change for everyone!
The environment will configure the `fides` server and CLI using the TOML configuration set in `src/fides/data/test_env/fides.test_env.toml`. To test out other configurations, you can edit this file and reload the test env; however, don't commit these changes unless you are sure that the default configuration for testing should change for everyone!

## Secrets Management

Expand Down
5 changes: 5 additions & 0 deletions noxfiles/constants_nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
IMAGE_SAMPLE = f"{IMAGE}:sample"
IMAGE_LATEST = f"{IMAGE}:latest"

# Image names for the secondary apps
PRIVACY_CENTER_IMAGE = f"{REGISTRY}/fides-privacy-center"
SAMPLE_APP_IMAGE = f"{REGISTRY}/fides-sample-app"


# Disable TTY to perserve output within Github Actions logs
# CI env variable is always set to true in Github Actions
# The else statement is required due to the way commmands are structured and is arbitrary.
Expand Down
2 changes: 1 addition & 1 deletion noxfiles/dev_nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_env(session: Session) -> None:

# Temporarily override some ENV vars as needed. To set local secrets, see 'example.env'
test_env_vars = {
"FIDES__CONFIG_PATH": "/fides/data/config/fides.test_env.toml",
"FIDES__CONFIG_PATH": "/fides/src/fides/data/test_env/fides.test_env.toml",
}

session.log(
Expand Down
38 changes: 35 additions & 3 deletions noxfiles/docker_nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
IMAGE_LOCAL,
IMAGE_LOCAL_UI,
IMAGE_SAMPLE,
PRIVACY_CENTER_IMAGE,
SAMPLE_APP_IMAGE,
)


Expand Down Expand Up @@ -83,17 +85,46 @@ def build(session: nox.Session, image: str, machine_type: str = "") -> None:
"admin_ui": {"tag": lambda: IMAGE_LOCAL_UI, "target": "frontend"},
}

if image == "sample":
# Build the privacy center here, but let the webserver image build later
# When building an image for release (either the "prod" or "sample"
# targets), ensure we also build the extra apps:
# ethyca/fides-privacy-center
# ethyca/fides-sample-app
#
# This is because these images aren't built via the regular build matrix,
# which is used to produce various tags of the main ethyca/fides image
#
# TODO: this is messy, and could be integrated alongside ethyca/fides
# instead
if image in ("sample", "prod"):
if image == "prod":
tag_name = get_current_tag()
if image == "sample":
tag_name = "sample"
privacy_center_image_tag = f"{PRIVACY_CENTER_IMAGE}:{tag_name}"
sample_app_image_tag = f"{SAMPLE_APP_IMAGE}:{tag_name}"

session.log("Building extra images:")
session.log(f" - {privacy_center_image_tag}")
session.log(f" - {sample_app_image_tag}")
session.run(
"docker",
"build",
"clients/privacy-center",
"--tag",
"ethyca/fides-privacy-center:sample",
privacy_center_image_tag,
external=True,
)
session.run(
"docker",
"build",
"src/fides/data/sample_project/cookie_house",
"--tag",
sample_app_image_tag,
external=True,
)

# Allow building the fides-privacy-center:local image directly when
# requested (for development purposes)
if image == "privacy_center":
session.run(
"docker",
Expand All @@ -104,6 +135,7 @@ def build(session: nox.Session, image: str, machine_type: str = "") -> None:
external=True,
)
else:
# Build the main ethyca/fides image
target = build_matrix[image]["target"]
tag = build_matrix[image]["tag"]
build_command = (
Expand Down
20 changes: 17 additions & 3 deletions src/fides/ctl/core/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,44 +145,57 @@ def pull_specific_docker_image() -> None:

fides_image_stub = "ethyca/fides:{}"
privacy_center_image_stub = "ethyca/fides-privacy-center:{}"
sample_app_image_stub = "ethyca/fides-sample-app:{}"

current_fides_image = fides_image_stub.format(current_fides_version)
current_privacy_center_image = privacy_center_image_stub.format(
current_fides_version
)
current_sample_app_image = sample_app_image_stub.format(current_fides_version)

dev_fides_image = fides_image_stub.format("dev")
dev_privacy_center_image = privacy_center_image_stub.format("dev")
dev_sample_app_image = sample_app_image_stub.format("dev")

try:
echo("Attempting to pull:")
echo(f"- {current_fides_image}")
echo(f"- {current_privacy_center_image}")
echo(f"- {current_sample_app_image}")

run_shell(f"docker pull {current_fides_image}")
run_shell(f"docker pull {current_privacy_center_image}")
run_shell(f"docker pull {current_sample_app_image}")
run_shell(
f"docker tag {current_fides_image} {fides_image_stub.format('sample')}"
)
run_shell(
f"docker tag {current_privacy_center_image} {privacy_center_image_stub.format('sample')}"
)
run_shell(
f"docker tag {current_sample_app_image} {sample_app_image_stub.format('sample')}"
)
except CalledProcessError:
echo_red("Unable to fetch matching version, defaulting to 'dev' versions...")

try:
echo("Attempting to pull:")
echo(f"- {dev_fides_image}")
echo(f"- {dev_privacy_center_image}")
echo(f"- {dev_sample_app_image}")

run_shell(f"docker pull {dev_fides_image}")
run_shell(f"docker pull {dev_privacy_center_image}")
run_shell(f"docker pull {dev_sample_app_image}")
run_shell(
f"docker tag {dev_fides_image} {fides_image_stub.format('sample')}"
)
run_shell(
f"docker tag {dev_privacy_center_image} {privacy_center_image_stub.format('sample')}"
)
run_shell(
f"docker tag {dev_sample_app_image} {sample_app_image_stub.format('sample')}"
)
except CalledProcessError:
echo_red("Failed to pull 'dev' versions of docker containers! Aborting...")
raise SystemExit(1)
Expand All @@ -205,11 +218,12 @@ def print_deploy_success() -> None:
echo_green("\n- Visit the Fides Admin UI running at http://localhost:8080")
echo_green(" (user=fidestest, password=Apassword1!)")

# Privacy Center
echo_green("\n- Visit the Fides Privacy Center running at http://localhost:3000")
# Sample App
echo_green("\n- Sample 'Cookie House' Application running at http://localhost:3000")
echo_green("\n- Sample Privacy Center running at http://localhost:3001")
echo_green(" (user=jane@example.com)")

# Example Datastores
# Example Databases
echo_green("\n- Example Postgres Database running at localhost:6432")
echo_green(" (user=postgres, password=postgres, db=postgres_example)")
echo_green("\n- Example Mongo Database running at localhost:37017")
Expand Down
7 changes: 7 additions & 0 deletions src/fides/data/sample_project/cookie_house/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Dockerfile
docker-compose.yml
.dockerignore
node_modules
npm-debug.log
.next
.git
19 changes: 19 additions & 0 deletions src/fides/data/sample_project/cookie_house/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
extends: [
'airbnb-typescript',
'airbnb/hooks',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
"next/core-web-vitals"
],
rules: {

},
parserOptions: {
ecmaVersion: 2022,
sourceType: 'module',
project: './tsconfig.json',
tsconfigRootDir: __dirname,
createDefaultProgram: true,
},
};
38 changes: 38 additions & 0 deletions src/fides/data/sample_project/cookie_house/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

!lib/

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
20 changes: 20 additions & 0 deletions src/fides/data/sample_project/cookie_house/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM node:16-alpine

ENV DATABASE_HOST localhost
ENV DATABASE_PORT 5432
ENV DATABASE_USER postgres
ENV DATABASE_PASSWORD postgres
ENV DATABASE_DB postgres_example

RUN mkdir /home/node/app
WORKDIR /home/node/app
COPY package.json package-lock.json ./
RUN npm clean-install
COPY . /home/node/app
RUN npm run build

EXPOSE 3000

ENV PORT 3000

CMD [ "npm", "run", "start" ]
7 changes: 7 additions & 0 deletions src/fides/data/sample_project/cookie_house/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
swcMinify: true,
}

module.exports = nextConfig
Loading

0 comments on commit 297a14d

Please sign in to comment.