Skip to content

Commit

Permalink
dockerization and k8s
Browse files Browse the repository at this point in the history
  • Loading branch information
danmgs committed Feb 13, 2019
1 parent 4eab79c commit 4e787e9
Show file tree
Hide file tree
Showing 18 changed files with 14,069 additions and 28 deletions.
26 changes: 8 additions & 18 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
version: '3'
services:
mongo:
my-mongo-service:
container_name: mongo
image: mongo
restart: always
ports:
- "27017:27017"
# environment:
# ME_CONFIG_MONGODB_ADMINUSERNAME: root
# ME_CONFIG_MONGODB_ADMINPASSWORD: example
server:
# ME_CONFIG_MONGODB_ADMINPASSWORD: example
my-server-api-service:
container_name: server
build:
dockerfile : Dockerfile.dev
Expand All @@ -18,28 +18,18 @@ services:
- "30001:30001"
environment:
- SERVER_API_PORT=30001
# - MONGODB_URI=mongodb://127.0.0.1:27017
- MONGODB_URI=mongodb://mongo:27017
# volumes:
# - /app/node_modules #do not touch this dir in container
# - ./server:/app # map server to app in container
- MONGODB_URI=mongodb://my-mongo-service:27017
restart: always
depends_on:
- mongo
client:
- my-mongo-service
client-service:
container_name: client
build:
dockerfile : Dockerfile.dev
context: ./public
ports:
- "4200:4200"
# environment:
# - API_URL=localhost
# - API_PORT=30001
# volumes:
# - /app/node_modules #do not touch this dir in container
# - ./public:/app # map public to app in container
restart: always
depends_on:
- server

- my-server-api-service
21 changes: 21 additions & 0 deletions k8s/client-web-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: client-web-deployment
namespace: weatherapp
spec:
replicas: 1
selector:
matchLabels:
component: client-web
template:
metadata:
labels:
component: client-web
spec:
containers:
- name: client-web-cont
image: danmgs/weatherapp-client:latest
ports:
- containerPort: 4200
args: ["npm", "run" , "start-for-k8s"]
14 changes: 14 additions & 0 deletions k8s/client-web-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: Service
metadata:
name: client-web-service
namespace: weatherapp
spec:
selector:
component: client-web
ports:
- port: 4200
targetPort: 4200
nodePort: 31515
type: NodePort

6 changes: 6 additions & 0 deletions k8s/create-namespace-weatherapp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
kind: Namespace
metadata:
name: weatherapp
labels:
component: weatherapp
11 changes: 11 additions & 0 deletions k8s/database-persistent-volume-claim.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: database-persistent-volume-claim
namespace: weatherapp
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
27 changes: 27 additions & 0 deletions k8s/mongodb-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: mongodb-deployment
namespace: weatherapp
spec:
replicas: 1
selector:
matchLabels:
component: mongodatabase
template:
metadata:
labels:
component: mongodatabase
spec:
volumes:
- name: mongo-storage
persistentVolumeClaim:
claimName: database-persistent-volume-claim
containers:
- name: mongodb-cont
image: mongo
ports:
- containerPort: 27017
volumeMounts:
- name: mongo-storage
mountPath: c/data-mongo
12 changes: 12 additions & 0 deletions k8s/mongodb-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Service
metadata:
name: mongodb-service
namespace: weatherapp
spec:
selector:
component: mongodatabase
ports:
- port: 27017
targetPort: 27017

23 changes: 23 additions & 0 deletions k8s/server-api-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: server-api-deployment
namespace: weatherapp
spec:
replicas: 1
selector:
matchLabels:
component: server-api
template:
metadata:
labels:
component: server-api
spec:
containers:
- name: server-api-cont
image: danmgs/weatherapp-server:latest
ports:
- containerPort: 30001
env:
- name: MONGODB_URI
value: mongodb://mongodb-service
13 changes: 13 additions & 0 deletions k8s/server-api-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: server-api-service
namespace: weatherapp
spec:
selector:
component: server-api
ports:
- port: 30001
targetPort: 30001
# nodePort: 31516
# type: NodePort
2 changes: 1 addition & 1 deletion public/Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ COPY package.json ./
RUN npm install
COPY . .

CMD ["npm", "start"]
CMD ["npm", "run", "start"]
24 changes: 22 additions & 2 deletions public/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,24 @@
"with": "src/environments/environment.prod.ts"
}
]
}
},
"production-k8s": {
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": false,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": false,
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod-k8s.ts"
}
]
}
}
},
"serve": {
Expand All @@ -65,7 +82,10 @@
"configurations": {
"production": {
"browserTarget": "my-weather-app:build:production"
}
},
"production-k8s": {
"browserTarget": "my-weather-app:build:production-k8s"
}
}
},
"extract-i18n": {
Expand Down
Loading

0 comments on commit 4e787e9

Please sign in to comment.