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

Add cors support for docker compose #2814

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
version: "3.7"
services:
nginx:
image: nginx:latest
container_name: nginx
ports:
- "80:80"
volumes:
- nginx-conf:/etc/nginx
environment:
- MARQUEZ_HOST=api
- MARQUEZ_PORT=${API_PORT}
depends_on:
- api
entrypoint: ["./etc/nginx/entrypoint.sh"]

api:
image: "marquezproject/marquez:${TAG}"
container_name: marquez-api
Expand Down Expand Up @@ -37,6 +51,7 @@ services:
# command: ["postgres", "-c", "log_statement=all"]

volumes:
nginx-conf:
data:
db-conf:
db-init:
Expand Down
11 changes: 11 additions & 0 deletions docker/nginx/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
#
# Copyright 2018-2024 contributors to the Marquez project
# SPDX-License-Identifier: Apache-2.0
#
# Usage: $ ./entrypoint.sh

envsubst '$MARQUEZ_HOST,$MARQUEZ_PORT' < /etc/nginx/nginx.template > /etc/nginx/nginx.conf

# Start Nginx
nginx -g 'daemon off;'
22 changes: 22 additions & 0 deletions docker/nginx/nginx.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
events {}

http {
server {
listen 80;

location / {
proxy_pass http://${MARQUEZ_HOST}:${MARQUEZ_PORT};
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;

# Allow access from any origin:
add_header 'Access-Control-Allow-Origin' '*';
# Or, configure access from a specific origin:
# add_header 'Access-Control-Allow-Origin' 'https://example.com';
add_header 'Access-Control-Allow-Methods' 'GET, POST, DELETE, PUT';
add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept, Authorization';
}
}
}
10 changes: 9 additions & 1 deletion docker/volumes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,34 @@ if [[ -z "${volume_prefix}" ]]; then
fi

# Volumes with prefix
nginx_conf_volume="${volume_prefix}_nginx-conf"
data_volume="${volume_prefix}_data"
db_conf_volume="${volume_prefix}_db-conf"
db_init_volume="${volume_prefix}_db-init"
db_backup_volume="${volume_prefix}_db-backup"

echo "...creating volumes: ${data_volume}, ${db_conf_volume}, ${db_init_volume}, ${db_backup_volume}"
echo "...creating volumes: ${nginx_conf_volume}, ${data_volume}, ${db_conf_volume}, ${db_init_volume}, ${db_backup_volume}"

# Create persistent volumes for Marquez
docker volume create "${nginx_conf_volume}" > /dev/null
docker volume create "${data_volume}" > /dev/null
docker volume create "${db_conf_volume}" > /dev/null
docker volume create "${db_init_volume}" > /dev/null
docker volume create "${db_backup_volume}" > /dev/null

# Provision persistent volumes for Marquez
docker create --name volumes-provisioner \
-v "${nginx_conf_volume}:/nginx-conf" \
-v "${data_volume}:/data" \
-v "${db_conf_volume}:/db-conf" \
-v "${db_init_volume}:/db-init" \
busybox > /dev/null 2>&1

# Add startup configuration for nginx
docker cp ./docker/nginx/entrypoint.sh volumes-provisioner:/nginx-conf/
docker cp ./docker/nginx/nginx.template volumes-provisioner:/nginx-conf/
echo "Added files to volume ${nginx_conf_volume}: $(ls "${nginx_conf_volume}")"

# Add startup configuration for Marquez
docker cp ./docker/wait-for-it.sh volumes-provisioner:/data/wait-for-it.sh
echo "Added files to volume ${data_volume}: $(ls "${data_volume}")"
Expand Down
Loading