From b4befd5e12a76f17319c7bc0ce41702b02d6e75d Mon Sep 17 00:00:00 2001 From: Eunho Lee <60344644+dev-ruby@users.noreply.github.com> Date: Thu, 23 May 2024 13:00:22 +0900 Subject: [PATCH] Update deploy.yml --- .github/workflows/deploy.yml | 43 +++++++++++++++--------------------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 1bd064e..566c277 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,4 +1,4 @@ -name: Deploy Frontend +name: Deploy Frontend and Backend on: push: @@ -6,34 +6,29 @@ on: - main jobs: - build: + build-and-deploy: runs-on: ubuntu-latest - + strategy: + matrix: + service: [frontend, backend] steps: - name: Checkout code uses: actions/checkout@v2 - - name: Build + - name: Setup Docker Buildx uses: docker/setup-buildx-action@v1 - name: Log in to Docker Hub - uses: docker/login-action@v2 + uses: docker/login-action@v1 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Build and push Docker image run: | - docker build -t devruby/l2s-frontend:latest ./frontend - docker build -t devruby/l2s-backend:latest ./backend - docker push devruby/l2s-frontend:latest - docker push devruby/l2s-backend:latest - - deploy: - runs-on: ubuntu-latest - needs: build + docker build -t devruby/l2s-${{ matrix.service }}:latest ./${{ matrix.service }} + docker push devruby/l2s-${{ matrix.service }}:latest - steps: - name: Deploy to server uses: appleboy/ssh-action@v0.1.6 with: @@ -41,14 +36,12 @@ jobs: username: ${{ secrets.SERVER_USER }} key: ${{ secrets.SERVER_PRIVATE_KEY }} script: | - sudo docker stop l2s-frontend || true - sudo docker rm l2s-frontend || true - sudo docker image rm devruby/l2s-frontend || true - sudo docker pull devruby/l2s-frontend:latest - sudo docker run -d --name l2s-frontend -p 3001:3000 devruby/l2s-frontend:latest - - sudo docker stop l2s-backend || true - sudo docker rm l2s-backend || true - sudo docker image rm devruby/l2s-backend || true - sudo docker pull devruby/l2s-backend:latest - sudo docker run -d --name l2s-backend -v l2s-data:/workspace/data -p 8001:8000 devruby/l2s-backend:latest + sudo docker stop l2s-${{ matrix.service }} || true + sudo docker rm l2s-${{ matrix.service }} || true + sudo docker image rm devruby/l2s-${{ matrix.service }} || true + sudo docker pull devruby/l2s-${{ matrix.service }}:latest + if [ "${{ matrix.service }}" = "frontend" ]; then + sudo docker run -d --name l2s-frontend -p 3001:3000 devruby/l2s-frontend:latest + else + sudo docker run -d --name l2s-backend -v l2s-data:/workspace/data -p 8001:8000 devruby/l2s-backend:latest + fi