Skip to content

Commit

Permalink
Agregado docker-compose.yml con ejemplo para producción
Browse files Browse the repository at this point in the history
El archivo incluye ejemplo para PHP y NodeJS
  • Loading branch information
gepd committed Mar 5, 2021
1 parent 0b71d10 commit 5b3472a
Show file tree
Hide file tree
Showing 8 changed files with 492 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/vendor/*
/vendor/*
node_modules
33 changes: 33 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: "3"
services:
dte-api:
restart: "always"
image: chialab/php:7.3-fpm
command: bash -c "composer install && php -S 0.0.0.0:8000 index.php"
expose:
- "8000"
volumes:
- .:/var/www/html

# APP CON EJEMPLO DE NODEJS
app-node:
build:
context: ./ejemplos/node
dockerfile: Dockerfile
ports: # Debes usar el mismo puerto que tu servidor
- "3000:3000"
depends_on:
- dte-api
volumes:
- ./ejemplos/node:/home/node/dte # Montamos el ejemplo desde fuera en el directorio de node del contenedor
- /home/node/dte/node_modules

# APP CON EJEMPLO DE PHP
app-php:
image: php:8-apache
ports: # Debes usar el mismo puerto que tu servidor
- "3001:80"
depends_on:
- dte-api
volumes:
- ./ejemplos/php/:/var/www/html
13 changes: 13 additions & 0 deletions ejemplos/node/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:12.13.1-alpine

WORKDIR /home/node/dte

COPY ./package*.json ./yarn.lock ./

RUN apk update && apk add yarn

RUN yarn install

COPY . .

CMD ["yarn", "start"]
40 changes: 40 additions & 0 deletions ejemplos/node/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const http = require('http');
const express = require('express');

const app = express();
// PUERTO QUE USARÁ EXPRESS
const port = 3000;

// OPCIONES DEL MODULO HTTP PARA REALIZAR LA LLAMADA
const options = {
hostname: 'dte-api',
port: 8000,
path: '/dte/estado',
method: 'POST'
}

app.get('/', (req, res) => {
// LLAMADA A HTTP-DTE
const apiReq = http.request(options, apiRes => {
let str = '';

apiRes.on('data', data => str += data);

apiRes.on('end', function () {
res.send(str);
// SI RECIBES EL ERROR:
// {
// "name":"FIRMA_NO_BASE64",
// "message":"La firma debe estar codificada en base64",
// "statusCode":400
// }
// ES PORQUE AMBOS CONTAINERS SE HAN COMUNICADO CORRECTAMETNE
});
});

apiReq.end();
});

app.listen(port, () => {
console.log(`Servidor nodejs escuchando en: http://localhost:${port}`)
});
13 changes: 13 additions & 0 deletions ejemplos/node/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "node",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"start": "node ./index.js"
},
"dependencies": {
"express": "^4.17.1"
}

}
Loading

0 comments on commit 5b3472a

Please sign in to comment.