From b3c54c6382b46bfea8730035b5ce3088135e963e Mon Sep 17 00:00:00 2001 From: dongkyun-dev Date: Wed, 10 Jan 2024 12:45:52 +0900 Subject: [PATCH] feat: test --- .github/workflows/deploy.yaml | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index f524898f..5701a0f7 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -40,19 +40,19 @@ jobs: docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG - name: Deploy to EC2 - run: | - echo "${{ secrets.EC2_SSH_PRIVATE_KEY }}" > private_key.pem - chmod 400 private_key.pem - ssh -i private_key.pem -o StrictHostKeyChecking=no ubuntu@${{ secrets.EC2_PUBLIC_DOMAIN }} " - aws ecr get-login-password --region ap-northeast-2 | - sudo docker login --username AWS --password-stdin ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} && - echo "chk" && - echo ${{ env.IMAGE_NAME }} && - if [ \$(sudo docker ps -q -f name=${{ env.IMAGE_NAME }}) ]; then - echo "chk2" && - echo ${{ env.IMAGE_NAME }} && - sudo docker stop ${{ env.IMAGE_NAME }} && - sudo docker rm ${{ env.IMAGE_NAME }} - fi && - sudo docker image pull ${{ steps.meta.outputs.tags }} && - sudo docker container run --name ${{ env.IMAGE_NAME }} -d -p 3000:3000 ${{ steps.meta.outputs.tags }}" + env: + REGISTRY: ${{ steps.login-ecr.outputs.registry }} + REPOSITORY: ${{ env.IMAGE_NAME }} + IMAGE_TAG: ${{ github.sha }} + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.EC2_PUBLIC_DOMAIN }} + username: ubuntu + key: ${{ secrets.EC2_SSH_PRIVATE_KEY }} + envs: REGISTRY,REPOSITORY,IMAGE_TAG,AWS_REGION,IMAGE_NAME + scripts: |- + aws ecr get-login-password --region ${{ env.AWS_REGION }} + sudo docker stop ${{ env.IMAGE_NAME }} || true + sudo docker rm ${{ env.IMAGE_NAME }} || true + sudo docker pull $REGISTRY/$REPOSITORY:$IMAGE_TAG + sudo docker container run --name ${{ env.IMAGE_NAME }} -d -p 3000:3000 $REGISTRY/$REPOSITORY:$IMAGE_TAG