Skip to content

Commit

Permalink
cicd: CICD.yml 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
CEO-Nick authored Feb 14, 2025
1 parent 9ebe7a7 commit e68243a
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/CICD.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: CI/CD

on:
push:
branches: [ main, feat/SCRUM-17 ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
distribution: 'corretto'
java-version: '17'

- name: Gradle Caching
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Make application.yml file
run: |
echo "${{ secrets.APPLICATION_YML }}" > ./src/main/resources/application.yml
- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Build with Gradle
run : ./gradlew clean build -x test -Dfile.encoding=UTF-8

- name: Docker Login
run: docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}

- name: Build Docker image
run: |
docker build -f Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/timeattack:latest .
- name: Push Docker image to Docker Hub
run: |
docker push ${{ secrets.DOCKER_USERNAME }}/timeattack:latest
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Deploy to Server
uses: appleboy/ssh-action@v0.1.7
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USER }}
key: ${{ secrets.SSH_KEY }}
script: |
echo "Pulling latest Docker image..."
docker pull ${{ secrets.DOCKER_USERNAME }}/timeattack:latest
echo "Stopping and removing existing container (if exists)..."
docker stop timeattack || true
docker rm timeattack || true
echo "Running new container..."
docker run -d --name timeattack -p 8080:8080 --restart always ${{ secrets.DOCKER_USERNAME }}/timeattack:latest

0 comments on commit e68243a

Please sign in to comment.