feat: Cors 설정 추가 #127
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Java CD with Gradle in Tiki-Taza | |
on: | |
workflow_dispatch: | |
push: | |
branches: [ "main" ] | |
permissions: | |
contents: read | |
jobs: | |
build-and-push-docker: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
## gradle 캐싱 | |
- 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- | |
## create application.yml | |
- name: make application-secret.yml | |
run: | | |
mkdir -p ./api/src/main/resources | |
touch ./api/src/main/resources/application-secret.yml | |
shell: bash | |
- name: deliver application-secret.yml | |
run: echo "${{ secrets.APPLICATION_SECRET }}" > ./api/src/main/resources/application-secret.yml | |
shell: bash | |
# 빌드 및 테스트 단계. | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
# gradle build | |
- name: Build with Gradle | |
run: ./gradlew build -x test | |
# push 하기 위해 로그인 | |
- name: Docker Hub 로그인 | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_ID }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
#도커 빌드 & 이미지 push | |
- name: Docker build & Push | |
run: | | |
docker build -f Dockerfile -t ${{ secrets.DOCKER_ID }}/tiki-taza . | |
docker push ${{ secrets.DOCKER_ID }}/tiki-taza | |
# Docker 파일을 EC2 서버에 배포 | |
- name: Deploy to Prod | |
uses: appleboy/ssh-action@master | |
id: deploy-prod | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ubuntu | |
key: ${{ secrets.EC2_PEM_KEY }} | |
port: 22 | |
script: | | |
if [ ! -z "$(docker ps -q)" ]; then | |
docker stop $(docker ps -q) | |
fi | |
if [ ! -z "$(docker ps -aq)" ]; then | |
docker rm $(docker ps -aq) | |
fi | |
docker login -u ${{ secrets.DOCKER_ID }} -p ${{ secrets.DOCKER_PASSWORD }} | |
docker pull ${{ secrets.DOCKER_ID }}/tiki-taza | |
docker pull wurstmeister/zookeeper | |
docker network create tikitaza | |
docker run -d \ | |
--name zookeeper \ | |
--network=tikitaza \ | |
-p 2181:2181 \ | |
wurstmeister/zookeeper | |
# Kafka 컨테이너 실행 | |
docker run -d \ | |
--name kafka \ | |
--network=tikitaza \ | |
-p 9092:9092 \ | |
-e KAFKA_ADVERTISED_HOST_NAME=${{ secrets.EC2_HOST }}\ | |
-e KAFKA_ADVERTISED_PORT=9092 \ | |
-e KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 \ | |
wurstmeister/kafka | |
docker run -d \ | |
--name redis \ | |
--network=tikitaza \ | |
-p 6379:6379 \ | |
redis | |
docker run -d \ | |
--name tiki-taza \ | |
--network=tikitaza \ | |
-p 80:8080 \ | |
-e TZ=Asia/Seoul \ | |
${{ secrets.DOCKER_ID }}/tiki-taza | |
docker system prune -f |