Skip to content

Commit c102335

Browse files
committed
able to build angular docker image successfully
1 parent 2d9cf57 commit c102335

File tree

10 files changed

+125
-41
lines changed

10 files changed

+125
-41
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Build image:
1818
`$ docker build --tag image_name .`
1919

2020
Docker run the image on container
21-
`$ docker run --detach -p HOST_PORT:Container_PORT image_name`
21+
`$ docker run --name container_name --detach -p HOST_PORT:Container_PORT image_name`
2222

2323
Docker run image and ssh to the container and remove container on terminal Exit
2424
`$ docker run -it --rm image_name /bin/bash`

api/.dockerignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
__pycache__
1+
__pycache__/
2+
models/

api/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
__pycache__/
33
*.py[cod]
44
*$py.class
5+
models/
56

67
# C extensions
78
*.so

api/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ attrs==19.3.0
33
certifi==2019.9.11
44
Click==7.0
55
Flask==1.1.1
6-
flask-restplus==0.13.0
6+
flask-restplus==0.10.1
77
gunicorn==20.0.4
88
importlib-metadata==0.23
99
itsdangerous==1.1.0

docker-compose.yml

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,55 @@ version: '3.7'
22

33
services:
44

5-
flask-api:
6-
shm_size: '1000000000'
7-
image: api_img
8-
container_name: ai_api
9-
build:
10-
context: api
11-
tty: true
5+
# flask-api:
6+
# image: api_img
7+
# container_name: ai_api
8+
# build:
9+
# context: api
10+
# tty: true
11+
# volumes:
12+
# - ~/docker_app/api/logs:/app/logs
13+
# - ./api/models:/app/models
14+
# environment:
15+
# MONGODB_DATABASE: ai_evaluator
16+
# MONGODB_USERNAME: admin
17+
# MONGODB_PASSWORD: mohan
18+
# MONGODB_HOSTNAME: mongodb
19+
# AUTH_DB: admin
20+
21+
web_app:
22+
image: web_app_img
23+
container_name: web_app
24+
build:
25+
context: web
1226
volumes:
13-
- ~/docker_app/api:/app/logs
14-
expose:
15-
- 5000
16-
17-
nginx:
18-
build: nginx
19-
image: nginx_img
20-
container_name: ai_nginx
21-
tty: true
27+
- ./web/dist/web/:/usr/share/nginx/html:ro
2228
ports:
2329
- '80:80'
24-
volumes:
25-
- ~/docker_app/nginx:/var/log/nginx/
30+
31+
# mongodb:
32+
# image: mongo:4.0.8
33+
# container_name: mongodb
34+
# restart: unless-stopped
35+
# command: mongod --auth
36+
# environment:
37+
# MONGO_INITDB_ROOT_USERNAME: admin
38+
# MONGO_INITDB_ROOT_PASSWORD: mohan
39+
# MONGO_INITDB_DATABASE: ai_evaluator
40+
# MONGODB_DATA_DIR: /data/db
41+
# MONDODB_LOG_DIR: /dev/null
42+
# volumes:
43+
# - ~/docker_app/mongodb:/data/db
44+
45+
# nginx:
46+
# build: nginx
47+
# image: nginx_img
48+
# container_name: ai_nginx
49+
# depends_on:
50+
# - flask-api
51+
# tty: true
52+
# ports:
53+
# - '80:80'
54+
# - '443:443'
55+
# volumes:
56+
# - ~/docker_app/nginx/logs:/var/log/nginx

nginx/Dockerfile

Lines changed: 0 additions & 10 deletions
This file was deleted.

nginx/nginx.conf

Lines changed: 0 additions & 9 deletions
This file was deleted.

web/Dockerfile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
### STAGE 1: Build ###
2+
3+
ARG APP_NAME=ng-app
4+
## We label our stage as ‘builder’ and we will be using 'builder' in the next stage
5+
FROM node:10-alpine as builder
6+
7+
ARG APP_NAME
8+
ENV APP $APP_NAME
9+
10+
RUN mkdir $APP
11+
WORKDIR $APP
12+
13+
COPY package.json package-lock.json ./
14+
15+
## Storing node modules on a separate layer will prevent unnecessary npm installs at each build
16+
## RUN npm ci && mkdir /ng-app && mv ./node_modules ./ng-app
17+
RUN npm ci
18+
19+
# Copying the code to APP directory
20+
COPY . .
21+
22+
## Build the angular app in production mode and store the artifacts in dist folder
23+
RUN npm run ng build -- --prod --output-path=dist
24+
25+
26+
27+
### STAGE 2: Setup ###
28+
29+
FROM nginx:1.14.1-alpine
30+
RUN apk add --no-cache bash
31+
ARG APP_NAME
32+
ENV APP $APP_NAME
33+
34+
## Copy our default nginx config which will replace the existing default.conf
35+
COPY nginx/default.conf /etc/nginx/conf.d/
36+
37+
## Remove default nginx website
38+
RUN rm -rf /usr/share/nginx/html/*
39+
40+
## From ‘builder’ stage copy over the artifacts in dist folder to default nginx public folder
41+
COPY --from=builder $APP/dist /usr/share/nginx/html
42+
43+
CMD ["nginx", "-g", "daemon off;"]

web/nginx/default.conf

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

web/src/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html lang="en">
33
<head>
44
<meta charset="utf-8">
5-
<title>Web</title>
5+
<title>Web 1</title>
66
<base href="/">
77
<meta name="viewport" content="width=device-width, initial-scale=1">
88
<link rel="icon" type="image/x-icon" href="favicon.ico">

0 commit comments

Comments
 (0)