-
Notifications
You must be signed in to change notification settings - Fork 915
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(docker): dockerfile for production
Added a multi-stage Production.Dockerfile to allow serving of a docker image Added a Production.docker-compose to run and build the Production.Dockerfile Updated the server.js to take ports from the environment
- Loading branch information
1 parent
6adbfed
commit 4f850fe
Showing
3 changed files
with
52 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
FROM node:11.1.0 as npm_builder | ||
# Set the entrypoint as bin bash incase we want to inspect the container | ||
ENTRYPOINT ["/bin/bash"] | ||
# Manually copy the package.json | ||
COPY ./package.json /usr/src/app/package.json | ||
COPY ./package-lock.json /usr/src/app/package-lock.json | ||
COPY cypress /usr/src/app/cypress | ||
# Set the work directory to where we copied our source files | ||
WORKDIR /usr/src/app | ||
# Install all of our dependencies | ||
RUN npm install | ||
|
||
FROM npm_builder as builder | ||
# Copy the app excluding everything in the .dockerignore | ||
COPY . /usr/src/app | ||
# Put node_modules into the path, this will purely be used for accessing the angular cli | ||
ENV PATH /usr/src/app/node_modules/.bin:$PATH | ||
# Set the work directory to where we copied our source files | ||
WORKDIR /usr/src/app | ||
# Build our distributable | ||
RUN npm run build:prod | ||
|
||
FROM node:11.1.0 as production | ||
# Copy the dist folder from builder | ||
COPY --from=builder /usr/src/app/dist /usr/src/app/dist | ||
COPY --from=builder /usr/src/app/server.js /usr/src/app/server.js | ||
# Set the work directory to where we copied our source files | ||
WORKDIR /usr/src/app | ||
RUN npm install compression@1.7.3 | ||
RUN npm install express@4.16.4 | ||
# Create 2 empty environment variables | ||
ENV CONTEXT= | ||
ENV PORT= | ||
# Run the node server which should be used for production | ||
CMD ["node", "server.js"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
version: '3.7' | ||
services: | ||
web: | ||
image: persistentcontainerregistry.azurecr.io/brothinjord.client | ||
container_name: b_client | ||
build: | ||
context: . | ||
dockerfile: Production.Dockerfile | ||
target: production | ||
environment: | ||
- CONTEXT=angular-ngrx-material-starter | ||
- PORT=150 | ||
ports: | ||
- '100:150' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
const express = require('express'); | ||
const compression = require('compression'); | ||
|
||
const CONTEXT = '/angular-ngrx-material-starter'; | ||
const PORT = 4000; | ||
const CONTEXT = `/${process.env.CONTEXT || 'angular-ngrx-material-starter'}`; | ||
const PORT = process.env.PORT || 4000; | ||
|
||
const app = express(); | ||
|
||
app.use(compression()); | ||
app.use(CONTEXT, express.static(__dirname + '/dist')); | ||
app.use('/', express.static(__dirname + '/dist')); | ||
app.listen(PORT, () => console.log(`App running on localhost:${PORT}/${CONTEXT}`)); | ||
app.listen(PORT, () => console.log(`App running on http://localhost:${PORT}${CONTEXT}`)); |