From 68bceabdccf3e0d443d9567aff3e0af30ad90bad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=98=B8=EC=A4=80?= Date: Mon, 10 Jun 2024 22:05:11 +0900 Subject: [PATCH] fix: init --- .github/workflows/main.yml | 66 +++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 06f6caf..0a78a7a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,53 +1,59 @@ -name: CI/CD using github actions & docker +name: CD with Gradle on: push: - branches: [ "main" ] # 해당 branch에 푸쉬 발생 시 업데이트 + branches: [ "main" ] + +permissions: + contents: read jobs: - CI-CD: + build: runs-on: ubuntu-latest + steps: - uses: actions/checkout@v3 + - name: Set up JDK 17 - uses: actions/setup-java@v2 + uses: actions/setup-java@v3 with: java-version: '17' - distribution: 'temurin' + distribution: "temurin" - - name: set chmod - run: chmod +x ./gradlew + - name: Make application.yml + run: | + cd ./src/main/resources + touch ./application.yml + echo "${{ secrets.APPLICATION }}" > ./application.yml + shell: bash - name: Build with Gradle - run: ./gradlew jar + run: | + chmod +x ./gradlew + ./gradlew clean build -x test - - name: Docker build & push to prod + - name: Docker build run: | docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} - docker build -f Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/sopo_v2:0.0.1 . - docker push ${{ secrets.DOCKER_USERNAME }}/sopo_v2:0.0.1 - - # - name: Install Docker - # run: | - # sudo apt-get update - # sudo apt-get install apt-transport-https ca-certificates curl software-properties-common - # curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - - # sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" - # sudo apt-get update - # sudo apt-get install docker-ce - - - name: Deploy to prod + docker build -t sopo_v2 . # Dockerfile 경로 수정 + docker tag sopo_v2 ${{ secrets.DOCKER_USERNAME }}/sopo_v2:latest + docker push ${{ secrets.DOCKER_USERNAME }}/sopo_v2:latest + + - name: Deploy with SSH + if: github.ref == 'refs/heads/main' uses: appleboy/ssh-action@master - id: deploy-prod + with: - host: ${{ secrets.HOST_PROD }} # EC2 퍼블릭 IPv4 DNS + host: ${{ secrets.HOST }} # EC2 인스턴스 퍼블릭 DNS username: ubuntu - key: ${{ secrets.PRIVATE_KEY }} # EC2 private key - port: ${{ secrets.PORT }} #ssh port (22) - envs: GITHUB_SHA + key: ${{ secrets.PRIVATE_KEY }} # pem 키 + # 도커 작업 script: | + docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} docker stop sopo_v2 docker rm sopo_v2 - docker rmi ${{ secrets.DOCKER_USERNAME }}/sopo_v2:0.0.1 - docker pull ${{ secrets.DOCKER_USERNAME }}/sopo_v2:0.0.1 - docker run -d -p 8080:8080 --name welspy ${{ secrets.DOCKER_USERNAME }}/sopo_v2:0.0.1\ \ No newline at end of file + docker network disconnect redis-network sopo_v2 + docker rmi ${{ secrets.DOCKER_USERNAME }}/sopo_v2:latest + docker pull ${{ secrets.DOCKER_USERNAME }}/sopo_v2:latest + docker run -d -p 80:8080 --name sopo_v2 ${{ secrets.DOCKER_USERNAME }}/sopo_v2:latest + docker network connect redis-network sopo_v2