.
This commit is contained in:
1 parent
434e5c91b7
commit
5252968f78
5 files changed
+20
-50
No files matched your search
@@ -137,11 +137,7 @@ jobs:
|
||||
|
||||
- name: Restart container
|
||||
env:
|
||||
# Postgres runs on the Docker host. From inside a bridge network,
|
||||
# the public IP often times out (hairpin/NAT). Reach it via the
|
||||
# host gateway instead — requires Postgres listening on 0.0.0.0
|
||||
# (or docker0) and pg_hba allowing the Docker subnet.
|
||||
DATABASE_URL: postgresql://managment_web:hD3H9seTqX1GJMu1mDJBGDYr@host.docker.internal:5432/ManagmentWebSite_Db
|
||||
DATABASE_URL: postgresql://managment_web:hD3H9seTqX1GJMu1mDJBGDYr@185.36.145.12:5432/ManagmentWebSite_Db
|
||||
run: |
|
||||
set -euo pipefail
|
||||
docker rm -f "$CONTAINER_NAME" 2>/dev/null || true
|
||||
@@ -151,7 +147,6 @@ jobs:
|
||||
--name "$CONTAINER_NAME"
|
||||
--restart unless-stopped
|
||||
--network "$NETWORK_NAME"
|
||||
--add-host=host.docker.internal:host-gateway
|
||||
-e NODE_ENV=production
|
||||
-e PORT=3000
|
||||
-e HOSTNAME=0.0.0.0
|
||||
@@ -163,22 +158,6 @@ jobs:
|
||||
sleep 2
|
||||
docker logs "$CONTAINER_NAME" 2>&1 | tail -n 30
|
||||
|
||||
# Fail the job early if the app cannot reach Postgres from the container
|
||||
if ! docker exec "$CONTAINER_NAME" node -e "
|
||||
const { Pool } = require('pg');
|
||||
const pool = new Pool({
|
||||
connectionString: process.env.DATABASE_URL,
|
||||
connectionTimeoutMillis: 5000,
|
||||
});
|
||||
pool.query('SELECT 1')
|
||||
.then(() => { console.log('DB_OK'); return pool.end(); })
|
||||
.catch(async (e) => { console.error('DB_FAIL', e.message); try { await pool.end(); } catch {} process.exit(1); });
|
||||
"; then
|
||||
echo "::error::Container cannot reach Postgres via DATABASE_URL"
|
||||
docker logs "$CONTAINER_NAME" 2>&1 | tail -n 50
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Deployed ${CONTAINER_NAME} on ${NETWORK_NAME}"
|
||||
echo "Point Nginx Proxy Manager: ${PUBLIC_HOST} → http://${CONTAINER_NAME}:3000"
|
||||
|
||||
|
||||
+1
-4
@@ -12,10 +12,7 @@ services:
|
||||
- PORT=3000
|
||||
- HOSTNAME=0.0.0.0
|
||||
- NEXT_PUBLIC_SITE_URL=${NEXT_PUBLIC_SITE_URL:-https://edu.mstaut.ir}
|
||||
# Prefer host.docker.internal when Postgres is on the same machine as Docker.
|
||||
- DATABASE_URL=${DATABASE_URL:-postgresql://managment_web:hD3H9seTqX1GJMu1mDJBGDYr@host.docker.internal:5432/ManagmentWebSite_Db}
|
||||
extra_hosts:
|
||||
- "host.docker.internal:host-gateway"
|
||||
- DATABASE_URL=${DATABASE_URL:-postgresql://managment_web:hD3H9seTqX1GJMu1mDJBGDYr@185.36.145.12:5432/ManagmentWebSite_Db}
|
||||
# Nginx Proxy Manager: edu.mstaut.ir → http://aut-management-faculty:3000
|
||||
expose:
|
||||
- "3000"
|
||||
|
||||
+1
-12
@@ -37,18 +37,7 @@ DATABASE_URL=postgresql://managment_web:hD3H9seTqX1GJMu1mDJBGDYr@185.36.145.12:5
|
||||
|
||||
فایل محلی: `.env.local` (در gitignore است).
|
||||
|
||||
### Docker (همان سرور Postgres)
|
||||
|
||||
اگر اپ داخل کانتینر bridge و Postgres روی host باشد، از داخل کانتینر به IP عمومی
|
||||
(`185.36.145.12`) اغلب **timeout** میخورید. در `deploy.yml` / `docker-compose.yml`
|
||||
از `host.docker.internal` (+ `--add-host=host.docker.internal:host-gateway`) استفاده میشود.
|
||||
|
||||
پیشنیاز روی host:
|
||||
|
||||
- `listen_addresses` در Postgres شامل اینترفیس docker/host-gateway باشد (مثلاً `*`)
|
||||
- در `pg_hba.conf` شبکهٔ Docker مجاز باشد (مثلاً `172.16.0.0/12`)
|
||||
|
||||
برای تست از داخل کانتینر: `docker exec <web> node scripts/test-db-connection.mjs` با همان `DATABASE_URL`.
|
||||
Production (Docker و CI) هم باید مستقیم به `185.36.145.12` وصل شود — نه DNS داخلی Docker.
|
||||
|
||||
## تست سریع اتصال
|
||||
|
||||
|
||||
@@ -13,18 +13,27 @@ export async function generateMetadata(): Promise<Metadata> {
|
||||
|
||||
export default async function FacultyPage() {
|
||||
const t = await getTranslations("pages");
|
||||
const members = await getFaculty();
|
||||
let members: Awaited<ReturnType<typeof getFaculty>> = [];
|
||||
try {
|
||||
members = await getFaculty();
|
||||
} catch (err) {
|
||||
console.error("[faculty] getFaculty failed:", err);
|
||||
}
|
||||
|
||||
return (
|
||||
<main id="main-content">
|
||||
<PageHero title={t("facultyTitle")} intro={t("facultyIntro")} />
|
||||
<Section className="bg-gradient-to-b from-background to-muted/40">
|
||||
<Container>
|
||||
<div className="grid gap-6 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{members.map((member) => (
|
||||
<FacultyMemberCard key={member.id} member={member} />
|
||||
))}
|
||||
</div>
|
||||
{members.length === 0 ? (
|
||||
<p className="text-muted-foreground">در حال حاضر مدرسی برای نمایش نیست.</p>
|
||||
) : (
|
||||
<div className="grid gap-6 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{members.map((member) => (
|
||||
<FacultyMemberCard key={member.id} member={member} />
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</Container>
|
||||
</Section>
|
||||
</main>
|
||||
|
||||
+2
-6
@@ -5,10 +5,7 @@ const { Pool } = pg;
|
||||
/**
|
||||
* Shared Postgres pool for server-side use.
|
||||
* Connection details: docs/03-database.md
|
||||
*
|
||||
* In Docker on the same host as Postgres, prefer
|
||||
* `host.docker.internal` (see deploy.yml / docker-compose.yml).
|
||||
* Connecting to the public IP from a bridge network often times out.
|
||||
* Production must use DATABASE_URL → 185.36.145.12 (not Docker-internal DNS).
|
||||
*/
|
||||
export const pool = new Pool({
|
||||
connectionString:
|
||||
@@ -16,8 +13,7 @@ export const pool = new Pool({
|
||||
"postgresql://managment_web:hD3H9seTqX1GJMu1mDJBGDYr@185.36.145.12:5432/ManagmentWebSite_Db",
|
||||
max: 5,
|
||||
idleTimeoutMillis: 30000,
|
||||
// Fail fast so a dead DB does not pin every request for 10s+
|
||||
connectionTimeoutMillis: 4000,
|
||||
connectionTimeoutMillis: 10000,
|
||||
});
|
||||
|
||||
pool.on("error", (err) => {
|
||||
|
||||
Reference in new issue
Block a user