Update gradle.yml #23
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" ] | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: make application.yml | |
run: | | |
mkdir ./src/main/resources | |
cd ./src/main/resources | |
touch ./application.yml | |
echo "${{ secrets.APPLICATION_YML }}" > ./application.yml | |
- name: Grant execute permission for gradlew and build | |
run: | | |
chmod +x ./gradlew | |
./gradlew clean | |
./gradlew -x test build | |
# Docker 이미지 Build (2) | |
- name: docker image build | |
run: docker build -t ${{ secrets.DOCKER_USERNAME }}/zero-docker --pull --no-cache . #image명 기입 | |
# DockerHub Login (3) | |
- name: docker login | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
# Docker Hub push (4) | |
- name: docker Hub push | |
run: docker push ${{ secrets.DOCKER_USERNAME }}/zero-docker | |
# AWS EC2 Server Connect & Docker 명령어 실행 (8) | |
- name: Deploy | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} # EC2 인스턴스 퍼블릭 DNS | |
username: ec2-user | |
key: ${{ secrets.PRIVATE_KEY }} # pem 키 | |
# 도커 작업 | |
script: | | |
sudo docker stop zero-docker | |
sudo docker rm zero-docker | |
sudo docker rmi ${{ secrets.DOCKER_USERNAME }}/zero-docker | |
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/zero-docker | |
# redis | |
docker stop my-redis | |
docker rm my-redis | |
docker rmi redis | |
docker pull redis | |
docker network create my-network | |
docker run --name my-redis --network my-network -d redis | |
sudo docker run -it -d -p 8080:8080 --name zero-docker -e TZ=Asia/Seoul --network my-network ${{ secrets.DOCKER_USERNAME }}/zero-docker |