diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml new file mode 100644 index 0000000..741cc86 --- /dev/null +++ b/.github/workflows/cicd.yml @@ -0,0 +1,56 @@ +name: Java CI with Gradle + +on: + pull_request: + branches: [ "main" ] + types : [closed] + +jobs: + build: + if : github.event.pull_request.merged == true + runs-on: ubuntu-latest + permissions: + contents: read + + steps: + - uses: actions/checkout@v4 + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + + - name: make application-prod.yml + run: | + cd ./src/main/resources + touch ./application-prod.yml + echo "${{ secrets.APPLICATION_PROD }}" > ./application-prod.yml + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0 + + - name: Build with Gradle Wrapper + run: ./gradlew build -x test + + - name: Docker build + run: | + docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} + docker build -t app . + docker tag app ${{ secrets.DOCKER_USERNAME }}/maru:latest + docker push ${{ secrets.DOCKER_USERNAME }}/maru:latest + + - name: Deploy + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.AWS_HOST }} # EC2 인스턴스 퍼블릭 DNS + username: ec2-user + key: ${{ secrets.AWS_ACCESS_SECRET_KEY }} # pem 키 + # 도커 작업 + script: | + docker pull ${{ secrets.DOCKER_USERNAME }}/maru:latest + docker stop $(docker ps -a -q) + docker run -d --log-driver=syslog -p 8080:8080 -e SPRING_PROFILES_ACTIVE=prod ${{ secrets.DOCKER_USERNAME }}/maru:latest + docker rm $(docker ps --filter 'status=exited' -a -q) + docker image prune -a -f + + diff --git a/.github/workflows/super-linter.yml b/.github/workflows/super-linter.yml deleted file mode 100644 index 993cc19..0000000 --- a/.github/workflows/super-linter.yml +++ /dev/null @@ -1,29 +0,0 @@ -# This workflow executes several linters on changed files based on languages used in your code base whenever -# you push a code or open a pull request. -# -# You can adjust the behavior by modifying this file. -# For more information, see: -# # https://github.com/github/super-linter -# name: Lint Code Base - -# on: -# push: -# branches: [ "main" ] -# pull_request: -# branches: [ "main" ] -# jobs: -# run-lint: -# runs-on: ubuntu-latest -# steps: -# - name: Checkout code -# uses: actions/checkout@v3 -# with: -# # Full git history is needed to get a proper list of changed files within `super-linter` -# fetch-depth: 0 - -# - name: Lint Code Base -# uses: github/super-linter@v4 -# env: -# VALIDATE_ALL_CODEBASE: false -# DEFAULT_BRANCH: "main" -# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}