Skip to content

Commit

Permalink
trying to push via travis
Browse files Browse the repository at this point in the history
  • Loading branch information
bersling committed May 10, 2018
1 parent 8e80974 commit 1673c60
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 3 deletions.
1 change: 1 addition & 0 deletions .dockerignore
@@ -0,0 +1 @@
**/node_modules
10 changes: 10 additions & 0 deletions .travis.yml
@@ -0,0 +1,10 @@
sudo: required
services:
- docker

deploy:
provider: script
script: bash docker/server.dockerfile
on:
branch: deploy

1 change: 1 addition & 0 deletions backend/package.json
Expand Up @@ -6,6 +6,7 @@
"scripts": {
"start": "cross-env NODE_ENV=development tsc && node dist/backend/src/server.js",
"prestart:prod": "tsc",
"build:prod": "tsc",
"start:prod": "cross-env NODE_ENV=production node dist/backend/src/server.js",
"dev": "cross-env NODE_ENV=development nodemon",
"test": "cross-env NODE_ENV=test jest --config=jest.json --coverage --runInBand --forceExit",
Expand Down
28 changes: 28 additions & 0 deletions docker/README.md
@@ -0,0 +1,28 @@
# Deployment

Deployment is done via docker swarm.

Docker Swarm helps you to scale your application.

## .dockerfile extension
Usually Dockerfiles are just named "Dockerfile", but that means you can just have one of them in a directory. I find it more practical to name them <name>.dockerfile, that way it's also easier to search for them in the IDE.

## Monolithic vs Service Oriented Deployment

You have two possibilities when it comes to deploying.

1) Monolithic: You build the frontend, then serve the built frontend through the backend via Express. Then the frontend requests resources from the backend like this: `/api/...`.
2) As Services: You treat frontend / backend more separated, with separated deployment processes. Then the frontend retrieves resources like this: `www.backend.com/api/...`.

What are respective advantages?

Advantages of combining them:
- No worrying about versioning. It can't happen that you deploy a backend that is incompatible with your frontend or vice versa.
- You only have to worry about one "service" (your application), you don't need to coordinate a more complex deployment

Separating them:
- You have a higher separation of concerns. This implies for example, that you don't need additional routing rules to separate frontend from backend. Otherwise you'll have to implement some kind of logic like "if `/api/<anything>` then serve backend, else serve index.html`. But it's not too complicated to set up this logic.
- You can guarantee higher availability for the frontend.
- Scales well: You can also divide the backend further into individual microservices, then you'll need a process to orchestrate anyways

In this project, I will go with the approach of deploying two separate services. However, I'll not set up a too complicated deployment process, that exactly coordinates that the deployment.
6 changes: 6 additions & 0 deletions docker/build-server.sh
@@ -0,0 +1,6 @@
#!/bin/bash bash

# run this from root of project
docker build -t tsmean/server -f docker/server.dockerfile .
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
docker push tsmean/server
14 changes: 14 additions & 0 deletions docker/client.dockerfile
@@ -0,0 +1,14 @@
# Run this from root of project (tsmean)
FROM node:8

COPY . /code

# Setup Shared
WORKDIR /code/shared
RUN npm install

# Setup Frontend
WORKDIR /code/frontend
RUN npm install
RUN npm run build:prod
RUN mv ./dist /code/server
7 changes: 7 additions & 0 deletions docker/docker-compose.yml
@@ -0,0 +1,7 @@
version: '3.5'
services:
tsmean-client:
image: tsmean/tsmean-client
tsmean-server:
image: tsmean/tsmean-server

19 changes: 19 additions & 0 deletions docker/server.dockerfile
@@ -0,0 +1,19 @@
# Run this from root of project (tsmean)
FROM node:8

COPY . /code

# Setup Shared
WORKDIR /code/shared
RUN npm install

# Setup Backend
WORKDIR /code/backend
RUN npm install
RUN npm run build:prod
ENV NODE_ENV production

EXPOSE 50500

## Run
CMD ["npm", "run", "start:prod"]
4 changes: 2 additions & 2 deletions frontend/package.json
Expand Up @@ -6,10 +6,10 @@
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"build:prod": "ng build --prod",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"deploy": "ng build --prod && firebase deploy"
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
Expand Down
Expand Up @@ -13,7 +13,7 @@ import {AnimalListDashboardListStore} from '../../animal-list/animal-list-dashbo
styleUrls: ['./animal-wrapper.component.css']
})
export class AnimalWrapperComponent implements OnInit {
private currentListId = 1;
currentListId = 1;
private animalsSubscription: Subscription;
animalIds: number[] = [];

Expand Down

0 comments on commit 1673c60

Please sign in to comment.