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

synchronize dev from main branch #62

Merged
merged 27 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
cd14c92
[github] add PULL_REQUEST_TEMPLATE.md
JackJey Jul 13, 2023
922b972
[dsp] cleanup dsp
JackJey Jul 1, 2023
18df4f3
[ssp] cleanup ssp
JackJey Jul 1, 2023
9899704
[shop] update dependencies
JackJey Jul 1, 2023
97c17cb
[shop] enable ServerActions
JackJey Jul 1, 2023
e12c88f
[shop] migrate api
JackJey Jul 1, 2023
5879dd4
[shop] migrate lib
JackJey Jul 1, 2023
2dc4ada
[shop] migrate components
JackJey Jul 1, 2023
3e19ae6
[shop] use start on dockerfile
JackJey Jul 1, 2023
717466f
[shop] update next.js to v13.4.8
JackJey Jul 5, 2023
bcef6df
[shop] replace localhost to ip
JackJey Jul 5, 2023
727630e
[.env] update origin trial tokens
Seburan Jul 14, 2023
8dda7fb
[shop] update dependencies
JackJey Jul 14, 2023
f1828d6
[shop] update node 18 to 20
JackJey Jul 14, 2023
ba19674
[shop] fix build fail
JackJey Jul 14, 2023
6e09673
[shop] add ncu task for update dependencies
JackJey Jul 14, 2023
f71409d
[shop] update dependencies
JackJey Jul 14, 2023
1da10b4
Merge pull request #50 from privacysandbox/shop
Seburan Jul 14, 2023
d5ee3c8
Merge pull request #48 from Seburan/fix-ot-token
JackJey Jul 14, 2023
d617535
[shop] install server-only
JackJey Jul 14, 2023
6eed7aa
[shop] use server-only for process.env
JackJey Jul 14, 2023
433a4e6
Merge pull request #47 from privacysandbox/pull-request-template
Seburan Jul 14, 2023
bc9d83d
Merge pull request #51 from privacysandbox/shop
Seburan Jul 14, 2023
c78d746
Add OpenSSF Scorecard badge to README
pmeric Jul 14, 2023
9bfcb3f
[cicd] migrate to artifact registry
Seburan Jul 14, 2023
ef2e687
Merge pull request #53 from Seburan/migrate-artifact-registry
JackJey Jul 14, 2023
4fde791
Merge pull request #52 from pmeric/scorecard-badge
Seburan Jul 20, 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
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ TRAVEL_DETAIL="Advertiser: EC travel site"
# Adtech
## dsp
DSP_HOST=privacy-sandbox-demos-dsp.dev
DSP_TOKEN="Ar6MqtKFw6SUh5oefu/4F6omNKaC+NcxUOkgodGSKUNxqK9F/R1zrG9Psug9lWjdp4KhLN3kZk9Y95w0sCWOCwMAAABseyJvcmlnaW4iOiJodHRwczovL3ByaXZhY3ktc2FuZGJveC1kZW1vcy1kc3AuZGV2OjQ0MyIsImZlYXR1cmUiOiJQcml2YWN5U2FuZGJveEFkc0FQSXMiLCJleHBpcnkiOjE2OTUxNjc5OTl9"
DSP_TOKEN="A+Fn9SHGiUYuoSfqU6TBYlRZXCXXSdU6dtU22qpmPhSm9a5fbgvg92HuT11AMsunaP+R/EBOLfI0z5PzCYYe3AMAAACTeyJvcmlnaW4iOiJodHRwczovL3ByaXZhY3ktc2FuZGJveC1kZW1vcy1kc3AuZGV2OjQ0MyIsImZlYXR1cmUiOiJQcml2YWN5U2FuZGJveEFkc0FQSXMiLCJleHBpcnkiOjE2OTUxNjc5OTksImlzU3ViZG9tYWluIjp0cnVlLCJpc1RoaXJkUGFydHkiOnRydWV9"
DSP_DETAIL="Ad-Platform: DSP for advertiser"

