From 56fc839be51e0ff95843c8038ae2eef3484fc874 Mon Sep 17 00:00:00 2001 From: Lee-Dongwook Date: Sat, 19 Oct 2024 17:41:10 +0900 Subject: [PATCH] ci: deploy.yml --- .github/workflows/deploy.yml | 41 ++++++++++++++++++++++++++++++++++++ 1 file changed, 41 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..3445197 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,41 @@ +name: Deploy to EC2 + +on: + push: + branches: + - main + +jobs: + deploy: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build and push Docker images + run: | + docker-compose -f docker-compose.yml build + docker-compose -f docker-compose.yml push + + - name: Deploy to EC2 + uses: appleboy/ssh-action@v0.1.6 + with: + host: ${{ secrets.EC2_HOST }} + username: ${{ secrets.EC2_USER }} + key: ${{ secrets.EC2_KEY }} + port: 22 + script: | + cd /path/to/your/app + git pull origin main + docker-compose down + docker-compose up -d