Skip to content

Commit

Permalink
docker multi-stage implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilioMartel committed Jan 18, 2023
1 parent 42d8f42 commit 742f3b6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 24 deletions.
4 changes: 3 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ Dockerfile

.git
.gitignore
.dockerignore
.dockerignore

README.md
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules
node_modules

package-lock.json
33 changes: 16 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
# FROM --platform=linux/amd64 node:19.2-alpine3.16
# FROM --platform=$BUILDPLATFORM node:19.2-alpine3.16
FROM node:19.2-alpine3.16

# cd app
# Dependencias de desarrollo
FROM node:19.2-alpine3.16 as deps
WORKDIR /app

# Dest /app
COPY package.json ./

# Instalar las dependencias
RUN npm install

# Dest /app
# Tests y Build
FROM node:19.2-alpine3.16 as builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

# Realizar testing
RUN npm run test

# Eliminar archivos/directorios no necesarios en PROD
RUN rm -rf tests && rm -rf node_modules

# Unicamente las dependencias de PROD
# Dependencias de producción
FROM node:19.2-alpine3.16 as prod-deps
WORKDIR /app
COPY package.json ./
RUN npm install --prod

# Comando run de la imagen
# Ejecutar la App
FROM node:19.2-alpine3.16 as runner
WORKDIR /app
COPY --from=prod-deps /app/node_modules ./node_modules
COPY app.js ./
COPY tasks/ ./tasks
CMD [ "node", "app.js" ]
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ npm start

### CMD
```
# docker buildx build \
# --platform linux/amd64,linux/arm64 \
# -t emmartel/cron-ticker --push .
docker buildx build \
--platform linux/amd64,linux/arm64 \
-t emmartel/cron-ticker --push .
```
### Dockerfile
```
# /app /usr /lib
# FROM --platform=linux/amd64 node:19.2-alpine3.16
# FROM node:19.2-alpine3.16
FROM --platform=$BUILDPLATFORM node:19.2-alpine3.16
# FROM --platform=$BUILDPLATFORM node:19.2-alpine3.16
FROM node:19.2-alpine3.16
```

0 comments on commit 742f3b6

Please sign in to comment.