Amazon Lightsail 기반 컨테이너 웹 앱 배포
시작 안내서
모듈 4: 새 컨테이너 버전 배포
이 모듈에서는 이미 배포된 컨테이너를 업데이트하는 방법을 알아봅니다
소개
애플리케이션은 사용하는 동안 여러 번 업데이트됩니다. 이 모듈에서는 배포를 업데이트하는 방법과 새 애플리케이션 버전에 문제가 있는 경우 배포를 롤백하는 방법을 알아봅니다.
학습 내용
- 애플리케이션 코드 업데이트 및 새 로컬 컨테이너 이미지 구축
- 업데이트된 컨테이너 이미지를 Amazon Lightsail로 푸시
- 새 애플리케이션 버전 배포
- 문제가 있는 경우 배포를 롤백하기
소요 시간
10분
모듈 사전 요구 사항
- 관리자 수준의 액세스 권한이 있는 AWS 계정**
- 권장 브라우저: 최신 버전의 Chrome 또는 Firefox
[**]생성된 지 24시간이 지나지 않은 계정은 이 자습서를 완료하는 데 필요한 서비스에 액세스할 권한이 아직 없을 수 있습니다.
구현
애플리케이션 코드 업데이트 및 새 컨테이너 이미지 구축
애플리케이션 첫 페이지의 도시 이름이 잘못되어 수정이 필요하다고 가정해 보겠습니다.
code/templates/index.html 파일을 엽니다. "라스베이거스"를 검색하고 "파리"로 교체합니다.
그런 다음 모듈 2에 설명된 대로 컨테이너를 구축하고 테스트합니다. 터미널을 열고 다음 명령을 입력합니다.
# build the container
docker build -t demo-flask-signup .
# run the container for local testing
docker run -p 8080:80 \
--rm \
-v ~/.aws:/root/.aws \
demo-flask-signup:latest
이제 컨테이너가 실행 중이며, 브라우저를 열고 http://localhost:8080에서 가리킵니다. 새 도시 이름으로 애플리케이션 홈 화면이 표시되어야 합니다.

