Skip to content

Commit

Permalink
Create gradle.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
MinsFuture authored Jun 11, 2024
1 parent ea6cd7e commit 0a5aed9
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# github repository actions 페이지에 나타날 이름
name: CI/CD using github actions & docker

# event trigger
# main이나 develop 브랜치에 push가 되었을 때 실행
on:
push:
branches: [ "main", "develop" ]
pull_request:
branches: [ "develop" ]

permissions:
contents: read

jobs:
CI-CD:
runs-on: ubuntu-latest
steps:

# JDK setting - github actions에서 사용할 JDK 설정 (프로젝트나 AWS의 java 버전과 달라도 무방)
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: Gradle Caching
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
# 환경별 yml 파일 생성(1) - application.yml
- name: make application.yml
if: |
contains(github.ref, 'main') ||
contains(github.ref, 'develop')
run: |
mkdir -p ./src/main/resources # resources 폴더 생성 (이미 존재해도 에러 없이 진행)
cd ./src/main/resources # resources 폴더로 이동
echo "${{ secrets.YML }}" > ./application.yml # github actions에서 설정한 값을 application.yml 파일에 쓰기 (덮어쓰기)
shell: bash

# gradle build
- name: Build with Gradle
run: ./gradlew build -x test

# docker build & push to develop
- name: Docker build & push to prod
if: contains(github.ref, 'develop')
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -t ${{ secrets.DOCKER_USERNAME }}/petwalk .
docker push ${{ secrets.DOCKER_USERNAME }}/petwalk

0 comments on commit 0a5aed9

Please sign in to comment.