chore: CICD application.yml 생성 추가 #3
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: CI CD | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4.1.0 | |
- name: Setup Java JDK | |
uses: actions/setup-java@v3.13.0 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Cache | |
uses: actions/cache@v3.3.2 | |
with: | |
path: | | |
~/.gradle/caches | |
~/.gradle/wrapper | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
restore-keys: | | |
${{ runner.os }}-gradle- | |
- name: Create application-dev.yml | |
env: | |
APPLICATION_DEV: ${{secrets.APPLICATION_DEV}} | |
run: echo $APPLICATION_DEV | base64 --decode > src/main/resources/application.yml | |
- name: Grant execute permission for gradlew | |
run: chmod u+x gradlew | |
- name: Build with Gradle | |
run: ./gradlew build -x test | |
- name: Build and push Docker image | |
env: | |
DOCKER_USERNAME: ${{secrets.DOCKER_USERNAME}} | |
DOCKER_PASSWORD: ${{secrets.DOCKER_PASSWORD}} | |
run: | | |
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD | |
docker build -t $DOCKER_USERNAME/alarm . | |
docker push $DOCKER_USERNAME/alarm | |
deploy: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4.1.0 | |
- name: SSH Remote Commands | |
uses: appleboy/ssh-action@v1.0.0 | |
with: | |
host: ${{secrets.EC2_HOST}} | |
username: ubuntu | |
key: ${{secrets.EC2_PRIVATE_KEY}} | |
port: 22 | |
script: | | |
sudo docker-compose down | |
sudo chmod 777 ./deploy.sh | |
sudo ./deploy.sh | |
sudo docker image prune -f |