Skip to content

BE CD for Dev

BE CD for Dev #29

Workflow file for this run

name: BE CD for Dev
on:
workflow_dispatch:
push:
branches: [ "develop" ]
paths:
- backend/**
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
working-directory: ./backend
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew clean bootJar
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_GMAIL }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Build Docker image
run: docker build --platform linux/arm64/v8 -t ${{ secrets.DOCKER_REPOSITORY_NAME }}/ddangkong-api-dev:latest .
- name: Push Docker image
run: docker push ${{ secrets.DOCKER_REPOSITORY_NAME }}/ddangkong-api-dev:latest
deploy:
needs: build
runs-on: [ self-hosted, linux, ARM64 ] # Self hosted runner 사용
steps:
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_GMAIL }}
password: ${{ secrets.DOCKER_TOKEN }}
env:
CONTAINER_NAME: ddangkong-api-dev
- name: Pull docker image
run: sudo docker pull ${{ secrets.DOCKER_REPOSITORY_NAME }}/ddangkong-api-dev:latest
- name: Stop and Remove previous Docker container
run: |
CONTAINER_ID=$(sudo docker ps -aqf "name=$CONTAINER_NAME")
sudo docker rm -f ${CONTAINER_ID}
- name: Run new Docker container
run: |
sudo docker run -d --name ${{ env.CONTAINER_NAME }} \
-p 8080:8080 \
ddangkong/ddangkong-api-dev:latest