## ssp
SSP_HOST=privacy-sandbox-demos-ssp.dev
SSP_TOKEN="ApaYz0jpASk+pCpujhNuZoN+I7rZY90hcS8cAbSZj7lm1vw2RozQ4SiawEEhuhujzL21G1Cucsiv+1/ASnpUiw4AAABseyJvcmlnaW4iOiJodHRwczovL3ByaXZhY3ktc2FuZGJveC1kZW1vcy1zc3AuZGV2OjQ0MyIsImZlYXR1cmUiOiJQcml2YWN5U2FuZGJveEFkc0FQSXMiLCJleHBpcnkiOjE2OTUxNjc5OTl9"
SSP_TOKEN="Axzh4tbjLU4oFhabm10G5MXd5XggN+BBSrZOLhSRk39zGhItK2WlafFFhkN6xLDdpGuvwVQkuVFSWue7vNTBnQYAAACTeyJvcmlnaW4iOiJodHRwczovL3ByaXZhY3ktc2FuZGJveC1kZW1vcy1zc3AuZGV2OjQ0MyIsImZlYXR1cmUiOiJQcml2YWN5U2FuZGJveEFkc0FQSXMiLCJleHBpcnkiOjE2OTUxNjc5OTksImlzU3ViZG9tYWluIjp0cnVlLCJpc1RoaXJkUGFydHkiOnRydWV9"
SSP_DETAIL="Ad-Platform: SSP for publisher"

## Collector for Aggregation Service
Expand Down
12 changes: 12 additions & 0 deletions .gcloudignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# ref : https://cloud.google.com/sdk/gcloud/reference/topic/gcloudignore

#!include:.gitignore

.gcloudignore
.git
.gitignore
services/home/.docusaurus
services/shop/.next

# include services/home/build/* files into `gcloud builds submit` command
!services/home/build
24 changes: 24 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
**Prior to creating a pull request, please follow all the steps in the [contributing guide](CONTRIBUTING.md).**

# Description

Please describe a summary of the changes.



## Related Issue

- Fixes #xxx


## Affected services

- [ ] Home
- [ ] News
- [ ] Shop
- [ ] Travel
- [ ] DSP
- [ ] SSP
- [ ] ALL

Other:
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ These use cases are based on a set of demo apps and services that we have develo
| DSP service (Demand Side Platform) | The demo DSP service will Add a user into an Interest Group with Protected Audience API. Register conversions with Attribution Reporting API |

We’re continuing our effort to deliver comprehensive documentation and demos, and we welcome your feedback on which use cases you would like to see in future releases. Share your ideas and feedback on our issue tracker.

---

