Skip to content

chore: 백엔드 CD 스크립트 작성 #4

chore: 백엔드 CD 스크립트 작성

chore: 백엔드 CD 스크립트 작성 #4

Workflow file for this run

name: Backend CI/CD Workflow
on:
pull_request:
branches: [ "develop-BE" ]
jobs:
build-and-test:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'corretto'
- name: Set up Gradle
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5
- name: Build with Gradle Wrapper
run: ./gradlew clean build
working-directory: ./backend
- name: Docker build and push
run: |
docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }}
docker build -t ${{ secrets.DOCKERHUB_IMAGE_NAME }} .
docker tag ${{ secrets.DOCKERHUB_IMAGE_NAME }} ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_IMAGE_NAME }}:${GITHUB_SHA::7}
docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_IMAGE_NAME }}:${GITHUB_SHA::7}
deploy:
needs: build-and-test
runs-on: self-hosted
steps:
- name: Pull Image And Restart Container
run: |
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_IMAGE_NAME }}:${GITHUB_SHA::7}
docker stop ${{ secrets.DOCKERHUB_CONTAINER_NAME }} | true
docker rm ${{ secrets.DOCKERHUB_CONTAINER_NAME }} | true
docker run --name ${{ secrets.DOCKERHUB_CONTAINER_NAME }} -p 80:8080 ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_IMAGE_NAME }}:${GITHUB_SHA::7}