Docs: Update README.md #51
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: Deploy To EC2 | |
on: | |
push: | |
branches: | |
- main | |
- dev | |
jobs: | |
build: | |
env: | |
REDIRECT_URL: ${{ secrets.REDIRECT_URL }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Github Repository에 올린 파일들을 불러오기 | |
uses: actions/checkout@v4 | |
- name: JDK 21 버전 설치 | |
uses: actions/setup-java@v4 | |
with: | |
distribution: temurin | |
java-version: 21 | |
- name: GitHub 환경변수 출력 | |
run: | | |
echo "REDIRECT_URL: $REDIRECT_URL" | |
echo "DOCKERHUB_USERNAME: $DOCKERHUB_USERNAME" | |
echo "DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}" # 비밀번호는 보안상 출력하지 않는 것이 좋습니다 | |
echo "REDIRECT_URL: ${{ secrets.REDIRECT_URL }}" | |
echo "DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}" | |
- name: 테스트 및 빌드하기 | |
run: | | |
chmod +x ./gradlew | |
./gradlew clean build -x test | |
- name: Docker Hub에 로그인하기 | |
run: docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Docker 이미지 생성 | |
run: docker build -t nullnull-server . | |
- name: Docker 이미지에 Tag 붙이기 | |
run: docker tag nullnull-server ${{ secrets.DOCKERHUB_USERNAME }}/nullnull-server:latest | |
- name: Docker Hub에 Docker 이미지 Push하기 | |
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/nullnull-server:latest | |
- name: SSH로 EC2에 접속하기 | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USERNAME }} | |
key: ${{ secrets.EC2_PRIVATE_KEY }} | |
script_stop: true | |
script: | | |
echo "REDIRECT_URL 환경변수:${{ secrets.REDIRECT_URL }}" | |
docker stop nullnull-server || true | |
docker rm nullnull-server || true | |
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/nullnull-server:latest | |
docker run -d --name nullnull-server -p 8080:8080 ${{ secrets.DOCKERHUB_USERNAME }}/nullnull-server:latest | |