Skip to content

Commit

Permalink
[BE] refactor: container port 매핑 조건 추가 (#24)
Browse files Browse the repository at this point in the history
Signed-off-by: EunJiJung <[email protected]>
  • Loading branch information
bianbbc87 committed Feb 9, 2025
1 parent 3ba3b60 commit 2d98feb
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions .github/actions/ecr-push/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,21 @@ runs:
username: ${{ inputs.ec2_username }}
key: ${{ inputs.ec2_ssh_key }}
script: |
sudo docker stop ${{ inputs.container_name }} || true
sudo docker rm ${{ inputs.container_name }} || true
# 컨테이너 포트 기본값 설정 (8080)
CONTAINER_PORT=${{ inputs.container_port }}
if [[ -z "$CONTAINER_PORT" || ! "$CONTAINER_PORT" =~ ^[0-9]+$ ]]; then
CONTAINER_PORT=8080
# 기존 컨테이너가 존재하면 중지 후 삭제
if sudo docker ps -aq -f name=${{ inputs.container_name }} | grep -q .; then
sudo docker stop ${{ inputs.container_name }}
sudo docker rm ${{ inputs.container_name }}
fi
echo "Using container port: $CONTAINER_PORT"
CONTAINER_PORT="${{ inputs.container_port }}"
# container_port가 0이면 포트 매핑 없이 실행
if [ "$CONTAINER_PORT" -eq 0 ]; then
sudo docker run -d --name ${{ inputs.container_name }} \
${{ inputs.ecr_uri }}/${{ inputs.namespace }}/${{ inputs.ecr_repo }}:${{ github.sha }}
else
sudo docker run -d --name ${{ inputs.container_name }} -p "$CONTAINER_PORT:$CONTAINER_PORT" \
${{ inputs.ecr_uri }}/${{ inputs.namespace }}/${{ inputs.ecr_repo }}:${{ github.sha }}
fi
sudo docker run -d --name ${{ inputs.container_name }} -p $CONTAINER_PORT:$CONTAINER_PORT ${{ inputs.ecr_uri }}/${{ inputs.namespace }}/${{ inputs.ecr_repo }}:${{ github.sha }}

0 comments on commit 2d98feb

Please sign in to comment.