diff --git a/docker-compose.yml b/docker-compose.yml index 5b83609..71bfb5b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,14 +1,5 @@ version: "3.9" services: - server: - image: ghcr.io/zhongfuze/id_allocation:main - container_name: id_allocation - volumes: - - ~/app/data:/app/data - - ~/app/config:/app/config - - ~/app/log_tmp:/tmp - - ~/app/log:/app/log - network_mode: "host" nginx: image: nginx container_name: nginx @@ -17,4 +8,21 @@ services: - ~/app/nginx/conf.d:/etc/nginx/conf.d - ~/app/nginx/logs:/var/log/nginx - ~/app/nginx/ssl:/etc/ssl - network_mode: "host" \ No newline at end of file + ports: + - "9002:9001" + depends_on: + - id_allocation + + id_allocation: + image: ghcr.io/zhongfuze/id_allocation:main + container_name: id_allocation + volumes: + - ~/app/data:/app/data + - ~/app/config:/app/config + - ~/app/log_tmp:/tmp + - ~/app/log:/app/log + ports: + - "9001:9001" +networks: + default: + driver: bridge \ No newline at end of file diff --git a/docker-compose.yml.bak b/docker-compose.yml.bak new file mode 100644 index 0000000..5b83609 --- /dev/null +++ b/docker-compose.yml.bak @@ -0,0 +1,20 @@ +version: "3.9" +services: + server: + image: ghcr.io/zhongfuze/id_allocation:main + container_name: id_allocation + volumes: + - ~/app/data:/app/data + - ~/app/config:/app/config + - ~/app/log_tmp:/tmp + - ~/app/log:/app/log + network_mode: "host" + nginx: + image: nginx + container_name: nginx + volumes: + - ~/app/nginx/nginx.conf:/etc/nginx/nginx.conf + - ~/app/nginx/conf.d:/etc/nginx/conf.d + - ~/app/nginx/logs:/var/log/nginx + - ~/app/nginx/ssl:/etc/ssl + network_mode: "host" \ No newline at end of file diff --git a/src/config/nginx/nginx.conf b/src/config/nginx/nginx.conf index 3ce57e8..4ab7ca1 100644 --- a/src/config/nginx/nginx.conf +++ b/src/config/nginx/nginx.conf @@ -25,15 +25,22 @@ http { include /etc/nginx/conf.d/*.conf; server { - listen 80; - server_name ec2-18-167-19-252.ap-east-1.compute.amazonaws.com; + listen 9001; + server_name ec2-18-167-19-252.ap-east-1.compute.amazonaws.com; + # Deny access to all resources by default location / { - proxy_pass http://localhost; + deny all; + return 403; + } + + # Allow access to the specific endpoint + location /id_allocation/allocation { + proxy_pass http://id_allocation:9001; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; - proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; } } } \ No newline at end of file diff --git a/src/data_server.py b/src/data_server.py index 68a5589..ac32abb 100644 --- a/src/data_server.py +++ b/src/data_server.py @@ -4,7 +4,7 @@ Author: Zella Zhong Date: 2024-05-23 22:34:52 LastEditors: Zella Zhong -LastEditTime: 2024-05-24 05:44:41 +LastEditTime: 2024-05-25 04:19:08 FilePath: /id_allocation/src/data_server.py Description: main entry point for allocating ''' diff --git a/src/script/create_id_allocation.sql b/src/script/create_id_allocation.sql index fee4763..ead9a29 100644 --- a/src/script/create_id_allocation.sql +++ b/src/script/create_id_allocation.sql @@ -39,8 +39,25 @@ BEGIN UPDATE id_allocation SET graph_id = return_graph_id, updated_nanosecond = return_updated_nanosecond, picked_time = CURRENT_TIMESTAMP WHERE unique_id = ANY(vids); + + -- Insert new records that do not exist in the table + FOR existing_record IN + SELECT unnest(vids) AS unique_id + LOOP + INSERT INTO id_allocation (unique_id, graph_id, platform, identity, updated_nanosecond, picked_time) + VALUES ( + existing_record.unique_id, + new_graph_id, + split_part(existing_record.unique_id, ',', 1), + split_part(existing_record.unique_id, ',', 2), + new_updated_nanosecond, + CURRENT_TIMESTAMP + ) + ON CONFLICT (unique_id) DO NOTHING; -- Ensure no duplicates + END LOOP; + ELSE - -- Insert new records + -- Insert all records since no existing records were found FOR existing_record IN SELECT unnest(vids) AS unique_id LOOP @@ -64,8 +81,6 @@ BEGIN END; $$ LANGUAGE plpgsql; - - SELECT * FROM process_id_allocation( ARRAY['twitter,chan_izaki65652', 'farcaster,gytred', 'ethereum,0x61ae970ac67ff4164ebf2fd6f38f630df522e5ef'], 'aec0c81c-7ab2-42e6-bb74-e7ea8d2cf903', diff --git a/src/script/test_api.sh b/src/script/test_api.sh index 283ceca..26328a3 100644 --- a/src/script/test_api.sh +++ b/src/script/test_api.sh @@ -3,4 +3,4 @@ curl -w "\nTime: %{time_total}s\n" -X POST http://127.0.0.1:9001/id_allocation/allocation -d '{"graph_id":"cba9bbf5-ee77-48f6-919c-302fcd1c2a23","updated_nanosecond":1716482473640540,"vids":["twitter,chan_izaki65652","farcaster,gytred","ethereum,0x61ae970ac67ff4164ebf2fd6f38f630df522e5ef"]}' -curl -w "\nTime: %{time_total}s\n" -X POST 'http://ec2-18-167-19-252.ap-east-1.compute.amazonaws.com/id_allocation/allocation' -d '{"graph_id":"101d4307-f84f-4942-b6ce-df0bab491bae","updated_nanosecond":1716565633694549,"vids":["crossbell,suji.csb","crossbell,sujiyan.csb","ethereum,0x934b510d4c9103e6a87aef13b816fb080286d649"]}' \ No newline at end of file +curl -w "\nTime: %{time_total}s\n" -X POST 'http://ec2-18-167-19-252.ap-east-1.compute.amazonaws.com:9002/id_allocation/allocation' -d '{"graph_id":"101d4307-f84f-4942-b6ce-df0bab491bae","updated_nanosecond":1716565633694549,"vids":["crossbell,suji.csb","crossbell,sujiyan.csb","ethereum,0x934b510d4c9103e6a87aef13b816fb080286d649"]}' \ No newline at end of file