-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from Likelion12/3-be-cicd-구축
- Loading branch information
Showing
29 changed files
with
283 additions
and
111 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,93 @@ | ||
name: Java CI/CD with Gradle | ||
|
||
on: | ||
push: | ||
branches: [ "develop" ] | ||
pull_request: | ||
branches: [ "develop"] | ||
types: [ closed ] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
env: | ||
PROFILE: ${{ secrets.PROFILE }} | ||
DB_PROD_HOST: ${{ secrets.DB_PROD_HOST }} | ||
DB_PROD_USERNAME: ${{ secrets.DB_PROD_USERNAME }} | ||
DB_PROD_PASSWD: ${{ secrets.DB_PROD_PASSWD }} | ||
WAS_HOST: ${{ secrets.WAS_HOST }} | ||
JWT_SECRET: ${{ secrets.JWT_SECRET }} | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
|
||
- name: Build with Gradle | ||
run: ./gradlew --warning-mode all build -i | ||
|
||
docker-build: | ||
runs-on: ubuntu-latest | ||
needs: build | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
|
||
- name: Grant execute permission for gradlew | ||
run: chmod +x gradlew | ||
|
||
- name: Build with Gradle (without Test) | ||
run: ./gradlew clean build -x test --stacktrace | ||
|
||
- name: Docker Hub build & push | ||
run: | | ||
docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} -p ${{ secrets.DOCKER_HUB_PWD }} | ||
docker build --build-arg PROFILE=${{ secrets.PROFILE }} \ | ||
--build-arg DB_PROD_HOST=${{ secrets.DB_PROD_HOST }} \ | ||
--build-arg DB_PROD_USERNAME=${{ secrets.DB_PROD_USERNAME }} \ | ||
--build-arg DB_PROD_PASSWD=${{ secrets.DB_PROD_PASSWD }} \ | ||
--build-arg JWT_SECRET=${{ secrets.JWT_SECRET }} \ | ||
-t likelion12/likelion12baby:latest . | ||
docker images | ||
docker push likelion12/likelion12baby:latest | ||
- name: deploy | ||
uses: appleboy/ssh-action@master | ||
with: | ||
username: ubuntu | ||
host: ${{ secrets.WAS_HOST }} | ||
key: ${{ secrets.PRIVATE_KEY }} | ||
port: ${{ secrets.WAS_PORT }} | ||
script: | | ||
echo "Checking Docker installation..." | ||
CONTAINER_ID=$(sudo docker ps -q --filter ancestor=${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPO_NAME }}) | ||
if [ ! -z "$CONTAINER_ID" ]; then | ||
echo "Docker could not be found, installing Docker" | ||
sudo docker stop $CONTAINER_ID | ||
sudo docker rm $CONTAINER_ID | ||
fi | ||
echo "Pulling Docker image..." | ||
sudo docker pull ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPO_NAME }} | ||
sudo docker run -d -e PROFILE=${{ secrets.PROFILE }} \ | ||
-e DB_PROD_HOST=${{ secrets.DB_PROD_HOST }} \ | ||
-e DB_PROD_USERNAME=${{ secrets.DB_PROD_USERNAME }} \ | ||
-e DB_PROD_PASSWD=${{ secrets.DB_PROD_PASSWD }} \ | ||
-e JWT_SECRET=${{ secrets.JWT_SECRET }} \ | ||
-p 8080:8080 ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPO_NAME }} | ||
sudo docker logs $(sudo docker ps -q --filter ancestor=${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPO_NAME }}) | ||
sudo docker image prune -f |
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,5 +1,4 @@ | ||
HELP.md | ||
.gradle | ||
build/ | ||
!gradle/wrapper/gradle-wrapper.jar | ||
!**/src/main/**/build/ | ||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
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,2 @@ | ||
#Tue Jul 30 01:49:23 KST 2024 | ||
gradle.version=8.9 |
Binary file not shown.
Binary file not shown.
Empty file.
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,27 @@ | ||
FROM openjdk:17-alpine | ||
|
||
ARG PROFILE | ||
ARG DB_PROD_HOST | ||
ARG DB_PROD_USERNAME | ||
ARG DB_PROD_PASSWD | ||
ARG JWT_SECRET | ||
|
||
ENV PROFILE=${PROFILE} | ||
ENV DB_PROD_HOST=${DB_PROD_HOST} | ||
ENV DB_PROD_USERNAME=${DB_PROD_USERNAME} | ||
ENV DB_PROD_PASSWD=${DB_PROD_PASSWD} | ||
ENV JWT_SECRET=${JWT_SECRET} | ||
|
||
# Install Redis | ||
RUN apk update && \ | ||
apk add redis | ||
|
||
# Copy application JAR | ||
ARG JAR_PATH=build/libs/*.jar | ||
COPY ${JAR_PATH} /home/server.jar | ||
|
||
# Expose ports | ||
EXPOSE 8080 6379 | ||
|
||
# Entry point | ||
ENTRYPOINT sh -c "redis-server --daemonize yes && java -jar /home/server.jar" |
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
Binary file not shown.
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
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
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,92 +1,94 @@ | ||
@rem | ||
@rem Copyright 2015 the original author or authors. | ||
@rem | ||
@rem Licensed under the Apache License, Version 2.0 (the "License"); | ||
@rem you may not use this file except in compliance with the License. | ||
@rem You may obtain a copy of the License at | ||
@rem | ||
@rem https://www.apache.org/licenses/LICENSE-2.0 | ||
@rem | ||
@rem Unless required by applicable law or agreed to in writing, software | ||
@rem distributed under the License is distributed on an "AS IS" BASIS, | ||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
@rem See the License for the specific language governing permissions and | ||
@rem limitations under the License. | ||
@rem | ||
|
||
@if "%DEBUG%"=="" @echo off | ||
@rem ########################################################################## | ||
@rem | ||
@rem Gradle startup script for Windows | ||
@rem | ||
@rem ########################################################################## | ||
|
||
@rem Set local scope for the variables with windows NT shell | ||
if "%OS%"=="Windows_NT" setlocal | ||
|
||
set DIRNAME=%~dp0 | ||
if "%DIRNAME%"=="" set DIRNAME=. | ||
@rem This is normally unused | ||
set APP_BASE_NAME=%~n0 | ||
set APP_HOME=%DIRNAME% | ||
|
||
@rem Resolve any "." and ".." in APP_HOME to make it shorter. | ||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi | ||
|
||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. | ||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" | ||
|
||
@rem Find java.exe | ||
if defined JAVA_HOME goto findJavaFromJavaHome | ||
|
||
set JAVA_EXE=java.exe | ||
%JAVA_EXE% -version >NUL 2>&1 | ||
if %ERRORLEVEL% equ 0 goto execute | ||
|
||
echo. 1>&2 | ||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 | ||
echo. 1>&2 | ||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2 | ||
echo location of your Java installation. 1>&2 | ||
|
||
goto fail | ||
|
||
:findJavaFromJavaHome | ||
set JAVA_HOME=%JAVA_HOME:"=% | ||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe | ||
|
||
if exist "%JAVA_EXE%" goto execute | ||
|
||
echo. 1>&2 | ||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 | ||
echo. 1>&2 | ||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2 | ||
echo location of your Java installation. 1>&2 | ||
|
||
goto fail | ||
|
||
:execute | ||
@rem Setup the command line | ||
|
||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar | ||
|
||
|
||
@rem Execute Gradle | ||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* | ||
|
||
:end | ||
@rem End local scope for the variables with windows NT shell | ||
if %ERRORLEVEL% equ 0 goto mainEnd | ||
|
||
:fail | ||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of | ||
rem the _cmd.exe /c_ return code! | ||
set EXIT_CODE=%ERRORLEVEL% | ||
if %EXIT_CODE% equ 0 set EXIT_CODE=1 | ||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% | ||
exit /b %EXIT_CODE% | ||
|
||
:mainEnd | ||
if "%OS%"=="Windows_NT" endlocal | ||
|
||
:omega | ||
@rem | ||
@rem Copyright 2015 the original author or authors. | ||
@rem | ||
@rem Licensed under the Apache License, Version 2.0 (the "License"); | ||
@rem you may not use this file except in compliance with the License. | ||
@rem You may obtain a copy of the License at | ||
@rem | ||
@rem https://www.apache.org/licenses/LICENSE-2.0 | ||
@rem | ||
@rem Unless required by applicable law or agreed to in writing, software | ||
@rem distributed under the License is distributed on an "AS IS" BASIS, | ||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
@rem See the License for the specific language governing permissions and | ||
@rem limitations under the License. | ||
@rem | ||
@rem SPDX-License-Identifier: Apache-2.0 | ||
@rem | ||
|
||
@if "%DEBUG%"=="" @echo off | ||
@rem ########################################################################## | ||
@rem | ||
@rem Gradle startup script for Windows | ||
@rem | ||
@rem ########################################################################## | ||
|
||
@rem Set local scope for the variables with windows NT shell | ||
if "%OS%"=="Windows_NT" setlocal | ||
|
||
set DIRNAME=%~dp0 | ||
if "%DIRNAME%"=="" set DIRNAME=. | ||
@rem This is normally unused | ||
set APP_BASE_NAME=%~n0 | ||
set APP_HOME=%DIRNAME% | ||
|
||
@rem Resolve any "." and ".." in APP_HOME to make it shorter. | ||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi | ||
|
||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. | ||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" | ||
|
||
@rem Find java.exe | ||
if defined JAVA_HOME goto findJavaFromJavaHome | ||
|
||
set JAVA_EXE=java.exe | ||
%JAVA_EXE% -version >NUL 2>&1 | ||
if %ERRORLEVEL% equ 0 goto execute | ||
|
||
echo. 1>&2 | ||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 | ||
echo. 1>&2 | ||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2 | ||
echo location of your Java installation. 1>&2 | ||
|
||
goto fail | ||
|
||
:findJavaFromJavaHome | ||
set JAVA_HOME=%JAVA_HOME:"=% | ||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe | ||
|
||
if exist "%JAVA_EXE%" goto execute | ||
|
||
echo. 1>&2 | ||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 | ||
echo. 1>&2 | ||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2 | ||
echo location of your Java installation. 1>&2 | ||
|
||
goto fail | ||
|
||
:execute | ||
@rem Setup the command line | ||
|
||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar | ||
|
||
|
||
@rem Execute Gradle | ||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* | ||
|
||
:end | ||
@rem End local scope for the variables with windows NT shell | ||
if %ERRORLEVEL% equ 0 goto mainEnd | ||
|
||
:fail | ||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of | ||
rem the _cmd.exe /c_ return code! | ||
set EXIT_CODE=%ERRORLEVEL% | ||
if %EXIT_CODE% equ 0 set EXIT_CODE=1 | ||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% | ||
exit /b %EXIT_CODE% | ||
|
||
:mainEnd | ||
if "%OS%"=="Windows_NT" endlocal | ||
|
||
:omega |
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,13 @@ | ||
package com.example.likelion12; | ||
|
||
import lombok.Getter; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class TestController { | ||
@GetMapping("") | ||
public String likelion(){ | ||
return "test"; | ||
} | ||
} |
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
Oops, something went wrong.