From d2c3010075ed002a0c0f173958fe32be836b1d56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EB=AF=BC?= <144198706+Minn-Choi@users.noreply.github.com> Date: Mon, 4 Nov 2024 16:16:43 +0900 Subject: [PATCH] =?UTF-8?q?[Chore]=20-=20deploy.yml=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 44 ++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..ee61ec3 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,44 @@ +# deploy.yml +name: Deploy Vue.js to EC2 + +on: + push: + branches: + - main # main 브랜치에 push될 때 트리거 + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Check out code + uses: actions/checkout@v2 + + - name: Log in to Docker Hub + run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin + + - name: Build Docker image + run: docker build -t ${{ secrets.DOCKER_USERNAME }}/my-vue-app . + + - name: Push Docker image to Docker Hub + run: | + docker tag ${{ secrets.DOCKER_USERNAME }}/my-vue-app:latest ${{ secrets.DOCKER_USERNAME }}/my-vue-app:latest + docker push ${{ secrets.DOCKER_USERNAME }}/my-vue-app:latest + + deploy: + needs: build + runs-on: ubuntu-latest + + steps: + - name: Deploy to EC2 + uses: appleboy/ssh-action@v0.1.3 + with: + host: ${{ secrets.EC2_HOST }} + username: ${{ secrets.EC2_USER }} + key: ${{ secrets.EC2_KEY }} + port: 22 + script: | + docker pull ${{ secrets.DOCKER_USERNAME }}/my-vue-app:latest + docker stop my-vue-app || true + docker rm my-vue-app || true + docker run -d -p 80:80 —name my-vue-app ${{ secrets.DOCKER_USERNAME }}/my-vue-app:latest