Skip to content

Commit 38a2f23

Browse files
IsmaestroIsmael Ramos
authored andcommitted
feat(docker): added docker support
1 parent ebf4817 commit 38a2f23

File tree

5 files changed

+67
-2
lines changed

5 files changed

+67
-2
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
.git

Dockerfile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM node:8-alpine as builder
2+
3+
COPY package.json package-lock.json ./
4+
5+
RUN npm set progress=false && npm config set depth 0 && npm cache clean --force
6+
7+
## Storing node modules on a separate layer will prevent unnecessary npm installs at each build
8+
RUN npm i && mkdir /ng-app && cp -R ./node_modules ./ng-app
9+
10+
WORKDIR /ng-app
11+
12+
COPY . .
13+
14+
## Build the angular app in production mode and store the artifacts in dist folder
15+
RUN $(npm bin)/ng build --prod
16+
17+
FROM nginx:1.13.3-alpine
18+
19+
## Copy our default nginx config
20+
COPY nginx/default.conf /etc/nginx/conf.d/
21+
22+
## Remove default nginx website
23+
RUN rm -rf /usr/share/nginx/html/*
24+
25+
## From 'builder' stage copy over the artifacts in dist folder to default nginx public folder
26+
COPY --from=builder /ng-app/dist /usr/share/nginx/html
27+
28+
CMD ["nginx", "-g", "daemon off;"]

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Example app with Angular 4 + Angular CLI + Angular Material + Travis CI
1+
# Example app with Angular 4 + Angular CLI + Angular Material + Docker
22

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

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

53+
`npm run docker` - Builds the docker image and run the container
54+
5355
**Windows: use precompilation to speed up**
5456

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

76+
## Docker
77+
78+
You can build the image and run the container with Docker. The configuration is in the nginx folder if you want to change it.
79+
80+
`docker build -t angularexampleapp .`
81+
82+
`docker run -d -p 4200:80 angularexampleapp`
83+
84+
Thanks to [avatsaev](https://github.com/avatsaev/angular4-docker-example)!
85+
7486
## Travis CI
7587
We use Travis CI to run this tasks in order:
7688
* Linter

nginx/default.conf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
server {
2+
listen 80;
3+
4+
sendfile on;
5+
6+
default_type application/octet-stream;
7+
8+
gzip on;
9+
gzip_http_version 1.1;
10+
gzip_disable "MSIE [1-6]\.";
11+
gzip_min_length 256;
12+
gzip_vary on;
13+
gzip_proxied expired no-cache no-store private auth;
14+
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
15+
gzip_comp_level 9;
16+
17+
root /usr/share/nginx/html;
18+
19+
location / {
20+
try_files $uri $uri/ /index.html =404;
21+
}
22+
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"lint": "ng lint",
1414
"ci": "npm run lint && npm run test && npm run e2e",
1515
"sme": "ng build && source-map-explorer dist/main.bundle.js",
16-
"release": "standard-version && git push --follow-tags origin master"
16+
"release": "standard-version && git push --follow-tags origin master",
17+
"docker": "docker build -t angularexampleapp . && docker run -d -p 4200:80 angularexampleapp"
1718
},
1819
"private": true,
1920
"engines": {

0 commit comments

Comments
 (0)