Skip to content

Commit 3489d3c

Browse files
authored
Merge pull request #44 from IABTechLab/sas-UID2-6012-migrate-sample-sites
environment variable substitution
2 parents 71fa4ba + a25f7a3 commit 3489d3c

File tree

12 files changed

+161
-40
lines changed

12 files changed

+161
-40
lines changed

.env.sample

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
UID2_CSTG_BASE_URL="https://operator-integ.uidapi.com"
2+
UID2_CSTG_SERVER_PUBLIC_KEY="UID2-X-I-MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEo+jcPlk8GWn3iG0R5Il2cbFQI9hR3TvHxaBUKHl5Vh+ugr+9uLMiXihka8To07ETFGghEifY96Hrpe5RnYko7Q=="
3+
UID2_CSTG_SUBSCRIPTION_ID="DMr7uHxqLU"

.gitattributes

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Set default behavior to automatically normalize line endings
2+
* text=auto
3+
4+
# Shell scripts should use LF
5+
*.sh text eol=lf
6+
7+
# Docker files should use LF
8+
Dockerfile text eol=lf
9+
docker-compose.yml text eol=lf
10+
11+
# Environment files can use CRLF on Windows
12+
*.env text
13+
env text

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.idea/
22
.DS_Store
3+
.env

README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,64 @@ The example applications illustrate the basic steps that you need to consider fo
2222
- Deal with missing identities.
2323
- Handle user opt-outs.
2424

25+
## Docker Compose Setup
26+
27+
This repository includes Docker Compose configuration for easy development and testing of multiple UID2 integration examples.
28+
29+
### Quick Start
30+
31+
**Start all services:**
32+
```bash
33+
docker-compose up -d
34+
```
35+
36+
**Start a single service:**
37+
```bash
38+
# Start only the Prebid.js client-side integration
39+
docker-compose up -d prebid-client
40+
41+
# Start with live logs (foreground)
42+
docker-compose up prebid-client
43+
```
44+
45+
**Stop services:**
46+
```bash
47+
# Stop all services
48+
docker-compose down
49+
50+
# Stop a single service
51+
docker-compose stop prebid-client
52+
```
53+
54+
**View logs:**
55+
```bash
56+
# View all logs
57+
docker-compose logs -f
58+
59+
# View logs for a specific service
60+
docker-compose logs -f prebid-client
61+
```
62+
63+
**Rebuild and restart:**
64+
```bash
65+
# Rebuild and restart all services
66+
docker-compose up -d --build
67+
68+
# Rebuild and restart a single service
69+
docker-compose up -d --build prebid-client
70+
```
71+
72+
### Available Services
73+
74+
- **`prebid-client`** - Prebid.js client-side integration (Port: 3031)
75+
- *More services will be added as they are containerized*
76+
77+
### Environment Configuration
78+
79+
Edit the `.env` file in the base directory to configure your UID2 settings:
80+
```
81+
UID2_BASE_URL="http://localhost:8080"
82+
SERVER_PUBLIC_KEY="your-public-key"
83+
SUBSCRIPTION_ID="your-subscription-id"
84+
```
85+

docker-compose.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
version: '3.8'
2+
3+
services:
4+
prebid-client:
5+
build:
6+
context: .
7+
dockerfile: web-integrations/prebid-integrations/client-side/Dockerfile
8+
ports:
9+
- "3031:3031"
10+
container_name: prebid-client-side
11+
12+
# Add more services here as needed
13+
# google-secure-signals-client:
14+
# build:
15+
# context: .
16+
# dockerfile: web-integrations/google-secure-signals/client-side/Dockerfile
17+
# ports:
18+
# - "3032:3032"
19+
# container_name: google-secure-signals-client
20+
21+
# javascript-sdk-client:
22+
# build:
23+
# context: .
24+
# dockerfile: web-integrations/javascript-sdk/client-side/Dockerfile
25+
# ports:
26+
# - "3033:3033"
27+
# container_name: javascript-sdk-client

web-integrations/prebid-integrations/client-side/.gitkeep

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
1-
# Use nginx as the base image
21
FROM nginx:alpine
32

