Separacion de docker para producion y desarrollo

This commit is contained in:
2021-07-13 23:59:45 -04:00
parent 7723cad823
commit 4b71bc67aa
7 changed files with 92 additions and 5 deletions

23
backend/Dockerfile.prod Normal file
View File

@@ -0,0 +1,23 @@
FROM alpine:3
RUN apk update
RUN apk --no-cache add php8 php8-openssl php8-pdo php8-pdo_mysql \
php8-pdo_sqlite php8-pdo_pgsql php8-mbstring \
php8-phar php8-curl php8-dom php8-xml \
php8-xmlwriter php8-tokenizer \
zip unzip curl sqlite
RUN ln -s /usr/bin/php8 /usr/bin/php
RUN curl -s https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer
WORKDIR /lumen
COPY composer.json .
COPY composer.lock .
RUN composer install --no-ansi --no-dev --no-interaction --no-plugins \
--no-progress --no-scripts --optimize-autoloader
COPY . /lumen
ENTRYPOINT ["php", "-S", "0.0.0.0:8080", "-t", "public"]

39
docker-compose.prod.yml Normal file
View File

@@ -0,0 +1,39 @@
version: "3.9"
services:
backend:
build:
context: ./backend
dockerfile: ./Dockerfile.prod
ports:
- 8080:8080
frontend:
build:
context: ./frontend
dockerfile: ./Dockerfile.prod
ports:
- 4200:80
database:
image: postgres:13
restart: unless-stopped
environment:
POSTGRES_PASSWORD: admin
PGDATA: "/var/lib/postgresql/data/pgdata"
volumes:
- ./database/init:/docker-entrypoint-initdb.d
- database:/var/lib/postgresql/data
ports:
- 5400:5432
cache:
image: redis
restart: unless-stopped
volumes:
- cache:/data
volumes:
database:
cache:

View File

@@ -24,8 +24,16 @@ services:
build:
context: ./frontend
dockerfile: ./Dockerfile
volumes:
- ./frontend/src:/angular/src
- ./frontend/angular.json:/angular/angular.json
- ./frontend/karma.conf.js:/angular/karma.conf.js
- ./frontend/README.md:/angular/README.md
- ./frontend/tsconfig.app.json:/angular/tsconfig.app.json
- ./frontend/tsconfig.json:/angular/tsconfig.json
- ./frontend/tsconfig.spec.json:/angular/tsconfig.spec.json
ports:
- 4200:80
- 4200:4200
database:
image: postgres:13

View File

@@ -1,9 +1,8 @@
FROM node:alpine as build
WORKDIR /angular
COPY package.json package-lock.json /angular/
RUN npm install
COPY . /angular
RUN npm run build --prod
FROM nginx:stable-alpine
COPY --from=build /angular/dist/frontend /usr/share/nginx/html
ENTRYPOINT ["npm", "run", "start"]

10
frontend/Dockerfile.prod Normal file
View File

@@ -0,0 +1,10 @@
FROM node:alpine as build
WORKDIR /angular
COPY package.json package-lock.json /angular/
RUN npm install
COPY . /angular
RUN npm run build --prod
FROM nginx:stable-alpine
COPY --from=build /angular/dist/frontend /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf

8
frontend/nginx.conf Normal file
View File

@@ -0,0 +1,8 @@
server {
listen 80;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
}
}

View File

@@ -3,7 +3,7 @@
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"start": "ng serve --host 0.0.0.0",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test"