Update README.md #152
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 CI with Gradle | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
permissions: | |
contents: read | |
jobs: | |
build: | |
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' | |
- name: Make application-prod.yml | |
run: | | |
cd ./src/main/resources && touch ./application-prod.yml && echo "${{ secrets.APPLICATION_PROD }}" > ./application-prod.yml | |
- name: Grant execute permission for gradlew | |
run: | | |
chmod +x gradlew | |
- name: Build with Gradle | |
run: | | |
./gradlew build -x test | |
- name: Docker build and push | |
run: | | |
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin | |
docker build -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }} . | |
docker build -f Dockerfile-nginx -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO_NGINX }} . | |
docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}:latest | |
docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO_NGINX }}:latest | |
- name: Make config.py | |
run: | | |
cd ./crawling && touch ./config.py && | |
echo "DB_HOST=\"${{ secrets.DB_HOST }}\"" >> ./config.py && | |
echo "DB_USER=\"${{ secrets.DB_USER }}\"" >> ./config.py && | |
echo "DB_PASSWORD=\"${{ secrets.DB_PASSWORD }}\"" >> ./config.py && | |
echo "DB_NAME=\"${{ secrets.DB_NAME }}\"" >> ./config.py | |
- name: Remove existing config.py, eventus.py, docker-compose.yml on EC2 | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} # EC2 인스턴스 퍼블릭 DNS | |
username: ubuntu | |
key: ${{ secrets.PRIVATE_KEY }} # pem 키 | |
script: | | |
rm -f /home/ubuntu/crawling/crawling/config.py | |
rm -f /home/ubuntu/crawling/crawling/eventus.py | |
rm -f /home/ubuntu/docker-compose.yml | |
- name: Copy config.py to EC2 | |
uses: appleboy/scp-action@master | |
with: | |
host: ${{ secrets.HOST }} # EC2 인스턴스 퍼블릭 DNS | |
username: ubuntu | |
key: ${{ secrets.PRIVATE_KEY }} # pem 키 | |
source: './crawling/config.py' # 로컬 파일 경로 | |
target: '/home/ubuntu/crawling' # EC2에 복사될 경로 | |
- name: Copy eventus.py to EC2 | |
uses: appleboy/scp-action@master | |
with: | |
host: ${{ secrets.HOST }} # EC2 인스턴스 퍼블릭 DNS | |
username: ubuntu | |
key: ${{ secrets.PRIVATE_KEY }} # pem 키 | |
source: './crawling/eventus.py' # 로컬 파일 경로 | |
target: '/home/ubuntu/crawling' # EC2에 복사될 경로 | |
- name: Copy docker-compose.yml to EC2 | |
uses: appleboy/scp-action@master | |
with: | |
host: ${{ secrets.HOST }} # EC2 인스턴스 퍼블릭 DNS | |
username: ubuntu | |
key: ${{ secrets.PRIVATE_KEY }} # pem 키 | |
source: './docker-compose.yml' # 로컬 파일 경로 | |
target: '/home/ubuntu' # EC2에 복사될 경로 | |
- name: Deploy | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} # EC2 인스턴스 퍼블릭 DNS | |
username: ubuntu | |
key: ${{ secrets.PRIVATE_KEY }} # pem 키 | |
# 도커 작업 | |
script: | | |
docker rm -f $(docker ps -qa) | |
docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}:latest | |
docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO_NGINX }}:latest | |
docker compose up -d | |
docker image prune -a -f |