Skip to content

Commit

Permalink
[#][CI] docker-compose
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhongFuze committed May 24, 2024
1 parent 712064c commit 785e776
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 19 deletions.
28 changes: 18 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
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
20 changes: 20 additions & 0 deletions docker-compose.yml.bak
Original file line number Diff line number Diff line change
@@ -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"
15 changes: 11 additions & 4 deletions src/config/nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
2 changes: 1 addition & 1 deletion src/data_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
'''
Expand Down
21 changes: 18 additions & 3 deletions src/script/create_id_allocation.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion src/script/test_api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}'
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"]}'

0 comments on commit 785e776

Please sign in to comment.