Skip to content

Commit

Permalink
fix: CD workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
MinhoJJang committed Aug 16, 2024
1 parent 5c520db commit 5884b33
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions .github/workflows/nextjs-prod-CD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ on:
env:
KCR_REGISTRY: dkation.kr-central-2.kcr.dev
KCR_REPOSITORY: dkation-prod-front/dkation-prod-fe
ACCESS_KEY: ${{ secrets.ACCESS_KEY }}
ACCESS_SECRET_KEY: ${{ secrets.ACCESS_SECRET_KEY }}

jobs:
deploy:
Expand Down Expand Up @@ -45,32 +47,27 @@ jobs:
IFS=',' read -r -a HOSTS <<< "${{ secrets.WEB_IPS }}"
KCR_REGISTRY='${{ env.KCR_REGISTRY }}'
KCR_REPOSITORY='${{ env.KCR_REPOSITORY }}'
ACCESS_KEY='${{ secrets.ACCESS_KEY }}'
ACCESS_SECRET_KEY='${{ secrets.ACCESS_SECRET_KEY }}'
for host in "${HOSTS[@]}"
do
echo "Deploying to $host"
ssh -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no ${{ secrets.USER }}@$host << 'EOF'
set -e
echo "Stopping and removing existing containers"
docker ps -q --filter ancestor=$KCR_REGISTRY/$KCR_REPOSITORY | xargs -r docker stop || true
docker ps -aq --filter ancestor=$KCR_REGISTRY/$KCR_REPOSITORY | xargs -r docker rm || true
docker ps --format '{{.ID}} {{.Image}}' | grep 'dkation.kr-central-2.kcr.dev/dkation-prod-front/dkation-prod-fe' | awk '{print $1}' | xargs -r docker stop && \
docker ps -a --format '{{.ID}} {{.Image}}' | grep 'dkation.kr-central-2.kcr.dev/dkation-prod-front/dkation-prod-fe' | awk '{print $1}' | xargs -r docker rm && \
echo "Removing old Docker images"
docker images $KCR_REGISTRY/$KCR_REPOSITORY --format '{{.ID}}' | xargs -r docker rmi || true
docker images --format '{{.Repository}}:{{.Tag}}' | grep 'dkation.kr-central-2.kcr.dev/dkation-prod-front/dkation-prod-fe' | xargs -r docker rmi
echo "Login to KCR"
echo $ACCESS_SECRET_KEY | docker login $KCR_REGISTRY --username $ACCESS_KEY --password-stdin
echo ${{ env.ACCESS_SECRET_KEY }} | docker login $KCR_REGISTRY --username ${{ env.ACCESS_KEY}} --password-stdin
echo "Pulling new Docker image"
docker pull $KCR_REGISTRY/$KCR_REPOSITORY:${{ steps.get_version.outputs.version }}
echo "Running new Docker container"
docker run -d -p 80:3000 --name frontend $KCR_REGISTRY/$KCR_REPOSITORY:${{ steps.get_version.outputs.version }}
docker run -d -p 80:3000 --name dkation-frontend $KCR_REGISTRY/$KCR_REPOSITORY:${{ steps.get_version.outputs.version }}
echo "Checking container health"
max_retries=5
Expand Down

0 comments on commit 5884b33

Please sign in to comment.