-
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.
Merge pull request #2 from SWM-M3PRO/feature/M3-127-ciCd
M3-127 백엔드 도커 CI/CD 구축
- Loading branch information
Showing
7 changed files
with
136 additions
and
0 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,52 @@ | ||
name: Backend Dev Server CD | ||
|
||
on: | ||
push: | ||
branches: [ "develop" ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-20.04 | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: JDK 17 설치 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '17' | ||
distribution: 'corretto' | ||
|
||
- name: env 설정 | ||
run: | | ||
echo "DB_URI=${{ secrets.DB_URI }}" >> .env | ||
echo "DB_USERNAME=${{ secrets.DB_USERNAME }}" >> .env | ||
echo "DB_PASSWORD=${{ secrets.DB_PASSWORD }}" >> .env | ||
echo "SPRING_PROFILES_ACTIVE=dev" >> .env | ||
- name: gradlew에 실행 권한 부여 | ||
run: chmod +x ./gradlew | ||
|
||
- name: 프로젝트 빌드 | ||
run: ./gradlew clean bootjar | ||
|
||
- name: 압축 | ||
run: zip -r ./ground_flip.zip . | ||
|
||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws-region: ${{ secrets.AWS_REGION}} | ||
|
||
- name: S3에 업로드 | ||
run: aws s3 cp ground_flip.zip s3://ground-flip-dev/deploy/ground_flip.zip --region ap-northeast-2 | ||
|
||
- name: Code Deploy 로 배포 | ||
run: > | ||
aws deploy create-deployment --application-name ground-flip-dev | ||
--deployment-config-name CodeDeployDefault.AllAtOnce | ||
--deployment-group-name ground_flip_dev | ||
--s3-location bucket=ground-flip-dev,bundleType=zip,key=deploy/ground_flip.zip |
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,32 @@ | ||
name: BackEnd CI | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- develop | ||
|
||
jobs: | ||
build_and_test: | ||
runs-on: ubuntu-20.04 | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: JDK 17 설치 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '17' | ||
distribution: 'corretto' | ||
|
||
- name: Setup Gradle | ||
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 | ||
|
||
- name: Grant execute permission to gradlew | ||
run: chmod +x ./gradlew | ||
|
||
- name: Build with Gradle | ||
run: ./gradlew build | ||
|
||
- name: Test with Gradle | ||
run: ./gradlew 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,3 +35,5 @@ out/ | |
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
*.env |
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,4 @@ | ||
FROM openjdk:17-jdk | ||
ARG JAR_FILE=build/libs/*.jar | ||
COPY ${JAR_FILE} app.jar | ||
ENTRYPOINT ["java", "-jar", "app.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
version: 0.0 | ||
os: linux | ||
|
||
files: | ||
- source: / | ||
destination: /home/ubuntu/ground_flip | ||
overwrite: yes | ||
permissions: | ||
- object: / | ||
pattern: "**" | ||
owner: ubuntu | ||
group: ubuntu | ||
|
||
hooks: | ||
AfterInstall: | ||
- location: deploy.sh | ||
timeout: 500 | ||
runas : root |
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,26 @@ | ||
#!/usr/bin/env bash | ||
|
||
APP_NAME="ground_flip" | ||
REPOSITORY=/home/ubuntu/ground_flip | ||
|
||
echo "> Check the currently running container" | ||
CONTAINER_ID=$(docker ps -aqf "name=$APP_NAME") | ||
pwd | ||
ls | ||
if [ -z "$CONTAINER_ID" ]; | ||
then | ||
echo "> No such container is running." | ||
else | ||
echo "> Stop and remove container: $CONTAINER_ID" | ||
docker stop "$CONTAINER_ID" | ||
docker rm "$CONTAINER_ID" | ||
fi | ||
|
||
echo "> Remove previous Docker image" | ||
docker rmi "$APP_NAME" | ||
|
||
echo "> Build Docker image" | ||
docker build -t "$APP_NAME" "$REPOSITORY" | ||
|
||
echo "> Run the Docker container" | ||
docker run -d -p 8080:8080 --env-file /home/ubuntu/ground_flip/.env --name "$APP_NAME" "$APP_NAME" |
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