Containerizacion completa
This commit is contained in:
4
.env
4
.env
@@ -14,4 +14,6 @@ SERVER_PORT=3300
|
|||||||
# Cliente simulado que va a recibir los webhooks
|
# Cliente simulado que va a recibir los webhooks
|
||||||
# puramente de debug para el servicio
|
# puramente de debug para el servicio
|
||||||
CLIENT_IP="127.0.0.1"
|
CLIENT_IP="127.0.0.1"
|
||||||
CLIENT_PORT=3000
|
CLIENT_PORT=3600
|
||||||
|
|
||||||
|
DEV_POSTGRES_PORT=5433
|
||||||
|
|||||||
4
.local.env
Normal file
4
.local.env
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
POSTGRES_PASSWORD='1234'
|
||||||
|
POSTGRES_USER=postgres
|
||||||
|
POSTGRES_DB=postgres
|
||||||
|
POSTGRES_PORT='5432'
|
||||||
2
build.local.sh
Executable file
2
build.local.sh
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
#/bin/bash
|
||||||
|
docker compose -f deployment/local/docker/docker-compose.yaml --project-directory ./ build
|
||||||
40
compose.yaml
40
compose.yaml
@@ -1,40 +0,0 @@
|
|||||||
services:
|
|
||||||
backend:
|
|
||||||
build:
|
|
||||||
context: ./
|
|
||||||
target: backend
|
|
||||||
expose:
|
|
||||||
- 3000
|
|
||||||
ports:
|
|
||||||
- 3000:${PORT}
|
|
||||||
env_file:
|
|
||||||
- ".env"
|
|
||||||
depends_on:
|
|
||||||
postgresql:
|
|
||||||
condition: service_healthy
|
|
||||||
restart: true
|
|
||||||
develop:
|
|
||||||
watch:
|
|
||||||
- path: ./src
|
|
||||||
action: sync
|
|
||||||
target: /usr/local/app/src
|
|
||||||
- path: ./backend/package.json
|
|
||||||
action: rebuild
|
|
||||||
postgresql:
|
|
||||||
image: postgres:16.1
|
|
||||||
ports:
|
|
||||||
- 5432:${POSTGRES_PORT}
|
|
||||||
volumes:
|
|
||||||
- ./sql-data/:/var/lib/postgres/data
|
|
||||||
- ./deployment/database/test.sql:/docker-entrypoint-initdb.d/init.sql
|
|
||||||
environment:
|
|
||||||
POSTGRES_PASSWORD: 1234
|
|
||||||
POSTGRES_USER: postgres
|
|
||||||
POSTGRES_DB: postgres
|
|
||||||
healthcheck:
|
|
||||||
test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
|
|
||||||
interval: 10s
|
|
||||||
retries: 5
|
|
||||||
start_period: 30s
|
|
||||||
timeout: 10s
|
|
||||||
|
|
||||||
@@ -5,7 +5,7 @@ WORKDIR /usr/local/app
|
|||||||
# compilacion del ts -> js
|
# compilacion del ts -> js
|
||||||
FROM base AS backend
|
FROM base AS backend
|
||||||
WORKDIR /usr/local/app
|
WORKDIR /usr/local/app
|
||||||
EXPOSE 3000
|
EXPOSE ${PORT}
|
||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
# copia el codigo en general
|
# copia el codigo en general
|
||||||
COPY .tsconfig*.json ./
|
COPY .tsconfig*.json ./
|
||||||
46
deployment/local/docker/docker-compose.yaml
Normal file
46
deployment/local/docker/docker-compose.yaml
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
name: p-simulador-webhooks
|
||||||
|
networks:
|
||||||
|
internal:
|
||||||
|
driver: bridge
|
||||||
|
driver_opts:
|
||||||
|
com.docker.network.bridge.host_binding_ipv4: "127.0.0.1"
|
||||||
|
services:
|
||||||
|
p-simulador-webhooks:
|
||||||
|
container_name: p-simulador-webhooks-standalone
|
||||||
|
build:
|
||||||
|
context: ./
|
||||||
|
dockerfile: deployment/Dockerfile.dev
|
||||||
|
args:
|
||||||
|
PORT: "${PORT:-3000}"
|
||||||
|
develop:
|
||||||
|
watch:
|
||||||
|
- path: ./src
|
||||||
|
action: sync
|
||||||
|
target: /usr/local/app/src
|
||||||
|
- path: ./package.json
|
||||||
|
action: rebuild
|
||||||
|
image: p-simulador-desarrollo-backend
|
||||||
|
ports:
|
||||||
|
- 3000:${PORT}
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
|
restart: unless-stopped
|
||||||
|
networks:
|
||||||
|
- internal
|
||||||
|
postgresql:
|
||||||
|
image: postgres:16.1
|
||||||
|
env_file:
|
||||||
|
- .local.env
|
||||||
|
ports:
|
||||||
|
- "5432:${DEV_POSTGRES_PORT}"
|
||||||
|
volumes:
|
||||||
|
- ./sql-data/:/var/lib/postgres/data
|
||||||
|
- ./deployment/database/test.sql:/docker-entrypoint-initdb.d/init.sql
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
|
||||||
|
interval: 10s
|
||||||
|
retries: 5
|
||||||
|
start_period: 30s
|
||||||
|
timeout: 10s
|
||||||
|
networks:
|
||||||
|
- internal
|
||||||
9
deployment/local/docker/rebuild.sh
Normal file
9
deployment/local/docker/rebuild.sh
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
cd /mnt/docker-storage/containers/savefamily/sf-shopify-orders
|
||||||
|
|
||||||
|
docker stop sf-shopify-orders-api || true
|
||||||
|
docker rm sf-shopify-orders-api || true
|
||||||
|
docker rmi sf-shopify-orders-api || true
|
||||||
|
|
||||||
|
docker compose -f docker-compose.yaml up --build -d
|
||||||
2
run.local.sh
Executable file
2
run.local.sh
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
#/bin/bash
|
||||||
|
docker compose -f deployment/local/docker/docker-compose.yaml --project-directory ./ up
|
||||||
@@ -13,7 +13,8 @@ server.listen(PORT, () => {
|
|||||||
console.log(`[Server] Server is running on port ${PORT} in ${config.env} mode`);
|
console.log(`[Server] Server is running on port ${PORT} in ${config.env} mode`);
|
||||||
console.log(`[Server] Webhook endpoint: http://localhost:${PORT}/api/webhooks`);
|
console.log(`[Server] Webhook endpoint: http://localhost:${PORT}/api/webhooks`);
|
||||||
});
|
});
|
||||||
|
/*
|
||||||
client.listen(CLIENT_PORT, () => {
|
clientient.listen(CLIENT_PORT, () => {
|
||||||
console.log(` [Client] Client ins running on port ${CLIENT_PORT}`)
|
console.log(` [Client] Client ins running on port ${CLIENT_PORT}`)
|
||||||
})
|
})
|
||||||
|
*/
|
||||||
|
|||||||
@@ -38,17 +38,33 @@ export const INITIAL_HOSTS: InitialHost[] = [
|
|||||||
{
|
{
|
||||||
topic: "order/create",
|
topic: "order/create",
|
||||||
host: "localhost",
|
host: "localhost",
|
||||||
port: "3000",
|
port: "3500",
|
||||||
endpoint: "/order/create",
|
endpoint: "/order/create",
|
||||||
method: "POST",
|
method: "POST",
|
||||||
secretkey: webhooksConfig.apiSecret || "1234",
|
secretkey: webhooksConfig.apiSecret || "1234",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
topic: "order/create",
|
||||||
|
host: "localhost",
|
||||||
|
port: "3000",
|
||||||
|
endpoint: '/webhooks/shopify/orders',
|
||||||
|
method: "POST",
|
||||||
|
secretkey: webhooksConfig.apiSecret || "1234",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
topic: "order/create",
|
||||||
|
host: "sf-shopify-orders-api",
|
||||||
|
port: "3000",
|
||||||
|
endpoint: '/webhooks/shopify/orders',
|
||||||
|
method: "POST",
|
||||||
|
secretkey: webhooksConfig.apiSecret || "1234",
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
export const INITIAL_EVENTS: ScheduledEvent[] = [
|
export const INITIAL_EVENTS: ScheduledEvent[] = [
|
||||||
{
|
{
|
||||||
topic: "order/create",
|
topic: "order/create",
|
||||||
numberOfMessages: 5,
|
numberOfMessages: -1,
|
||||||
periodMs: 1000
|
periodMs: 5000
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -27,14 +27,9 @@ export class EventScheduler {
|
|||||||
|
|
||||||
private start() {
|
private start() {
|
||||||
for (const event of this.eventList) {
|
for (const event of this.eventList) {
|
||||||
console.log("Evento", event)
|
|
||||||
let sentMesages = 0
|
let sentMesages = 0
|
||||||
const interval = setInterval(() => {
|
const interval = setInterval(() => {
|
||||||
console.log("[Server] Lanzado evento ", event)
|
console.log("[Server] Lanzado evento ", event)
|
||||||
if (event.numberOfMessages == undefined || event.numberOfMessages < 1) {
|
|
||||||
console.log("xx")
|
|
||||||
return; // Se lannza de continuo
|
|
||||||
}
|
|
||||||
|
|
||||||
this.subscriptionManager.poll(<ShopifyEvent>{
|
this.subscriptionManager.poll(<ShopifyEvent>{
|
||||||
topic: event.topic,
|
topic: event.topic,
|
||||||
@@ -42,7 +37,10 @@ export class EventScheduler {
|
|||||||
})
|
})
|
||||||
|
|
||||||
sentMesages++;
|
sentMesages++;
|
||||||
if (sentMesages > event.numberOfMessages) {
|
|
||||||
|
if (event.numberOfMessages == undefined || event.numberOfMessages < 1) {
|
||||||
|
return; // Se lannza de continuo
|
||||||
|
} else if (sentMesages > event.numberOfMessages) {
|
||||||
clearInterval(interval)
|
clearInterval(interval)
|
||||||
}
|
}
|
||||||
}, event.periodMs ?? 1000)
|
}, event.periodMs ?? 1000)
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user