업데이트된 컨테이너 이미지를 Amazon Lightsail로 푸시
이제 컨테이너가 구축되었으며 다음 단계는 새 컨테이너 이미지를 Amazon Lightsail로 푸시하는 것입니다.
터미널을 열고 다음 명령을 입력합니다.
aws lightsail push-container-image \
--region eu-west-3 \
--service-name signup-application \
--label latest \
--image demo-flask-signup:latest
# the command outputs the following lines
df0f7d33bb59: Pushed
951ffe99d911: Pushed
cee40450fe90: Pushed
1327150a5178: Pushed
4bc5d67b6427: Layer already exists
ce8ffb5c560e: Layer already exists
4226d5d0360f: Layer already exists
9d1af766c818: Layer already exists
d97733c0a3b6: Layer already exists
c553c6ba5f13: Layer already exists
48b4a40de359: Layer already exists
ace9ed9bcfaf: Layer already exists
764055ebc9a7: Layer already exists
Digest: sha256:42d2e19ee7340bc7f028593318e9b7406e9e70fb4785618d3f6c78443e097a87
Image "demo-flask-signup:latest" registered.
Refer to this image as ":signup-application.latest.2" in deployments.
출력의 마지막 줄은 컨테이너의 내부 이름을 표시합니다. 컨테이너를 컨테이너 서비스에 배포하려면 이 이름이 필요하므로 메모해 두시기 바랍니다. 이후 단계에서 컨테이너 이름에 액세스하려는 경우, 다음 명령을 입력합니다.
aws lightsail get-container-images \
--region eu-west-3 \
--service-name signup-application
# the command outputs the following lines
{
"containerImages": [
{
"image": ":signup-application.latest.2",
"digest": "sha256:42d2e19ee7340bc7f028593318e9b7406e9e70fb4785618d3f6c78443e097a87",
"createdAt": "2021-07-17T18:34:00+02:00"
},
{
"image": ":signup-application.latest.1",
"digest": "sha256:128f84907d30a1fb47c1888720485fa8050cc99bc1034e0cfd1f46d3b6e57e19",
"createdAt": "2021-07-17T15:11:49+02:00"
}
]
}
"상태"는 "PENDING" 상태입니다.. 잠시 후 상태가 ACTIVE로 변경됩니다. 배포를 완료하는 데는 몇 분 정도 걸립니다. 다음 명령을 사용하여 배포의 상태를 확인할 수 있습니다.
# while deploying
aws lightsail get-container-services \
--region eu-west-3 \
--query "containerServices[].nextDeployment.state"
# once deployed
aws lightsail get-container-services \
--region eu-west-3 \
--query "containerServices[].currentDeployment.state"
배포 테스트
배포를 테스트하려면 먼저 생성된 URL Lightsail을 검색합니다. 터미널을 열고 다음 명령을 입력합니다.
aws lightsail get-container-services \
--region eu-west-3 \
--query "containerServices[].url"
# the command outputs something like the below
[
"https://signup-application.me04fvc6dbk4e.eu-west-3.cs.amazonlightsail.com/"
]
현재 지원되는 두 가지 버전의 컨테이너 이미지 - :signup-application.latest.1 및 :signup-application.latest.2.
새 애플리케이션 버전 배포
이제 컨테이너 이미지가 Amazon Lightsail에 저장되었으며, 이전 모듈(컨테이너 배포)에서 설명한 것과 비슷한 명령을 사용하여 해당 이미지를 컨테이너 서비스에 배포할 수 있습니다.
lc.json 파일 편집 및 사용할 이미지 이름 교체 - :signup-application.latest.1 - 새 버전별 :signup-application.latest.2.
새 lc.json 파일은 다음과 같이 표시되어야 합니다.
{
"serviceName": "signup-application",
"containers": {
"signup-app-container": {
"image": ":signup-application.latest.2",
"ports": {
"80": "HTTP"
}
}
},
"publicEndpoint": {
"containerName": "signup-app-container",
"containerPort": 80
}
}
그런 다음, 다음 명령을 입력하여 컨테이너를 배포합니다.
aws lightsail create-container-service-deployment \
--region eu-west-3 \
--cli-input-json file://lc.json
# the command outputs the following
배포 테스트
배포를 테스트하려면 브라우저 윈도우로 전환하여 이전 모듈에서 제공된 Container Service URL의 페이지를 새로 고침합니다.
터미널에 다음 명령을 입력하여 URL을 검색할 수 있습니다.
aws lightsail get-container-services \
--region eu-west-3 \
--query "containerServices[].url"
# the command outputs something like the below
[
"https://signup-application.me04fvc6dbk4e.eu-west-3.cs.amazonlightsail.com/"
]
배포 롤백
최종 배포는 애플리케이션의 처음 버전을 재정의하지 않고 새 버전을 생성합니다.
버전이 사용 가능한지 확인하려면 터미널을 열고 다음 명령을 입력합니다.
aws lightsail get-container-service-deployments \
--region eu-west-3 \
--service-name signup-application
# the command outputs a JSON similar to this one
{
"deployments": [
{
"version": 2,
"state": "ACTIVE",
"containers": {
"signup-app-container": {
"image": ":signup-application.latest.2",
"command": [],
"environment": {},
"ports": {
"80": "HTTP"
}
}
},
"publicEndpoint": {
"containerName": "signup-app-container",
"containerPort": 80,
"healthCheck": {
"healthyThreshold": 2,
"unhealthyThreshold": 2,
"timeoutSeconds": 2,
"intervalSeconds": 5,
"path": "/",
"successCodes": "200-499"
}
},
"createdAt": "2021-07-17T18:40:58+02:00"
},
{
"version": 1,
"state": "INACTIVE",
"containers": {
"signup-app-container": {
"image": ":signup-application.latest.1",
"command": [],
"environment": {},
"ports": {
"80": "HTTP"
}
}
},
"publicEndpoint": {
"containerName": "signup-app-container",
"containerPort": 80,
"healthCheck": {
"healthyThreshold": 2,
"unhealthyThreshold": 2,
"timeoutSeconds": 2,
"intervalSeconds": 5,
"path": "/",
"successCodes": "200-499"
}
},
"createdAt": "2021-07-17T15:31:01+02:00"
}
]
}
이전 명령의 출력을 읽으면 두 개의 배포가 있음을 확인할 수 있습니다. 버전 1은 비활성 상태인 반면 버전 2는 활성 상태입니다.
다음 명령은 배포에 대한 자세한 개요를 제공합니다.
aws lightsail get-container-service-deployments \
--region eu-west-3 \
--service-name signup-application \
--query 'deployments[].{version: version, state: state, image: containers."signup-app-container".image}'
# the command outputs something similar to
[
{
"version": 2,
"state": "ACTIVE",
"image": ":signup-application.latest.2"
},
{
"version": 1,
"state": "INACTIVE",
"image": ":signup-application.latest.1"
}
]
이제 방금 배포한 애플리케이션의 최종 버전이 올바르게 작동하지 않는다고 가정하겠습니다. 테스트 중에 버그가 나타나지 않았을 수도 있습니다.
컨테이너의 로그에 액세스하려면 터미널을 열고 다음 명령을 입력합니다.
aws lightsail get-container-log \
--region eu-west-3 \
--service-name signup-application \
--container-name signup-app-container \
--output text
# the command outputs log lines similar to this
LOGEVENTS 2021-07-17T18:14:51+02:00 [pid: 26|app: 0|req: 5821/5821] 172.26.7.236 () {34 vars in 401 bytes} [Sat Jul 17 16:14:51 2021] GET / => generated 4579 bytes in 0 msecs (HTTP/1.1 200) 2 headers in 81 bytes (1 switches on core 0)
LOGEVENTS 2021-07-17T18:14:51+02:00 [pid: 23|app: 0|req: 5824/5824] 172.26.7.236 () {34 vars in 402 bytes} [Sat Jul 17 16:14:51 2021] GET / => generated 4579 bytes in 0 msecs (HTTP/1.1 200) 2 headers in 81 bytes (1 switches on core 0)
LOGEVENTS 2021-07-17T18:14:51+02:00 172.26.7.236 - - [17/Jul/2021:16:14:51 +0000] "GET / HTTP/1.1" 200 4579 "-" "ELB-HealthChecker/2.0" "-"
배포를 신속하게 롤백하고 애플리케이션의 이전 버전을 재배포하려면 lc.json 파일을 컨테이너 이미지의 처음 버전을 사용하도록 변경하고 이 이미지를 다시 배포합니다.
lc.json 파일을 다음과 같이 수정합니다.
# update the lc.json file
{
"serviceName": "signup-application",
"containers": {
"signup-app-container": {
"image": ":signup-application.latest.1",
"ports": {
"80": "HTTP"
}
}
},
"publicEndpoint": {
"containerName": "signup-app-container",
"containerPort": 80
}
}
그런 다음 터미널에서 다음 명령을 실행합니다.
aws lightsail create-container-service-deployment \
--region eu-west-3 \
--cli-input-json file://lc.json
# the command outputs the following
{
"containerService": {
"containerServiceName": "signup-application",
"arn": "arn:aws:lightsail:eu-west-3:486652066693:ContainerService/528a0bcf-fd14-42d4-a09a-943a241adc51",
"createdAt": "2021-07-17T13:38:40+02:00",
"location": {
"availabilityZone": "all",
"regionName": "eu-west-3"
},
"resourceType": "ContainerService",
"tags": [],
"power": "nano",
"powerId": "nano-1",
"state": "DEPLOYING",
"scale": 2,
"currentDeployment": {
"version": 2,
"state": "ACTIVE",
"containers": {
"signup-app-container": {
"image": ":signup-application.latest.2",
"command": [],
"environment": {},
"ports": {
"80": "HTTP"
}
}
},
"publicEndpoint": {
"containerName": "signup-app-container",
"containerPort": 80,
"healthCheck": {
"healthyThreshold": 2,
"unhealthyThreshold": 2,
"timeoutSeconds": 2,
"intervalSeconds": 5,
"path": "/",
"successCodes": "200-499"
}
},
"createdAt": "2021-07-17T18:40:58+02:00"
},
"nextDeployment": {
"version": 3,
"state": "ACTIVATING",
"containers": {
"signup-app-container": {
"image": ":signup-application.latest.1",
"command": [],
"environment": {},
"ports": {
"80": "HTTP"
}
}
},
"publicEndpoint": {
"containerName": "signup-app-container",
"containerPort": 80,
"healthCheck": {
"healthyThreshold": 2,
"unhealthyThreshold": 2,
"timeoutSeconds": 2,
"intervalSeconds": 5,
"path": "/",
"successCodes": "200-499"
}
},
"createdAt": "2021-07-17T19:40:42+02:00"
},
"isDisabled": false,
"principalArn": "arn:aws:iam::577312533299:role/amazon/lightsail/eu-west-3/containers/signup-application/1jetjd21p8qshe57seuh71tnrnn29ps77lnno20sbgl2ghbuc0r0",
"privateDomainName": "signup-application.service.local",
"url": "https://signup-application.me04fvc6dbk4e.eu-west-3.cs.amazonlightsail.com/"
}
}
잠시 후 컨테이너 이미지 v1을 사용하는 배포 v3이 ACTIVE로 바뀝니다. 배포 v2 및 v1은 INACTIVE 상태입니다.
브라우저를 열고 컨테이너 서비스 URL을 가리켜서 처음 버전이 배포되었는지 확인할 수 있습니다.
