Skip to content

Update README.md

Update README.md #131

Workflow file for this run

name: Deploy Spring Application to Ec2
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
# 워크플로우가 저장소의 콘텐츠를 읽을 수 있는 권한을 갖도록 설정
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v4
- name: set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'corretto'
java-version: '17'
- name: Make KeyStore
env:
KEYSTORE_P12: ${{ secrets.KEYSTORE_P12 }}
run: |
cd ./be/issue-tracker/src/main
mkdir resources
cd resources
mkdir ssl
cd ssl
touch keystore.p12
echo "${{ secrets.KEYSTORE_P12 }}" | base64 -d > ./keystore.p12
shell: bash
- name: Make application.properties
run: |
cd ./be/issue-tracker/src/main/resources
touch application.properties
echo "${{ secrets.PROPERTIES }}" > ./application.properties
shell: bash
- name: Grant execute permission for gradlew
run: |
cd ./be/issue-tracker
chmod +x gradlew
- name: Build with Gradle
run: |
cd ./be/issue-tracker
./gradlew clean build -x test
# dockerfile을 통해 이미지를 빌드하고, 이를 docker repo로 push 합니다.
- name: Docker build & push to docker repo
run: |
cd ./be/issue-tracker
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -f Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}:latest .
docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}:latest
# 서버에 접속 후 Docker 이미지 가져와서 배포
- name: Deploy to server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_PRIVATE_KEY }}
run: |
cd /home/ubuntu
script: |
sudo docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}:latest
# 기존에 실행 중인 컨테이너 중지 및 삭제
if [ $(sudo docker ps -q -f name=spring-server) ]; then
sudo docker stop spring-server
sudo docker rm spring-server
fi
# 새로운 컨테이너 실행
sudo docker-compose up -d