From 270f0456ce9b28a319c3ca580740560021bd07a0 Mon Sep 17 00:00:00 2001 From: "chosw1002@naver.com" Date: Fri, 5 Jan 2024 20:45:37 +0900 Subject: [PATCH] =?UTF-8?q?chore:=20=EA=B9=83=ED=97=88=EB=B8=8C=20?= =?UTF-8?q?=EC=95=A1=EC=85=98=20=EC=9B=8C=ED=81=AC=ED=94=8C=EB=A1=9C?= =?UTF-8?q?=EC=9A=B0=20=EC=9E=91=EC=84=B1=20(#1)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cicd.yml | 53 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 .github/workflows/cicd.yml diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml new file mode 100644 index 0000000..517cd43 --- /dev/null +++ b/.github/workflows/cicd.yml @@ -0,0 +1,53 @@ +name: build and deploy + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +permissions: + contents: read + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + + - name: Run chmod to make gradlew executable + run: chmod +x ./gradlew + - name: Build with Gradle + run : ./gradlew clean build --exclude-task test + + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Build Docker + run: docker build --platform linux/amd64 -t ${{ secrets.DOCKERHUB_USERNAME }}/infra_practice_server . + - name: Push Docker + run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/infra_practice_server:latest + + + deploy: + runs-on: ubuntu-latest + needs: build + steps: + - name: Docker compose + uses: appleboy/ssh-action@master + with: + username: ubuntu + host: ${{ secrets.INFRA_PRACTICE_SERVER_IP }} + key: ${{ secrets.EC2_SSH_KEY }} + script: | + sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/infra_practice_server:latest + sudo docker run -d -p 8080:8080 --name deploy_container \ No newline at end of file