Skip to content

Commit

Permalink
Merge branch 'dockerization-branch'
Browse files Browse the repository at this point in the history
  • Loading branch information
danmgs committed Mar 16, 2020
2 parents 0dcacf4 + dca3420 commit ca19333
Show file tree
Hide file tree
Showing 59 changed files with 1,259 additions and 19,319 deletions.
12 changes: 12 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
COMPOSE_PROJECT_NAME=my-weather-app

NODE_ENV=production
ENV_SERVER_API_MONGODB_URI=mongodb://mongo-service:27017
ENV_SERVER_API_ALLOW_HOSTS=*
ENV_SERVER_API_PORT=30001

ENV_WEBAPP_NODE_ENV=prod
ENV_WEBAPP_PORT=80

ENV_FRONTEND_IMAGE_TAG=danmgs/weather-app-frontend
ENV_BACKEND_IMAGE_TAG=danmgs/weather-app-backend
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ npm-debug.log
testem.log
/typings
yarn-error.log
*.lock.json

# e2e
/e2e/*.js
Expand Down
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
language: node_js
node_js:
- "10"

# whitelist
branches:
only:
- /.*/

script:
- sh ./travis-script.sh

notifications:
- email: false
75 changes: 75 additions & 0 deletions Dockerrun.aws.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"AWSEBDockerrunVersion": 2,
"volumes": [
{
"name": "mongodata",
"host": {
"sourcePath": "/var/app/current/mongodata/data/db"
}
}
],
"containerDefinitions": [
{
"name": "mongo-service",
"image": "mongo:latest",
"hostname": "mongo-service",
"essential": true,
"memory": 512,
"mountPoints": [
{
"sourceVolume": "mongodata",
"containerPath": "/data/db"
}
]
},
{
"name": "app-backend",
"image": "danmgs/weather-app-backend:1.1",
"hostname": "app-backend",
"environment": [
{
"name": "NODE_ENV",
"value": "production"
},
{
"name": "ENV_SERVER_API_MONGODB_URI",
"value": "mongodb://mongo-service:27017"
},
{
"name": "ENV_SERVER_API_ALLOW_HOSTS",
"value": "*"
},
{
"name": "ENV_SERVER_API_PORT",
"value": "30001"
}
],
"essential": true,
"memory": 256,
"portMappings": [
{
"hostPort": 30001,
"containerPort": 30001
}
],
"links": [
"mongo-service"
]
},
{
"name": "app-frontend",
"image": "danmgs/weather-app-frontend:1.1",
"essential": true,
"memory": 128,
"portMappings": [
{
"hostPort": 80,
"containerPort": 80
}
],
"links": [
"app-backend"
]
}
]
}
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# MY WEB APP - MEAN STACK

# MY WEB APP - MEAN STACK [![Build Status](https://travis-ci.org/danmgs/My-weather-app.svg?branch=master)](https://travis-ci.org/danmgs/My-weather-app)

A WEB application providing weather, news, financial information.

Expand Down Expand Up @@ -52,7 +53,7 @@ npm start

5. Once started, to test server urls api :
```
http://localhost:3000/api/users
http://localhost:30001/api/serverhealth
```

6. To launch unit tests (server must be shutdown, i.e no "**npm start**"), make sure mongodb is started.
Expand Down Expand Up @@ -108,7 +109,7 @@ To get more help on the Angular CLI use `ng help` or go check out the [Angular C

# <span style="color:red">TASKS LIST</span>

- [x] CORS issue between backend / frontend: No 'Access-Control-Allow-Origin' header is present on the requested resource.
- [x] CORS issue between backend / frontend: No 'Access-Control-Allow-Origin' header is present on the requested resource.
[Help jsonp here](https://codecraft.tv/courses/angular/http/jsonp-with-observables/).
- [ ] Langages fr/eng for web pages.
- [ ] Reorganize menu labels Weather, Finance ...
Expand Down
36 changes: 36 additions & 0 deletions docker-compose-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
version: '3'
services:

mongo-service:
image: mongo:latest
volumes:
- mongodata:/data/db
restart: always

app-backend:
container_name: app-backend
image: danmgs/weather-app-backend:1.1
environment:
NODE_ENV: production
ENV_SERVER_API_MONGODB_URI: mongodb://mongo-service:27017
ENV_SERVER_API_ALLOW_HOSTS: "*"
ENV_SERVER_API_PORT: 30001
ports:
- "30001:30001"
depends_on:
- mongo-service
restart: always

app-frontend:
container_name: app-frontend
image: danmgs/weather-app-frontend:1.1
working_dir: /usr/src/app
ports:
- "80:80"
depends_on:
- app-backend
restart: always

volumes:
mongodata:
45 changes: 45 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
version: '3'
services:

mongo-service:
image: mongo:latest
volumes:
- mongodata:/data/db
restart: always

app-backend:
build:
context: ./server
dockerfile: Dockerfile
container_name: app-backend
image: ${ENV_BACKEND_IMAGE_TAG}
environment:
NODE_ENV: ${NODE_ENV}
ENV_SERVER_API_MONGODB_URI: ${ENV_SERVER_API_MONGODB_URI}
ENV_SERVER_API_ALLOW_HOSTS: ${ENV_SERVER_API_ALLOW_HOSTS}
ENV_SERVER_API_PORT: ${ENV_SERVER_API_PORT}
ports:
- ${ENV_SERVER_API_PORT}:${ENV_SERVER_API_PORT}
depends_on:
- mongo-service
restart: always

app-frontend:
build:
context: ./public
dockerfile: Dockerfile
args:
- NODE_ENV=${ENV_WEBAPP_NODE_ENV} # development / staging / prod
container_name: app-frontend
image: ${ENV_FRONTEND_IMAGE_TAG}
working_dir: /usr/src/app
ports:
- ${ENV_WEBAPP_PORT}:${ENV_WEBAPP_PORT}
depends_on:
- app-backend
restart: always

# https://github.com/docker-library/mongo/issues/74#issuecomment-350034758
volumes:
mongodata:
18 changes: 18 additions & 0 deletions docker-push.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Purpose: script to push image into your docker hub. Must be logged in first.
# Usage: powershell docker-push.ps1 -tag <version>
Param([parameter(Mandatory=$true,
HelpMessage="Enter docker tag version")]
$tag)

write-output "Entered tag = $tag"

# Build the images using tag name specify via image attributes in the docker-compose files.
docker-compose build

# Tags the images
docker tag danmgs/weather-app-frontend danmgs/weather-app-frontend:$tag
docker tag danmgs/weather-app-backend danmgs/weather-app-backend:$tag

# Push the images
docker push danmgs/weather-app-frontend:$tag
docker push danmgs/weather-app-backend:$tag
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: /data/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
Loading

0 comments on commit ca19333

Please sign in to comment.