3.3 엄브렐라(umbrella) 프로젝트로 서비스 연결 (P267)
엄브렐라 프로젝트는 지정된 표준을 포함하는 기본 저장소 및 표준을 준수하는 다수의 "하위 프로젝트"로 구성된 프로젝트입니다.
엄브렐라 저장소 아래에 개별 마이크로서비스 저장소를 체크아웃하기 위해 오픈 소스 프로젝트 Faux 깃 서브모듈을 사용
마이크로서비스가 포함된 워크스페이스 저장소의 하위 폴더를 업데이트, 커밋, 푸시할 수 있는 완전한 기능의 저장소로 취급
깃 템플릿 복제
https://github.com/inadarei/microservices-workspace
로컬 개발 환경으로 복제
c:\msur> git clone https://github.com/myanjini/microservices-workspace.git
워크스페이스 구성요소 설정
ms-flights와 ms-reservations 마이크로서비스의 저장소를 워크스페이스의 구성요소로 표시
C:\msur\microservices-workspace\fgs.json
{
"ms-flights": {
"url": "https://github.com/naanjini/ms-flights.git"
},
"ms-reservations": {
"url": "https://github.com/naanjini/ms-reservations.git"
}
}
ms-flights와 ms-reservations 마이크로서비스를 워크스페이스로 가져옮
C:\msur\microservices-workspace> make update
git clone -b master https://github.com/myanjini/ms-flights.git ms-flights
Cloning into 'ms-flights'...
fatal: Remote branch master not found in upstream origin ⇐ git checkout -b "master" 후 git push origin master
git clone -b master https://github.com/myanjini/ms-reservations.git ms-reservations
Cloning into 'ms-reservations'...
C:\msur\microservices-workspace> make update
git clone -b master https://github.com/myanjini/ms-flights.git ms-flights
Cloning into 'ms-flights'...
git pull
Already up to date.
프로젝트 이름 변경
ms-flights, ms-reservations, microservices-workspace 모두 동일한 프로젝트 이름을 가지고 있어야 함
C:\msur\microservices-workspace\ms-flights\Makefile
C:\msur\microservices-workspace\ms-reservations\Makefile
C:\msur\microservices-workspace\Makefile
윈도우 환경에 맞춰서 쉘 스크립트를 수정
C:\msur\microservices-workspace\bin\start.cmd
@echo off
set PWD=%cd%
cd %PWD%/ms-flights
make start
cd %PWD%/ms-reservations
make start
cd %PWD%
make proxystart
set PWD=
exit
C:\msur\microservices-workspace\bin\stop.cmd
@echo off
set PWD=%cd%
cd %PWD%/ms-flights
make stop
cd %PWD%/ms-reservations
make stop
cd %PWD%
make proxystop
set PWD=
exit
Makefile 수정
… (생략) …
.PHONY: default
default: update start
.PHONY: start
start:
- ${PWD}/bin/start.cmd
.PHONY: stop
stop:
- ${PWD}/bin/stop.cmd
… (생략) …
라우팅 설정
Traefix 엣지 라우터를 사용해 마이크로서비스로의 라우팅을 제공 → 이를 위해 각 마이크로서비스의 docker-compose.yaml 파일에 Traefix 관련 레이블을 추가해 적절한 서비스로 트래픽이 라우팅되도록 구성
C:\msur\microservices-workspace\ms-flights\docker-compose.yml
version: '3.4'
services:
ms-flights:
container_name: ms-flights
labels:
- 'traefik.enable=true'
- 'traefik.http.routers.ms-flights.rule=PathPrefix(`/flights`)'
user: root # avoids ton of volume mounting headaches in dev mode.
build:
context: .
target: build
… (생략) …
C:\msur\microservices-workspace\ms-reservations\docker-compose.yml
version: '3.4'
services:
ms-reservations:
container_name: ms-reservations
labels:
- 'traefik.enable=true'
- 'traefik.http.routers.ms-reservations.rule=PathPrefix(`/reservations`)'
# ms-template-microservice:
# container_name: ms-template-microservice
build:
context: .
… (생략) …
Makefile 수정 - start, stop 스크립트 수정
C:\msur\microservices-workspace\Makefile
project:=ms-workspace-demo ⇐ ms-flights, ms-reservations 모두 동일한 프로젝트 이름을 가지고 있어야 함
ifeq ($(OS),Windows_NT)
CHECKOUT_BIN:=bin/checkout.exe
else
UNAME_S:=$(shell uname -s)
ifeq ($(UNAME_S),Linux)
CHECKOUT_BIN:=bin/checkout-linux
endif
ifeq ($(UNAME_S),Darwin)
CHECKOUT_BIN:=bin/checkout-mac
endif
endif
.PHONY: default
default: update start
.PHONY: start
start:
- ${PWD}/bin/start.cmd
.PHONY: stop
stop:
- ${PWD}/bin/stop.cmd
… (생략) …
마이크로서비스 실행 후 예약 및 항공권 정보 조회
아래 파일들의 개행문자가 LF로 설정되어 있는지 확인
C:\msur\microservices-workspace\ms-flights\shell\wait-for.sh
C:\msur\microservices-workspace\ms-flights\shell\start-dev.sh
C:\msur\microservices-workspace\ms-reservations\wait-for.sh
c:\msur\microservices-workspace> make start PWD=c:/msur/microservices-workspace
c:/msur/microservices-workspace/bin/start.cmd
make[1]: Entering directory `c:/msur/microservices-workspace/ms-flights'
docker-compose -p nb-demo up -d
Creating network "nb-demo_default" with the default driver
Creating ms-flights-db ... done
Creating ms-flights ... done
make[1]: Leaving directory `c:/msur/microservices-workspace/ms-flights'
make[1]: Entering directory `c:/msur/microservices-workspace/ms-reservations'
docker-compose -p ms-workspace-demo up -d
Creating network "ms-workspace-demo_default" with the default driver
Creating ms-redis ... done
Creating ms-reservations ... done
make[1]: Leaving directory `c:/msur/microservices-workspace/ms-reservations'
make[1]: Entering directory `c:/msur/microservices-workspace'
docker-compose -p msupandrunning up -d
Creating network "msupandrunning_default" with the default driver
Creating traefik ... done
make[1]: Leaving directory `c:/msur/microservices-workspace'
C:\msur\microservices-workspace> docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b228180c3d75 traefik:2.2 "/entrypoint.sh --we…" 7 seconds ago Up 4 seconds 0.0.0.0:9080->80/tcp, 0.0.0.0:9880->8080/tcp traefik
bcbf1f2ad17b ms-workspace-demo_ms-reservations "./wait-for.sh -t 60…" 13 seconds ago Up 11 seconds 0.0.0.0:7701->5000/tcp ms-reservations
37235b4fe895 redis:6-alpine "docker-entrypoint.s…" 15 seconds ago Up 12 seconds 6379/tcp ms-redis
d12b58364958 nb-demo_ms-flights "docker-entrypoint.s…" 24 seconds ago Up 19 seconds 0.0.0.0:7507->5501/tcp ms-flights
d0b321305a90 mysql:5.7 "docker-entrypoint.s…" 26 seconds ago Up 23 seconds 33060/tcp, 0.0.0.0:55172->3306/tcp ms-flights-db
c:\msur\microservices-workspace> curl http://127.127.127.127:9080/reservations?flight_id=werty
{
"12B": "dfdg"
}
c:\msur\microservices-workspace> curl "http://127.127.127.127:9080/flights?flight_no=AA34&departure_date_time=2020-05-17T13:20"
{"flight_id":"edcc03a4-7f4e-40d1-898d-bf84a266f1b9","origin_code":"LAX","destination_code":"DCA"}
마이크로서비스 종료
c:\msur\microservices-workspace> make stop PWD=c:/msur/microservices-workspace
댓글