-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
92 additions
and
8 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
name: Java CD with Gradle | ||
|
||
on: | ||
push: | ||
branches: [ main, deploy/cd ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
CD: | ||
runs-on: ubuntu-latest | ||
steps: | ||
## jdk setting | ||
- uses: actions/checkout@v3 | ||
- name: Set up JDK 11 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '11' | ||
distribution: 'temurin' # https://github.com/actions/setup-java | ||
|
||
## gradle caching | ||
- 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- | ||
## gradle build | ||
- name: Build with Gradle | ||
run: ./gradlew build -x test | ||
|
||
## text application build | ||
- name: Test with Gradle | ||
run: ./gradlew test | ||
|
||
## docker build & push to production | ||
- name: Docker build & push to prod | ||
run: | | ||
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | ||
docker build -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }} . | ||
docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }} | ||
## deploy to production | ||
- name: Deploy to prod | ||
uses: appleboy/ssh-action@master | ||
id: deploy-prod | ||
with: | ||
host: ${{ secrets.HOST_PROD }} | ||
username: ec2-user | ||
key: ${{ secrets.PRIVATE_KEY }} | ||
envs: GITHUB_SHA | ||
script: | | ||
sudo docker rm -f $(docker ps -qa) | ||
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }} | ||
touch .env | ||
echo DB_PORT=${{ secrets.DB_PORT }} >> .env | ||
echo DB_NAME=${{ secrets.DB_NAME }} >> .env | ||
echo DB_USERNAME=${{ secrets.DB_USERNAME }} >> .env | ||
echo DB_PASSWORD=${{ secrets.DB_PASSWORD }} >> .env | ||
echo DB_ROOT_PASSWORD=${{ secrets.DB_ROOT_PASSWORD }} >> .env | ||
echo JWT_SECRET=${{ secrets.JWT_SECRET }} >> .env | ||
echo REDIS_HOST=${{ secrets.REDIS_HOST }} >> .env | ||
echo REDIS_PORT=${{ secrets.REDIS_PORT }} >> .env | ||
echo SOCKET_PORT=${{ secrets.SOCKET_PORT }} >> .env | ||
cat .env | ||
docker-compose up -d | ||
docker image prune -f | ||
## time | ||
current-time: | ||
needs: CD | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Get Current Time | ||
uses: 1466587594/get-current-time@v2 | ||
id: current-time | ||
with: | ||
format: YYYY-MM-DDTHH:mm:ss | ||
utcOffset: "+09:00" # 기준이 UTC이기 때문에 한국시간인 KST를 맞추기 위해 +9시간 추가 | ||
|
||
- name: Print Current Time | ||
run: echo "Current Time=${{steps.current-time.outputs.formattedTime}}" # current-time 에서 지정한 포맷대로 현재 시간 출력 | ||
shell: bash |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,5 @@ | ||
FROM openjdk:11-jdk | ||
FROM openjdk:11-jdk AS builder | ||
COPY ./ ./ | ||
RUN ./gradlew clean | ||
RUN chmod +x ./gradlew | ||
RUN ./gradlew bootJAR | ||
|
||
FROM openjdk:11-jdk | ||
COPY --from=builder build/libs/*.jar app.jar | ||
ARG JAR_FILE=build/libs/*.jar | ||
COPY ${JAR_FILE} app.jar | ||
ENV TZ=Asia/Seoul | ||
ENTRYPOINT ["java","-jar","-Dspring.profiles.active=prod","/app.jar"] |