Skip to content

Commit

Permalink
Merge pull request #794 from woowacourse-teams/chore/#793
Browse files Browse the repository at this point in the history
무중단배포 중단 문제 해결
  • Loading branch information
ay-eonii authored Nov 25, 2024
2 parents 98b19c3 + 514ddc7 commit 0a37cd5
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 14 deletions.
52 changes: 38 additions & 14 deletions .github/workflows/be-rolling-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2

- name: Prepare Deploy
run: |
cd ~/deploy && ./prepare-deploy.sh
- name: Run Prod1 instance deploy script
run: |
cd ~/deploy && ./deploy.sh
Expand All @@ -25,16 +29,24 @@ jobs:

steps:
- name: Wait for Prod1 instance to be ready
run: sleep 30
run: sleep 25

- name: Health check for Prod1 instance
run: |
RESPONSE=$(curl --write-out '%{http_code}' --silent --output /dev/null http://localhost:8080/health)
if [ $RESPONSE -ne 200 ]; then
echo "Prod1 instance deployment failed."
exit 1
fi
echo "Prod1 instance is healthy."
ATTEMPTS=0
MAX_ATTEMPTS=3
until [ $ATTEMPTS -ge $MAX_ATTEMPTS ]; do
RESPONSE=$(curl --write-out '%{http_code}' --silent --output /dev/null http://localhost:8080/health)
if [ $RESPONSE -eq 200 ]; then
echo "Prod1 instance is healthy."
exit 0
fi
echo "Health check failed, attempt $((ATTEMPTS+1))/$MAX_ATTEMPTS. Retrying in 5 seconds..."
ATTEMPTS=$((ATTEMPTS+1))
sleep 5
done
echo "Prod1 instance deployment failed after $MAX_ATTEMPTS attempts."
exit 1
deploy-prod2:
name: Deploy to Prod2 Instance
Expand All @@ -45,6 +57,10 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2

- name: Prepare Deploy
run: |
cd ~/deploy && ./prepare-deploy.sh
- name: Run Prod2 instance deploy script
run: |
cd ~/deploy && ./deploy.sh
Expand All @@ -56,13 +72,21 @@ jobs:

steps:
- name: Wait for Prod2 instance to be ready
run: sleep 30
run: sleep 25

- name: Health check for Prod2 instance
run: |
RESPONSE=$(curl --write-out '%{http_code}' --silent --output /dev/null http://localhost:8080/health)
if [ $RESPONSE -ne 200 ]; then
echo "Prod2 instance deployment failed."
exit 1
fi
echo "Prod2 instance is healthy."
ATTEMPTS=0
MAX_ATTEMPTS=3
until [ $ATTEMPTS -ge $MAX_ATTEMPTS ]; do
RESPONSE=$(curl --write-out '%{http_code}' --silent --output /dev/null http://localhost:8080/health)
if [ $RESPONSE -eq 200 ]; then
echo "Prod2 instance is healthy."
exit 0
fi
echo "Health check failed, attempt $((ATTEMPTS+1))/$MAX_ATTEMPTS. Retrying in 5 seconds..."
ATTEMPTS=$((ATTEMPTS+1))
sleep 5
done
echo "Prod2 instance deployment failed after $MAX_ATTEMPTS attempts."
exit 1
Original file line number Diff line number Diff line change
@@ -1,14 +1,39 @@
package mouda.backend.common;

import java.util.concurrent.atomic.AtomicBoolean;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.servlet.http.HttpServletRequest;

@RestController
public class HealthCheckController {

private static final String HOST_IPV4 = "127.0.0.1";
private static final String HOST_IPV6 = "0:0:0:0:0:0:0:1";
private static final String HOST_NAME = "localhost";

private final AtomicBoolean isTerminating = new AtomicBoolean(false);

@GetMapping("/health")
public ResponseEntity<Void> checkHealth() {
if (isTerminating.get()) {
return ResponseEntity.status(HttpStatus.BAD_GATEWAY).build();
}
return ResponseEntity.ok().build();
}

@PostMapping("/termination")
public ResponseEntity<Void> terminate(HttpServletRequest request) {
String remoteHost = request.getRemoteHost();
if (HOST_IPV6.equals(remoteHost) || HOST_IPV4.equals(remoteHost) || HOST_NAME.equals(remoteHost)) {
isTerminating.set(true);
return ResponseEntity.ok().build();
}
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
}
}
1 change: 1 addition & 0 deletions backend/src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ server:
tomcat:
mbeanregistry:
enabled: true
shutdown: graceful

0 comments on commit 0a37cd5

Please sign in to comment.