Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adicionar Dockerfile de Produção(+Desenvolvimento) #58

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
node_modules
npm-debug.log
npm-debug.log
Dockerfile*
docker-compose*
.dockerignore
.git
.gitignore
README.md
LICENSE
.vscode
vitest
35 changes: 35 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
FROM node:18.9.0-alpine3.16 AS builder

ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}

WORKDIR /deps

# Install app dependencies
COPY package*.json ./
COPY tsconfig.json ./

# Install dependencies
RUN if [ "$NODE_ENV" = "production" ] ; then npm ci --omit=dev --ignore-scripts; else npm ci ; fi

# ============================================================
# Application
# ============================================================

FROM node:18.9.0-alpine3.16 as application

ARG NODE_ENV

# Set the working directory
WORKDIR /app

# Copy the node_modules from the builder stage
COPY --from=builder /deps/node_modules ./node_modules

# Copy the app source code
COPY . .

# If production we need Typescript to build our app
RUN if [ "$NODE_ENV" = "production" ] ; then npm install typescript -g && npm run build ; fi

CMD exec npm run start:${NODE_ENV}
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
APP_NAME=discord-bot
PORT=4000

dev-build:
docker build --build-arg NODE_ENV=development -t $(APP_NAME) .

dev-start:
docker run --rm -it -v $(pwd):/app -e NODE_ENV=development -p=$(PORT):$(PORT) --name="$(APP_NAME)" $(APP_NAME)

prod-build:
docker build --build-arg NODE_ENV=production -t $(APP_NAME) .

prod-start:
docker run --rm -it -v $(pwd):/app -e NODE_ENV=production -p=$(PORT):$(PORT) --name="$(APP_NAME)" $(APP_NAME)

stop:
docker stop $(APP_NAME); docker rm $(APP_NAME)
Loading