Create nginx-release.conf #69
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: [infra/#8-cicd, release] | |
permissions: | |
contents: read | |
jobs: | |
build-image: | |
runs-on: ubuntu-latest | |
environment: bee-market | |
defaults: | |
run: | |
shell: bash | |
working-directory: ./be/carrot | |
steps: | |
- uses: actions/checkout@v3 | |
## JDK Setting | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'adopt' | |
# gradle caching - 빌드 시간 향상 | |
- name: Gradle Caching | |
uses: actions/cache@v3 | |
with: | |
# cache directory setting | |
path: | |
~/.gradle/caches | |
~/.gradle/wrapper | |
# separate cache key setting | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
# 이전에 생성된 캐시 복원에 사용할 키 지정 | |
# 캐시가 없거나 만료되었을 때, 이 키를 기반으로 이전에 생성된 캐시를 찾아 복원 | |
restore-keys: | | |
${{ runner.os }}-gradle- | |
# 환경별 yml 파일 생성 - application.yml | |
- name: make application.yml | |
if: | | |
contains(github.ref, 'release') || | |
contains(github.ref, 'infra/#8-cicd') | |
run: | | |
mkdir ./src/main/resources | |
cd ./src/main/resources | |
touch ./application.yml | |
echo "${{ secrets.APPLICATION_RELEASE }}" > ./application.yml | |
shell: bash | |
# gradlew 실행을 위한 실행 권한 부여 | |
- name: Grant execute permission for gradlew | |
run: chmod +x ./gradlew | |
# Clean Gradle Build | |
- name: Clean with Gradle | |
run: ./gradlew clean | |
# Gradle을 이용하여 빌드 수행 | |
- name: Build with Gradle | |
run: ./gradlew build -x test | |
# docker build & push to devleop | |
- name: Docker build & push to release | |
if: contains(github.ref, 'release') || | |
contains(github.ref, 'infra/#8-cicd') | |
run: | | |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | |
docker build -f Dockerfile-release -t ${{ secrets.DOCKER_USERNAME }}/bee_market_app_release . | |
docker push ${{ secrets.DOCKER_USERNAME }}/bee_market_app_release | |
build-react-image: | |
runs-on: ubuntu-latest | |
environment: bee-market | |
defaults: | |
run: | |
shell: bash | |
working-directory: ./fe | |
strategy: | |
matrix: | |
node-version: [ 18.x ] | |
steps: | |
- uses: actions/checkout@v3 | |
# 환경별 .env 파일 생성 | |
- name: make ".env" file | |
if: | | |
contains(github.ref, 'release') || | |
contains(github.ref, 'infra/#8-cicd') | |
run: | | |
touch ./.env | |
echo "${{ secrets.DOT_ENV }}" > ./.env | |
shell: bash | |
- name: Docker build to release | |
if: contains(github.ref, 'release') || | |
contains(github.ref, 'infra/#8-cicd') | |
run: | | |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | |
docker build -f Dockerfile-release -t ${{ secrets.DOCKER_USERNAME }}/bee_market_web_release . | |
docker push ${{ secrets.DOCKER_USERNAME }}/bee_market_web_release | |
cd-pipeline: | |
needs: | |
- build-image | |
- build-react-image | |
name: continuos deploy | |
runs-on: ubuntu-latest | |
environment: bee-market | |
steps: | |
- uses: actions/checkout@master | |
# nginx-release.conf 파일 EC2에 업로드 | |
- name: copy nginx-release.conf file via ssh password | |
uses: appleboy/scp-action@master | |
if: contains(github.ref, 'release') || | |
contains(github.ref, 'infra/#8-cicd') | |
with: | |
host: ${{ secrets.HOST }} | |
username: ubuntu | |
key: ${{ secrets.PRIVATE_KEY }} | |
port: 22 | |
source: "./nginx/nginx-release.conf" | |
target: "/home/ubuntu/" | |
# docker-compose-release.yml 파일 EC2에 업로드 | |
- name: copy docker-compose-release file via ssh password | |
uses: appleboy/scp-action@master | |
if: contains(github.ref, 'release') || | |
contains(github.ref, 'infra/#8-cicd') | |
with: | |
host: ${{ secrets.HOST }} | |
username: ubuntu | |
key: ${{ secrets.PRIVATE_KEY }} | |
port: 22 | |
source: "docker-compose-release.yml" | |
target: "/home/ubuntu/" | |
# docker-compose-release 실행 | |
- name: Deploy to release | |
uses: appleboy/ssh-action@master | |
if: contains(github.ref, 'release') | |
|| contains(github.ref, 'infra/#8-cicd') | |
with: | |
host: ${{ secrets.HOST }} # EC2 인스턴스 퍼블릭 DNS | |
username: ubuntu | |
key: ${{ secrets.PRIVATE_KEY }} # pem 키 | |
port: 22 | |
script: | | |
sudo chmod 666 /var/run/docker.sock | |
docker-compose -f docker-compose-release.yml down -v | |
docker-compose -f docker-compose-release.yml pull | |
docker-compose -f docker-compose-release.yml up -d | |
docker image prune -f |