Skip to content

Commit 38bccad

Browse files
committed
운영환경 pgadmin 서버 추가
1 parent 976f326 commit 38bccad

4 files changed

Lines changed: 96 additions & 1 deletion

File tree

.github/workflows/release.yml

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,35 @@ jobs:
139139
--user root \
140140
grafana/promtail:3.4 -config.file=/etc/promtail/config.yaml || echo "Docker run failed: $?"
141141
142-
- name: Deploy Web Service to EC2
142+
- name: Setup pgAdmin config files
143+
run: |
144+
# Parse DATABASE_URL to extract connection details
145+
DB_URL="${{ secrets.DATABASE_URL }}"
146+
DB_HOST=$(echo $DB_URL | sed -n 's/.*@\([^:]*\):.*/\1/p')
147+
DB_USER=$(echo $DB_URL | sed -n 's/.*:\/\/\([^:]*\):.*/\1/p')
148+
DB_PASS=$(echo $DB_URL | sed -n 's/.*:\/\/[^:]*:\([^@]*\)@.*/\1/p')
149+
DB_NAME=$(echo $DB_URL | sed -n 's/.*\/\([^?]*\).*/\1/p')
150+
151+
# Create servers.json with actual DB details
152+
sed "s/HOST_PLACEHOLDER/$DB_HOST/g; s/USER_PLACEHOLDER/$DB_USER/g; s/DB_NAME_PLACEHOLDER/$DB_NAME/g" \
153+
infra/pgadmin/servers.json > servers.json
154+
155+
# Create pgpass with actual credentials
156+
sed "s/HOST_PLACEHOLDER/$DB_HOST/g; s/USER_PLACEHOLDER/$DB_USER/g; s/PASSWORD_PLACEHOLDER/$DB_PASS/g" \
157+
infra/pgadmin/pgpass > pgpass
158+
159+
chmod 600 pgpass
160+
161+
- name: Copy pgAdmin config to EC2
162+
uses: appleboy/scp-action@master
163+
with:
164+
host: ${{ secrets.EC2_HOST }}
165+
username: ubuntu
166+
key: ${{ secrets.EC2_SSH_KEY }}
167+
source: "servers.json,pgpass"
168+
target: "/home/ubuntu"
169+
170+
- name: Deploy Web Service and pgAdmin to EC2
143171
uses: appleboy/ssh-action@master
144172
with:
145173
host: ${{ secrets.EC2_HOST }}
@@ -153,7 +181,25 @@ jobs:
153181
docker pull ${{ secrets.ECR_REGISTRY }}/loa-work/web-service:latest
154182
docker stop web-service || true
155183
docker rm web-service || true
184+
docker stop pgadmin || true
185+
docker rm pgadmin || true
186+
187+
# Start pgAdmin with pre-configured database
188+
docker run -d \
189+
--name pgadmin \
190+
-p 5050:80 \
191+
--log-driver json-file \
192+
--log-opt max-size=10m \
193+
--log-opt max-file=3 \
194+
-e PGADMIN_DEFAULT_EMAIL="admin@loa-work.info" \
195+
-e PGADMIN_DEFAULT_PASSWORD="admin" \
196+
-e PGADMIN_CONFIG_SERVER_MODE=False \
197+
-v /home/ubuntu/servers.json:/pgadmin4/servers.json:ro \
198+
-v /home/ubuntu/pgpass:/pgpass:ro \
199+
--restart always \
200+
dpage/pgadmin4:latest
156201
202+
# Start web service
157203
docker run -d \
158204
--name web-service \
159205
-p 3000:3000 \

infra/pgadmin/pgpass

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
HOST_PLACEHOLDER:5432:*:USER_PLACEHOLDER:PASSWORD_PLACEHOLDER

infra/pgadmin/servers.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"Servers": {
3+
"1": {
4+
"Name": "LOA Work Database",
5+
"Group": "Servers",
6+
"Host": "HOST_PLACEHOLDER",
7+
"Port": 5432,
8+
"MaintenanceDB": "DB_NAME_PLACEHOLDER",
9+
"Username": "USER_PLACEHOLDER",
10+
"SSLMode": "require"
11+
}
12+
}
13+
}

infra/web/default.conf

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,41 @@ server {
1515
expires 1d;
1616
}
1717

18+
# pgAdmin 4 reverse proxy configuration
19+
location /pgadmin/ {
20+
# Remove trailing slash and redirect to add it back
21+
rewrite ^/pgadmin$ /pgadmin/ permanent;
22+
23+
proxy_pass http://localhost:5050;
24+
proxy_http_version 1.1;
25+
26+
proxy_set_header Host $host;
27+
proxy_set_header X-Real-IP $remote_addr;
28+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
29+
proxy_set_header X-Forwarded-Proto https;
30+
proxy_set_header X-Script-Name /pgadmin;
31+
32+
# WebSocket support for pgAdmin
33+
proxy_set_header Upgrade $http_upgrade;
34+
proxy_set_header Connection "upgrade";
35+
36+
# Increase buffer sizes for large queries
37+
proxy_buffer_size 128k;
38+
proxy_buffers 4 256k;
39+
proxy_busy_buffers_size 256k;
40+
41+
# Increase timeout for long-running queries
42+
proxy_connect_timeout 60s;
43+
proxy_send_timeout 60s;
44+
proxy_read_timeout 60s;
45+
46+
# Security headers for pgAdmin
47+
add_header X-Frame-Options "SAMEORIGIN" always;
48+
add_header X-Content-Type-Options "nosniff" always;
49+
add_header X-XSS-Protection "1; mode=block" always;
50+
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
51+
}
52+
1853
location / {
1954
proxy_pass http://localhost:3000;
2055
proxy_http_version 1.1;

0 commit comments

Comments
 (0)