[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/privacysandbox/privacy-sandbox-demos/badge)](https://securityscorecards.dev/viewer/?uri=github.com/privacysandbox/privacy-sandbox-demos)
88 changes: 88 additions & 0 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
steps:
# Build the container image
- name: "gcr.io/cloud-builders/docker"
args:
[
"build",
"-t",
"${_LOCATION}-docker.pkg.dev/$PROJECT_ID/${_REPOSITORY}/dsp",
"services/dsp",
]
# # Push the container image to Container Registry
# - name: "gcr.io/cloud-builders/docker"
# args:
# [
# "push",
# "${_LOCATION}-docker.pkg.dev/$PROJECT_ID/${_REPOSITORY}/dsp:$SHORT_SHA",
# ]
# # Deploy container image to Cloud Run
# - name: "gcr.io/cloud-builders/gcloud"
# args:
# [
# "run",
# "deploy",
# "dsp",
# "--image",
# "${_LOCATION}-docker.pkg.dev/$PROJECT_ID/${_REPOSITORY}/dsp:$SHORT_SHA",
# "--region",
# "${_LOCATION}",
# "--platform",
# "managed",
# "-memory",
# " 2Gi",
# "--min-instances",
# "1",
# "--allow-unauthenticated",
# ]
# Build the container image
- name: "gcr.io/cloud-builders/docker"
args:
[
"build",
"-t",
"${_LOCATION}-docker.pkg.dev/$PROJECT_ID/${_REPOSITORY}/home",
"services/home",
]
# Build the container image
- name: "gcr.io/cloud-builders/docker"
args:
[
"build",
"-t",
"${_LOCATION}-docker.pkg.dev/$PROJECT_ID/${_REPOSITORY}/news",
"services/news",
]
# Build the container image
- name: "gcr.io/cloud-builders/docker"
args:
[
"build",
"-t",
"${_LOCATION}-docker.pkg.dev/$PROJECT_ID/${_REPOSITORY}/shop",
"services/shop",
]
# Build the container image
- name: "gcr.io/cloud-builders/docker"
args:
[
"build",
"-t",
"${_LOCATION}-docker.pkg.dev/$PROJECT_ID/${_REPOSITORY}/ssp",
"services/ssp",
]
# Build the container image
- name: "gcr.io/cloud-builders/docker"
args:
[
"build",
"-t",
"${_LOCATION}-docker.pkg.dev/$PROJECT_ID/${_REPOSITORY}/travel",
"services/travel",
]
images:
- "${_LOCATION}-docker.pkg.dev/$PROJECT_ID/${_REPOSITORY}/dsp"
- "${_LOCATION}-docker.pkg.dev/$PROJECT_ID/${_REPOSITORY}/home"
- "${_LOCATION}-docker.pkg.dev/$PROJECT_ID/${_REPOSITORY}/news"
- "${_LOCATION}-docker.pkg.dev/$PROJECT_ID/${_REPOSITORY}/shop"
- "${_LOCATION}-docker.pkg.dev/$PROJECT_ID/${_REPOSITORY}/ssp"
- "${_LOCATION}-docker.pkg.dev/$PROJECT_ID/${_REPOSITORY}/travel"
46 changes: 40 additions & 6 deletions docs/deploy-to-gcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,19 @@ https://firebase.corp.google.com/project/_privacy-sandbox-demos_/settings/integr

Select all the sites you want to export logs from, click Save and Finish.

## Install Google Cloud SDK & Enable the Google Cloud Run API
## Serve dynamic content and host microservices with Cloud Run

Next you will deploy containers to Cloud Run to run the content of the demo sites.

For our architecture, we chose to deploy everything container based for portability and flexibility and to use Firebase hosting as a frontend solution for HTTPS request handling, domain name and ssl certificates.

### Install Google Cloud SDK & Enable the Google Cloud Run API

Install Google Cloud SDK : If Google Cloud SDK is not installed on the machine, follow instructions here : https://cloud.google.com/sdk/docs/install#linux

Initialize Google Cloud SDK : https://cloud.google.com/sdk/docs/initializing

```shell
```sh
# Run `gcloud init` to setup authentication and project
gcloud init

Expand All @@ -175,19 +177,51 @@ gcloud config set project

# Verify your configuration (account and project) with the command :
gcloud config list
```

Resources : https://firebase.google.com/docs/hosting/cloud-run

# Enable Cloud Run API
### Enable the APIs
Enable Cloud Run API & Cloud Build API & Artifact Registry

```sh
gcloud services enable run.googleapis.com cloudbuild.googleapis.com artifactregistry.googleapis.com
```

# Setup the default region for deployment
Setup the default region for deployment

```sh
gcloud config set run/region us-central1
```

Resources : https://firebase.google.com/docs/hosting/cloud-run
### Setup Artifact Registry

```sh
# create docker repository in Cloud Artifact Registry
gcloud artifacts repositories create docker-repo --repository-format=docker \
--location=us-central1 --description="Privacy Sandbox Demos Docker repository"

# set default repository
gcloud config set artifacts/repository docker-repo

# set default location
gcloud config set artifacts/location us-central1

```

confirm repository exists with

```sh
gcloud artifacts repositories list
```

Resources :
- https://cloud.google.com/artifact-registry/docs/enable-service
- https://cloud.google.com/artifact-registry/docs/transition/setup-repo

## Deploy all Cloud Run services and Firebase Sites

Once you have confirmed you can deploy a sample demo application on Cloud Run and access it from Firebase hosting site, you are ready to deploy all the services and hosting sites.
You are ready to deploy all the services and hosting sites.

Edit `services/.env` file to match the `${SERVICE}_HOST` parameter to your firebase hosting domain e.g. : `privacy-sandbox-demos-${SERVICE}.dev`

Expand Down
36 changes: 36 additions & 0 deletions scripts/cicd_setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env zsh

# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# evaluate .env file
source .env.deploy

# setup Google Cloud SDK project
gcloud config set project $GCP_PROJECT_NAME
gcloud config get-value project

# Enable Cloud Run API
gcloud services enable artifactregistry.googleapis.com

# create docker repository in Cloud Artifact Registry
gcloud artifacts repositories create docker-repo --repository-format=docker \
--location=us-central1 --description="Privacy Sandbox Demos Docker repository"

# set default repository
gcloud config set artifacts/repository docker-repo


# set default location
gcloud config set artifacts/location us-central1
12 changes: 6 additions & 6 deletions scripts/cloudrun_deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ gcloud config get-value project
# make the default region us-central1
gcloud config set run/region us-central1

# Containerize all services with Cloud Build (config file) and upload it to Container Registry
gcloud builds submit --config=cloudbuild.yaml --substitutions=_LOCATION="us-central1",_REPOSITORY="docker-repo" .

# Cloud Build
for service in $SERVICES; do
echo deploy $GCP_PROJECT_NAME/${service}

## push docker image
# docker push gcr.io/$GCP_PROJECT_NAME/${service}

# Containerize app with Cloud Build and upload it to Container Registry
gcloud builds submit services/${service} --tag gcr.io/$GCP_PROJECT_NAME/${service}
# Containerize service with Cloud Build (Dockerfile) and upload it to Container Registry
# gcloud builds submit services/${service} --tag us-central1-docker.pkg.dev/$GCP_PROJECT_NAME/docker-repo/${service}

# add "--min-instances 1" to have your service always on (cpu and memory billing will go up accordingly)
gcloud run deploy ${service} \
--image gcr.io/$GCP_PROJECT_NAME/${service}:latest \
--image us-central1-docker.pkg.dev/$GCP_PROJECT_NAME/docker-repo/${service}:latest \
--platform managed \
--region us-central1 \
--memory 2Gi \
Expand Down
3 changes: 0 additions & 3 deletions services/dsp/src/public/dsp-tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,4 @@
$iframe.src = src
$iframe.allow = "join-ad-interest-group"
$script.parentElement.insertBefore($iframe, $script.nextSibling)

const topics = await document?.browsingTopics?.()
console.log({ topics })
})()
10 changes: 7 additions & 3 deletions services/dsp/src/public/js/join-ad-interest-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ async function getInterestGroup(advertiser, id) {
}

document.addEventListener("DOMContentLoaded", async (e) => {
if (navigator.joinAdInterestGroup === undefined) {
return console.log("Protected Audience API is not supported")
}

// Protected Audience API
const url = new URL(location.href)
const advertiser = url.searchParams.get("advertiser")
Expand All @@ -36,7 +40,7 @@ document.addEventListener("DOMContentLoaded", async (e) => {
const kSecsPerDay = 3600 * 24 * 30
console.log(await navigator.joinAdInterestGroup(interestGroup, kSecsPerDay))

// Call Topics API for opt-in
const topics = await document.browsingTopics?.()
console.log({ topics })
// TODO: consider using Topics API for choosing Ads
// const topics = await document.browsingTopics?.()
// console.log({ topics })
})
11 changes: 11 additions & 0 deletions services/home/.gcloudignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

# ref : https://cloud.google.com/sdk/gcloud/reference/topic/gcloudignore

.gcloudignore
.git
.gitignore

#!include:.gitignore

# include build/* files into `gcloud builds submit` command
!build
6 changes: 3 additions & 3 deletions services/shop/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM node:18-alpine3.17
FROM node:20-alpine3.17

Check warning

Code scanning / Scorecard

Pinned-Dependencies

score is 8: containerImage not pinned by hash Remediation tip: pin your Docker image by updating node:20-alpine3.17 to node:20-alpine3.17@sha256:e6df1a7e4da3c01fee080bfb504dc5b980a19bea23bd1884629469b55d6cd02f Click Remediation section below for further remediation help

WORKDIR /workspace

COPY package*.json ./
RUN npm install
COPY . .

CMD [ "npm", "start" ]
# CMD ["npm", "run", "dev"]
# CMD ["npm", "run", "dev"]
CMD [ "npm", "start" ]
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
import type { NextApiRequest, NextApiResponse } from "next"
import { NextResponse } from "next/server"
import { fileURLToPath } from "url"
import { readFile } from "fs/promises"

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const id = req.query.id as string
const img = `../../../public/image/svg/emoji_u${id}.svg`
export async function GET(req: Request, { params }: { params: { id: string } }) {
const id = params.id
const img = `../../../../public/image/svg/emoji_u${id}.svg`
const path = fileURLToPath(new URL(img, import.meta.url))
const blob = await readFile(path)
res.setHeader("Content-Type", "image/svg+xml")
res.send(blob)
const res = new NextResponse(blob)
res.headers.set("Content-Type", "image/svg+xml")
return res
}
Loading