diff --git a/.env.sample b/.env.sample new file mode 100644 index 0000000..87fb6d4 --- /dev/null +++ b/.env.sample @@ -0,0 +1,3 @@ +UID2_CSTG_BASE_URL="https://operator-integ.uidapi.com" +UID2_CSTG_SERVER_PUBLIC_KEY="UID2-X-I-MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEo+jcPlk8GWn3iG0R5Il2cbFQI9hR3TvHxaBUKHl5Vh+ugr+9uLMiXihka8To07ETFGghEifY96Hrpe5RnYko7Q==" +UID2_CSTG_SUBSCRIPTION_ID="DMr7uHxqLU" \ No newline at end of file diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..45e1818 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,13 @@ +# Set default behavior to automatically normalize line endings +* text=auto + +# Shell scripts should use LF +*.sh text eol=lf + +# Docker files should use LF +Dockerfile text eol=lf +docker-compose.yml text eol=lf + +# Environment files can use CRLF on Windows +*.env text +env text diff --git a/.gitignore b/.gitignore index f32e31a..8e08bbd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea/ .DS_Store +.env \ No newline at end of file diff --git a/README.md b/README.md index 8a19df4..68e1574 100644 --- a/README.md +++ b/README.md @@ -22,3 +22,64 @@ The example applications illustrate the basic steps that you need to consider fo - Deal with missing identities. - Handle user opt-outs. +## Docker Compose Setup + +This repository includes Docker Compose configuration for easy development and testing of multiple UID2 integration examples. + +### Quick Start + +**Start all services:** +```bash +docker-compose up -d +``` + +**Start a single service:** +```bash +# Start only the Prebid.js client-side integration +docker-compose up -d prebid-client + +# Start with live logs (foreground) +docker-compose up prebid-client +``` + +**Stop services:** +```bash +# Stop all services +docker-compose down + +# Stop a single service +docker-compose stop prebid-client +``` + +**View logs:** +```bash +# View all logs +docker-compose logs -f + +# View logs for a specific service +docker-compose logs -f prebid-client +``` + +**Rebuild and restart:** +```bash +# Rebuild and restart all services +docker-compose up -d --build + +# Rebuild and restart a single service +docker-compose up -d --build prebid-client +``` + +### Available Services + +- **`prebid-client`** - Prebid.js client-side integration (Port: 3031) +- *More services will be added as they are containerized* + +### Environment Configuration + +Edit the `.env` file in the base directory to configure your UID2 settings: +``` +UID2_BASE_URL="http://localhost:8080" +SERVER_PUBLIC_KEY="your-public-key" +SUBSCRIPTION_ID="your-subscription-id" +``` + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..0be1df0 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,27 @@ +version: '3.8' + +services: + prebid-client: + build: + context: . + dockerfile: web-integrations/prebid-integrations/client-side/Dockerfile + ports: + - "3031:3031" + container_name: prebid-client-side + + # Add more services here as needed + # google-secure-signals-client: + # build: + # context: . + # dockerfile: web-integrations/google-secure-signals/client-side/Dockerfile + # ports: + # - "3032:3032" + # container_name: google-secure-signals-client + + # javascript-sdk-client: + # build: + # context: . + # dockerfile: web-integrations/javascript-sdk/client-side/Dockerfile + # ports: + # - "3033:3033" + # container_name: javascript-sdk-client diff --git a/web-integrations/prebid-integrations/client-side/.gitkeep b/web-integrations/prebid-integrations/client-side/.gitkeep deleted file mode 100644 index dcf2c80..0000000 --- a/web-integrations/prebid-integrations/client-side/.gitkeep +++ /dev/null @@ -1 +0,0 @@ -# Placeholder diff --git a/web-integrations/prebid-integrations/client-side/Dockerfile b/web-integrations/prebid-integrations/client-side/Dockerfile index 5d74510..9db702a 100644 --- a/web-integrations/prebid-integrations/client-side/Dockerfile +++ b/web-integrations/prebid-integrations/client-side/Dockerfile @@ -1,23 +1,21 @@ -# Use nginx as the base image FROM nginx:alpine -# Copy the static files to nginx html directory -COPY index.html /usr/share/nginx/html/ -COPY app.css /usr/share/nginx/html/ -COPY prebid.js /usr/share/nginx/html/ -COPY config.js /usr/share/nginx/html/ +# Install gettext for envsubst +RUN apk add --no-cache gettext -# Create custom nginx config to listen on port 3031 -RUN echo 'server {' > /etc/nginx/conf.d/default.conf && \ - echo ' listen 3031;' >> /etc/nginx/conf.d/default.conf && \ - echo ' location / {' >> /etc/nginx/conf.d/default.conf && \ - echo ' root /usr/share/nginx/html;' >> /etc/nginx/conf.d/default.conf && \ - echo ' index index.html;' >> /etc/nginx/conf.d/default.conf && \ - echo ' }' >> /etc/nginx/conf.d/default.conf && \ - echo '}' >> /etc/nginx/conf.d/default.conf +# Copy the env file +COPY .env /tmp/env -# Expose port 3031 -EXPOSE 3031 +# Copy static files from client-side directory +COPY web-integrations/prebid-integrations/client-side/app.css /usr/share/nginx/html/ +COPY web-integrations/prebid-integrations/client-side/prebid.js /usr/share/nginx/html/ -# Start nginx -CMD ["nginx", "-g", "daemon off;"] +# Copy config and HTML +COPY web-integrations/prebid-integrations/client-side/default.conf /etc/nginx/conf.d/default.conf +COPY web-integrations/prebid-integrations/client-side/index.html /usr/share/nginx/html/index.template.html +COPY web-integrations/prebid-integrations/client-side/entrypoint.sh /entrypoint.sh + +RUN chmod +x /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/web-integrations/prebid-integrations/client-side/README.md b/web-integrations/prebid-integrations/client-side/README.md index 7e02593..78510b6 100644 --- a/web-integrations/prebid-integrations/client-side/README.md +++ b/web-integrations/prebid-integrations/client-side/README.md @@ -22,17 +22,16 @@ Then navigate to [http://localhost:3031](http://localhost:3031) to view the appl ### Local Development with Custom Settings -For local development, you can override the default settings by editing the `config.js` file: +The application automatically reads configuration from the `.env` file in the sample directory and substitutes the values into the HTML: -1. **Edit `config.js`** - Uncomment and modify the lines for your local environment: - ```javascript - // Uncomment these lines in config.js: - window.UID2_BASE_URL = 'https://your-local-uid2-operator.com'; - window.SERVER_PUBLIC_KEY = 'your-local-public-key'; - window.SUBSCRIPTION_ID = 'your-local-subscription-id'; +1. **Edit the `env` file** in the sample directory (`.env`) to set your local values: + ``` + UID2_BASE_URL="http://localhost:8080" + SERVER_PUBLIC_KEY="your-local-public-key" + SUBSCRIPTION_ID="your-local-subscription-id" ``` -2. **Rebuild and run the Docker container:** +2. **Build and run the Docker container:** ```bash docker build -t prebid-client-side . docker run -p 3031:3031 prebid-client-side @@ -41,10 +40,10 @@ For local development, you can override the default settings by editing the `con 3. **Alternative: Use browser dev tools** (for quick testing): ```javascript // In browser console before page load - window.UID2_BASE_URL = 'https://your-local-uid2-operator.com'; + window.uid2_example_settings.UID2_BASE_URL = 'https://your-local-uid2-operator.com'; ``` -The `config.js` file includes example configurations for different environments (local, test, staging). +The Docker build process automatically reads the `.env` file and substitutes the values into the HTML using `envsubst`. If a variable is not set in the `env` file, it uses the default values (after the `:-` in the substitution syntax). ## Prebid.js diff --git a/web-integrations/prebid-integrations/client-side/config.js b/web-integrations/prebid-integrations/client-side/config.js deleted file mode 100644 index 6db9c2c..0000000 --- a/web-integrations/prebid-integrations/client-side/config.js +++ /dev/null @@ -1,7 +0,0 @@ -// Local Development Configuration -// This file can be modified to override default settings for local development - -// Uncomment and modify the lines below to override default settings for local development -window.UID2_BASE_URL = 'http://localhost:8080'; -window.SERVER_PUBLIC_KEY = 'UID2-X-L-MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEtXJdTSZAYHvoRDWiehMHoWF1BNPuqLs5w2ZHiAZ1IJc7O4/z0ojPTB0V+KYX/wxQK0hxx6kxCvHj335eI/ZQsQ=='; -window.SUBSCRIPTION_ID = '4WvryDGbR5'; \ No newline at end of file diff --git a/web-integrations/prebid-integrations/client-side/default.conf b/web-integrations/prebid-integrations/client-side/default.conf new file mode 100644 index 0000000..4f7cebc --- /dev/null +++ b/web-integrations/prebid-integrations/client-side/default.conf @@ -0,0 +1,9 @@ +server { + listen 3031; + + location / { + root /usr/share/nginx/html; + index index.html; + try_files $uri $uri/ =404; + } +} diff --git a/web-integrations/prebid-integrations/client-side/entrypoint.sh b/web-integrations/prebid-integrations/client-side/entrypoint.sh new file mode 100644 index 0000000..e975303 --- /dev/null +++ b/web-integrations/prebid-integrations/client-side/entrypoint.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +# Load environment variables from env file +export $(cat /tmp/env | xargs) + +# Set default values if not provided +export BASE_URL=${UID2_CSTG_BASE_URL:-"https://operator-integ.uidapi.com"} +export SERVER_PUBLIC_KEY=${UID2_CSTG_SERVER_PUBLIC_KEY:-"UID2-X-I-MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEo+jcPlk8GWn3iG0R5Il2cbFQI9hR3TvHxaBUKHl5Vh+ugr+9uLMiXihka8To07ETFGghEifY96Hrpe5RnYko7Q=="} +export SUBSCRIPTION_ID=${UID2_CSTG_SUBSCRIPTION_ID:-"DMr7uHxqLU"} + +# Copy static files +cp /usr/share/nginx/html/app.css /usr/share/nginx/html/ +cp /usr/share/nginx/html/prebid.js /usr/share/nginx/html/ + +# Process index.html template with environment variables +envsubst < /usr/share/nginx/html/index.template.html > /usr/share/nginx/html/index.html + +# Start nginx +exec nginx -g "daemon off;" diff --git a/web-integrations/prebid-integrations/client-side/index.html b/web-integrations/prebid-integrations/client-side/index.html index 218db49..26033f0 100644 --- a/web-integrations/prebid-integrations/client-side/index.html +++ b/web-integrations/prebid-integrations/client-side/index.html @@ -7,14 +7,13 @@ -