Skip to content
This repository was archived by the owner on Mar 25, 2018. It is now read-only.

POLY1_INFRA_HOUR2 #33

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Dockerfile_Auth
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM openjdk:8 AS gradle-builder

WORKDIR /app

COPY . .

WORKDIR authorization

RUN ../gradlew build

FROM openjdk:8-jre

WORKDIR /root/

COPY --from=gradle-builder /app/authorization/build/libs/authorization-0.0.1-SNAPSHOT.jar .

CMD ["java","-jar","authorization-0.0.1-SNAPSHOT.jar"]
17 changes: 17 additions & 0 deletions Dockerfile_Comm
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM openjdk:8 AS gradle-builder

WORKDIR /app

COPY . .

WORKDIR communication

RUN ../gradlew build

FROM openjdk:8-jre

WORKDIR /root/

COPY --from=gradle-builder /app/communication/build/libs/communication-0.0.1-SNAPSHOT.jar .

CMD ["java","-jar","communication-0.0.1-SNAPSHOT.jar"]
17 changes: 17 additions & 0 deletions Dockerfile_Config_Server
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM openjdk:8 AS gradle-builder

WORKDIR /app

COPY . .

WORKDIR config-server

RUN ../gradlew build

FROM openjdk:8-jre

WORKDIR /root/

COPY --from=gradle-builder /app/config-server/build/libs/config-server-0.0.1-SNAPSHOT.jar .

CMD ["java","-jar","config-server-0.0.1-SNAPSHOT.jar"]
17 changes: 17 additions & 0 deletions Dockerfile_Eureka_Server
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM openjdk:8 AS gradle-builder

WORKDIR /app

COPY . .

WORKDIR eureka-server

RUN ../gradlew build

FROM openjdk:8-jre

WORKDIR /root/

COPY --from=gradle-builder /app/eureka-server/build/libs/eureka-server-0.0.1-SNAPSHOT.jar .

CMD ["java","-jar","eureka-server-0.0.1-SNAPSHOT.jar"]
17 changes: 17 additions & 0 deletions Dockerfile_Zuul_Server
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM openjdk:8 AS gradle-builder

WORKDIR /app

COPY . .

WORKDIR zuul-server

RUN ../gradlew build

FROM openjdk:8-jre

WORKDIR /root/

COPY --from=gradle-builder /app/zuul-server/build/libs/zuul-server-0.0.1-SNAPSHOT.jar .

CMD ["java","-jar","zuul-server-0.0.1-SNAPSHOT.jar"]
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
#INFRA
## Hour 1
- [X] (2pt) Create a dockerfile for each projects in `settings.gradle`
- [ ] (1pt) Create a gradle task to build all docker, the task could look like `./gradlew clean build buildDocker -x test`
- [ ] (0.5pt) Create a gradle task to build single docker images when you are working in only one module
- [X] (2pt) Create a docker-compose version 3+ file to orchestrate de booting of all modules


# Java micro-services

## Build
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import static com.ship.authorization.service.UsersService.GetRank;
import static com.ship.authorization.service.UsersService.ROLE_ADMIRAL;
import static com.ship.authorization.service.UsersService.ROLE_CREWMAN;

Expand All @@ -40,7 +41,7 @@ public void checkAccess(Authentication authentication, @RequestBody ActionDto ac

for (GrantedAuthority grantedAuthority : userDetails.getAuthorities()){
if (grantedAuthority.getAuthority().equals(ROLE_CREWMAN)) {
if (recipientRole.contains(ROLE_ADMIRAL)) {
if (GetRank(recipientRole) - 1 >= 2) {
throw new ForbiddenAccessException();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ public class UsersService {
public static final String ROLE_ENSIGN = "ROLE_ENSIGN";
public static final String ROLE_CREWMAN = "ROLE_CREWMAN";

public static final int GetRank(String role) {
if (role.equals(ROLE_ADMIRAL)) {
return 7;
} else if (role.equals(ROLE_VICE_ADMIRAL)) {
return 6;
} else if (role.equals(ROLE_CAPTAIN)) {
return 5;
} else if (role.equals(ROLE_COMMANDER)) {
return 4;
} else if (role.equals(ROLE_LIEUTENANT)) {
return 3;
} else if (role.equals(ROLE_ENSIGN)) {
return 2;
} else {
return 1;
}
}

private Map<String, String> users = new HashMap<>();

public UsersService() {
Expand Down
2 changes: 1 addition & 1 deletion config-server/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ security.user:
---
spring:
profiles: native
cloud.config.server.native.search-locations: file:///${user.home}/Documents/wilau2/cs-games-2018-relay-cloud/config-server/config
cloud.config.server.native.search-locations: file:///${user.home}/git/csgames/infra-perso/config-server/config

eureka:
client:
Expand Down
48 changes: 48 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
version: "3"
services:
authorization:
build:
context: ./
dockerfile: Dockerfile_Auth
ports:
- 8090:8090

communication:
build:
context: ./
dockerfile: Dockerfile_Comm
ports:
- 8100:8100

config-server:
build:
context: ./
dockerfile: Dockerfile_Config_Server
ports:
- 8888:8888
depends_on:
- redis

eureka-server:
build:
context: ./
dockerfile: Dockerfile_Eureka_Server
ports:
- 8082:8082
depends_on:
- config-server

zuul-server:
build:
context: ./
dockerfile: Dockerfile_Zuul_Server
ports:
- 9090:9090
depends_on:
- authorization
- communication

redis:
image: redis
ports:
- 6379:6379