Skip to content

[18기_이윤서] Github Action을 이용한 CI/CD 배포 미션 제출합니다. #3

[18기_이윤서] Github Action을 이용한 CI/CD 배포 미션 제출합니다.

[18기_이윤서] Github Action을 이용한 CI/CD 배포 미션 제출합니다. #3

Workflow file for this run

name: Deploy Development Server # 깃헙 레포지토리의 액션 탭에 노출되는 workflow의 이름으로 옵셔널한 값
## develop 브랜치에 push가 되면 실행됩니다
on:
push:
branches: [ "yoonsseo" ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
# 우리의 branch를 현재 비어있는 ubuntu에 내려받도록 함
- name: checkout
uses: actions/checkout@v3
## java 다운받기
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Set up NTP
run: |
sudo apt-get update
sudo apt-get install -y ntp
sudo service ntp start

Check failure on line 32 in .github/workflows/gradle.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/gradle.yml

Invalid workflow file

You have an error in your yaml syntax on line 32
- name: Set APPLICATION.YML
run: |
# cd ./src/main/resources
# touch ./application.yml
mkdir -p src/main/resources
echo "${{ secrets.APPLICATION_YML }}" | base64 --decode > src/main/resources/application.yml
find src
shell: bash
# ## gradle build
# - name: Build with Gradle
# run: ./gradlew bootJar
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
- name: Build with Gradle
run: ./gradlew build -x test # test 빼고 JAR 생성
# ./gradlew bootJar
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
## 웹 이미지 빌드 및 도커허브에 push
- name: Docker Image Build and Push
run: |
docker build -t app -f Dockerfile .
docker tag app ${{ secrets.DOCKER_USERNAME }}/ceos18dangn:latest
docker push ${{ secrets.DOCKER_USERNAME }}/ceos18dangn:latest
- name: Deploy to EC2
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_PUBLIC_DNS }}
username: ubuntu
key: ${{ secrets.PEM_KEY }}
script: |
sudo docker rm $(sudo docker ps -a)
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/ceos18dangn
docker-compose up -d
sudo docker image prune -f
# cd /home/ubuntu/
#
# sudo touch docker-compose.yml
# echo "${{ secrets.DOCKER_COMPOSE }}" | sudo tee docker-compose.yml > /dev/null
#
## ## docker-compose 실행
# sudo chmod 666 /var/run/docker.sock
# # 현재 사용자에게 Docker 소켓에 대한 읽기 및 쓰기 권한 부여
# sudo docker rm -f $(docker ps -qa)
# # docker ps -qa : 현재 실행 중인 모든 컨테이너의 ID 반환
# # -f 옵션으로 모든 컨테이너 강제로 중지하고 제거
# sudo docker pull ${{ secrets.DOCKER_USERNAME }}/ceos18dangn
# # Docker Hub에서 해당 이미지 가져오기
# docker-compose -f docker-compose.yml up -d
# #docker-compose -f docker-compose.yml --env-file ./.env up -d
# docker image prune -f
# # 사용하지 않는 모든 Docker 이미지 강제로 삭제
# docker pull ${{ secrets.DOCKER_USERNAME }}/ceos18dangn:latest
# docker stop $(docker ps -a -q)
# docker-compose up -d
# docker image prune -a -f