This commit is contained in:
David Arranz 2024-09-04 12:24:41 +02:00
parent 56410d43e3
commit 5fc3088b73
6 changed files with 115 additions and 39 deletions

7
.env-production Normal file
View File

@ -0,0 +1,7 @@
MYSQL_ROOT_PASSWORD=uZm#bch6pPs8
MYSQL_DATABASE=uecko
MYSQL_USER=uecko
MYSQL_USER_PASSWORD=u8Ax5Nw3%sjd
PMA_USER=uecko
PMA_PASSWORD=u8Ax5Nw3%sjd

17
Caddyfile Normal file
View File

@ -0,0 +1,17 @@
presupuestos.uecko.com {
# Protección con Basic Auth para PhpMyAdmin
route /phpmyadmin/* {
basicauth {
usuario_secreto contraseña_segura
}
reverse_proxy phpmyadmin:80
}
reverse_proxy /api/* api:3000 # Redirige el tráfico de la API a tu contenedor de API
reverse_proxy /* client:80 # Redirige todo lo demás a tu aplicación React
encode gzip # Comprime las respuestas con gzip
}
www.presupuestos.uecko.com {
redir https://presupuestos.uecko.com{uri} # Redirige www a la versión sin www
}

10
client/Dockerfile Normal file
View File

@ -0,0 +1,10 @@
# BUILD
FROM node:lts-iron AS builder
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn install
COPY . .
RUN yarn build

View File

@ -5,53 +5,74 @@ services:
image: mariadb:latest
container_name: mariadb
environment:
MYSQL_ROOT_PASSWORD: uZm#bch6pPs8
MYSQL_DATABASE: uecko
MYSQL_USER: uecko
MYSQL_PASSWORD: u8Ax5Nw3%sjd
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_USER_PASSWORD}
volumes:
- mariadb_data:/var/lib/mysql
networks:
- bridge
- presupuestos-uecko-app-network
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
environment:
PMA_HOST: mariadb
PMA_USER: uecko
PMA_PASSWORD: u8Ax5Nw3%sjd
ports:
- "8080:80"
PMA_USER: ${MYSQL_USER}
PMA_PASSWORD: ${MYSQL_USER_PASSWORD}
networks:
- bridge
- presupuestos-uecko-app-network
nginx:
image: nginx:latest
container_name: nginx
volumes:
- nginx_conf:/etc/nginx
- nginx_html:/usr/share/nginx/html
caddy:
image: caddy:latest
container_name: caddy
ports:
- "80:80"
- "443:443"
networks:
- bridge
nodejs:
image: node:lts-iron
container_name: nodejs
ports:
- "3000:3000"
volumes:
- ./app:/usr/src/app
working_dir: /usr/src/app
- caddy_etc:/etc/caddy/
- caddy_html:/html
- caddy_data:/data
- caddy_config:/config
networks:
- presupuestos-uecko-app-network
depends_on:
- backend
- frontend
frontend:
build: ./client
networks:
- presupuestos-uecko-app-network
backend:
build: ./server
environment:
MYSQL_HOST: mysql
MYSQL_USER: root
MYSQL_PASSWORD: yourpassword
MYSQL_DB: yourdatabase
DATABASE_URL: mysql://user:user_password@db:3306/my_database
networks:
- presupuestos-uecko-app-network
depends_on:
- mariadb
api:
build:
dockerfile: Dockerfile
context: "./server"
volumes:
- /api/node_modules
- ./server:/api
volumes:
mariadb_data:
nginx_html:
nginx_conf:
app:
caddy_etc:
caddy_data:
caddy_html:
caddy_config:
networks:
bridge:
presupuestos-uecko-app-network:

View File

@ -1,14 +1,35 @@
FROM node:20 as builder
RUN corepack enable && corepack prepare pnpm@latest --activate
ENV PNPM_HOME=/usr/local/bin
# BUILD
FROM node:lts-iron AS builder
# Establecer el directorio de trabajo
WORKDIR /api
COPY ./server/package.json pnpm-lock.yaml ./
COPY package.json yarn.lock ./
RUN yarn install --production=false
# Copiar el código de la aplicación
COPY . .
RUN pnpm install
RUN pnpm build
#ENV MYSQL_HOST=mysql
#ENV MYSQL_USER=root
#ENV MYSQL_PASSWORD=yourpassword
#ENV MYSQL_DB=yourdatabase
RUN yarn run build
# RUN
FROM node:lts-iron AS prod
WORKDIR /api
COPY package.json yarn.lock ./
RUN yarn install --production
COPY --from=builder /dist ./dist
# Exponer el puerto que la API usa
EXPOSE 3000
# Comando para correr la aplicación
CMD ["node", "dist/server/index.js"]

View File

@ -17,8 +17,8 @@ module.exports = {
server: {
hostname: process.env.HOSTNAME || "127.0.0.1",
port: process.env.PORT || 17777,
public_url: "https://...",
port: process.env.PORT || 3000,
public_url: "https://presupuestos.uecko.com",
},
uploads: {