4-
# Copy the static files to nginx html directory
5-
COPY index.html /usr/share/nginx/html/
6-
COPY app.css /usr/share/nginx/html/
7-
COPY prebid.js /usr/share/nginx/html/
8-
COPY config.js /usr/share/nginx/html/
3+
# Install gettext for envsubst
4+
RUN apk add --no-cache gettext
95

10-
# Create custom nginx config to listen on port 3031
11-
RUN echo 'server {' > /etc/nginx/conf.d/default.conf && \
12-
echo ' listen 3031;' >> /etc/nginx/conf.d/default.conf && \
13-
echo ' location / {' >> /etc/nginx/conf.d/default.conf && \
14-
echo ' root /usr/share/nginx/html;' >> /etc/nginx/conf.d/default.conf && \
15-
echo ' index index.html;' >> /etc/nginx/conf.d/default.conf && \
16-
echo ' }' >> /etc/nginx/conf.d/default.conf && \
17-
echo '}' >> /etc/nginx/conf.d/default.conf
6+
# Copy the env file
7+
COPY .env /tmp/env
188

19-
# Expose port 3031
20-
EXPOSE 3031
9+
# Copy static files from client-side directory
10+
COPY web-integrations/prebid-integrations/client-side/app.css /usr/share/nginx/html/
11+
COPY web-integrations/prebid-integrations/client-side/prebid.js /usr/share/nginx/html/
2112

22-
# Start nginx
23-
CMD ["nginx", "-g", "daemon off;"]
13+
# Copy config and HTML
14+
COPY web-integrations/prebid-integrations/client-side/default.conf /etc/nginx/conf.d/default.conf
15+
COPY web-integrations/prebid-integrations/client-side/index.html /usr/share/nginx/html/index.template.html
16+
COPY web-integrations/prebid-integrations/client-side/entrypoint.sh /entrypoint.sh
17+
18+
RUN chmod +x /entrypoint.sh
19+
20+
ENTRYPOINT ["/entrypoint.sh"]
21+
CMD ["nginx", "-g", "daemon off;"]

web-integrations/prebid-integrations/client-side/README.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,16 @@ Then navigate to [http://localhost:3031](http://localhost:3031) to view the appl
2222

2323
### Local Development with Custom Settings
2424

25-
For local development, you can override the default settings by editing the `config.js` file:
25+
The application automatically reads configuration from the `.env` file in the sample directory and substitutes the values into the HTML:
2626

27-
1. **Edit `config.js`** - Uncomment and modify the lines for your local environment:
28-
```javascript
29-
// Uncomment these lines in config.js:
30-
window.UID2_BASE_URL = 'https://your-local-uid2-operator.com';
31-
window.SERVER_PUBLIC_KEY = 'your-local-public-key';
32-
window.SUBSCRIPTION_ID = 'your-local-subscription-id';
27+
1. **Edit the `env` file** in the sample directory (`.env`) to set your local values:
28+
```
29+
UID2_BASE_URL="http://localhost:8080"
30+
SERVER_PUBLIC_KEY="your-local-public-key"
31+
SUBSCRIPTION_ID="your-local-subscription-id"
3332
```
3433

35-
2. **Rebuild and run the Docker container:**
34+
2. **Build and run the Docker container:**
3635
```bash
3736
docker build -t prebid-client-side .
3837
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
4140
3. **Alternative: Use browser dev tools** (for quick testing):
4241
```javascript
4342
// In browser console before page load
44-
window.UID2_BASE_URL = 'https://your-local-uid2-operator.com';
43+
window.uid2_example_settings.UID2_BASE_URL = 'https://your-local-uid2-operator.com';
4544
```
4645

47-
The `config.js` file includes example configurations for different environments (local, test, staging).
46+
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).
4847

4948

5049
## Prebid.js

web-integrations/prebid-integrations/client-side/config.js

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
server {
2+
listen 3031;
3+
4+
location / {
5+
root /usr/share/nginx/html;
6+
index index.html;
7+
try_files $uri $uri/ =404;
8+
}
9+
}

0 commit comments

Comments
 (0)