Skip to content

Commit

Permalink
feat(docker): added docker support
Browse files Browse the repository at this point in the history
  • Loading branch information
Ismaestro authored and Ismael Ramos committed Nov 2, 2017
1 parent ebf4817 commit 38a2f23
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.git
28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM node:8-alpine as builder

COPY package.json package-lock.json ./

RUN npm set progress=false && npm config set depth 0 && npm cache clean --force

## Storing node modules on a separate layer will prevent unnecessary npm installs at each build
RUN npm i && mkdir /ng-app && cp -R ./node_modules ./ng-app

WORKDIR /ng-app

COPY . .

## Build the angular app in production mode and store the artifacts in dist folder
RUN $(npm bin)/ng build --prod

FROM nginx:1.13.3-alpine

## Copy our default nginx config
COPY nginx/default.conf /etc/nginx/conf.d/

## Remove default nginx website
RUN rm -rf /usr/share/nginx/html/*

## From 'builder' stage copy over the artifacts in dist folder to default nginx public folder
COPY --from=builder /ng-app/dist /usr/share/nginx/html

CMD ["nginx", "-g", "daemon off;"]
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Example app with Angular 4 + Angular CLI + Angular Material + Travis CI
# Example app with Angular 4 + Angular CLI + Angular Material + Docker

> ### Base project made with much :heart: . Contains CRUD, official style guide, patterns, etc.
Expand Down Expand Up @@ -50,6 +50,8 @@ Live DEMO [here](http://angularexampleapp.com/)!

`npm run release` - Creates a new release using standard-version

`npm run docker` - Builds the docker image and run the container

**Windows: use precompilation to speed up**

`tsc --project tsconfig.json`
Expand All @@ -71,6 +73,16 @@ Live DEMO [here](http://angularexampleapp.com/)!
* Modernizr (browser features detection)
* Following the [best practices](https://angular.io/guide/styleguide)!

## Docker

You can build the image and run the container with Docker. The configuration is in the nginx folder if you want to change it.

`docker build -t angularexampleapp .`

`docker run -d -p 4200:80 angularexampleapp`

Thanks to [avatsaev](https://github.com/avatsaev/angular4-docker-example)!

## Travis CI
We use Travis CI to run this tasks in order:
* Linter
Expand Down
22 changes: 22 additions & 0 deletions nginx/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
server {
listen 80;

sendfile on;

default_type application/octet-stream;

gzip on;
gzip_http_version 1.1;
gzip_disable "MSIE [1-6]\.";
gzip_min_length 256;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_comp_level 9;

root /usr/share/nginx/html;

location / {
try_files $uri $uri/ /index.html =404;
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"lint": "ng lint",
"ci": "npm run lint && npm run test && npm run e2e",
"sme": "ng build && source-map-explorer dist/main.bundle.js",
"release": "standard-version && git push --follow-tags origin master"
"release": "standard-version && git push --follow-tags origin master",
"docker": "docker build -t angularexampleapp . && docker run -d -p 4200:80 angularexampleapp"
},
"private": true,
"engines": {
Expand Down

0 comments on commit 38a2f23

Please sign in to comment.