-
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 #12 from byeolhaha/feat/2
chore : docker 관련 설정
- Loading branch information
Showing
4 changed files
with
56 additions
and
30 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 |
---|---|---|
|
@@ -38,8 +38,25 @@ jobs: | |
|
||
# 순차적으로 실행될 단계들을 정의하는 섹션 | ||
steps: | ||
- name: Checkout code | ||
uses: actions/[email protected] | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Install mongosh | ||
run: | | ||
sudo apt-get install gnupg | ||
wget -qO- https://www.mongodb.org/static/pgp/server-7.0.asc | sudo tee /etc/apt/trusted.gpg.d/server-7.0.asc | ||
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list | ||
sudo apt-get update | ||
sudo apt-get install -y mongodb-mongosh | ||
mongosh --version | ||
- name: Initalize MongoDB | ||
run: | | ||
mongosh --host localhost:27017 -u admin -p admin --authenticationDatabase admin <<EOF | ||
db = db.getSiblingDB('APP-DB'); | ||
db.createUser({ user: 'APP-USERNAME', pwd: 'APP-PASSWORD', roles: [{ role: 'readWrite', db: 'APP-DB' }] }) | ||
db.createCollection('APP-COLLECTION'); | ||
EOF | ||
# Do whatever you like in here | ||
- name: Set up JDK 17 | ||
uses: actions/[email protected] | ||
|
@@ -59,26 +76,30 @@ jobs: | |
echo "${{ secrets.APPLICATION_TEST_YML_CONTENT }}" > src/test/resources/application.yml | ||
echo "${{ secrets.GCP_BUCKET_CONTENT }}" > src/main/resources/meritz-420004-93e56cbdf236.json | ||
- name: Clean with gradle | ||
run: ./gradlew clean | ||
|
||
- name: Build with gradle | ||
run: ./gradlew build | ||
|
||
- name: Make Zip File | ||
run: zip -qq -r ./$GITHUB_SHA.zip . | ||
shell: bash | ||
- name: Docker login | ||
if: contains(github.ref, 'main') | ||
run: | | ||
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | ||
docker build -f Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/hello-counsellor . | ||
docker push ${{ secrets.DOCKER_USERNAME }}/hello-counsellor | ||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
- name: Deploy to prod | ||
uses: appleboy/ssh-action@master | ||
id: deploy-prod | ||
if: contains(github.ref, 'main') | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_PRIVATE_ACCESS_KEY }} | ||
aws-region: ap-northeast-2 | ||
|
||
- name: Upload to S3 | ||
run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://$BUCKET_NAME/$PROJECT_NAME/$GITHUB_SHA.zip | ||
|
||
- name: Code Deploy To EC2 instance | ||
run: aws deploy create-deployment | ||
--application-name $CODE_DEPLOY_APP_NAME | ||
--deployment-config-name CodeDeployDefault.AllAtOnce | ||
--deployment-group-name $DEPLOYMENT_GROUP_NAME | ||
--s3-location bucket=$BUCKET_NAME,bundleType=zip,key=$PROJECT_NAME/$GITHUB_SHA.zip | ||
host: ${{ secrets.HOST_PROD }} # EC2 퍼블릭 IPv4 DNS | ||
username: ubuntu | ||
key: ${{ secrets.PRIVATE_KEY }} | ||
envs: GITHUB_SHA | ||
script: | | ||
sudo docker ps | ||
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/hello-counsellor | ||
sudo docker run -d -p 8080:8080 ${{ secrets.DOCKER_USERNAME }}/hello-counsellor | ||
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 |
---|---|---|
|
@@ -58,13 +58,12 @@ jobs: | |
EOF | ||
# Do whatever you like in here | ||
- name: Checkout code | ||
uses: actions/[email protected] | ||
- name: Set up JDK 17 | ||
uses: actions/[email protected] | ||
with: | ||
java-version: '17' | ||
distribution: 'corretto' | ||
|
||
- name: Grant execute permission for gradlew | ||
run: chmod +x ./gradlew | ||
|
||
|
@@ -81,11 +80,4 @@ jobs: | |
run: ./gradlew clean | ||
|
||
- name: Build with gradle | ||
run: ./gradlew build | ||
|
||
- name: Upload Test Report | ||
if: failure() # 이 단계는 테스트 실패시에만 실행됩니다. | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: test-report | ||
path: build/reports/tests/test | ||
run: ./gradlew build |
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,9 @@ | ||
FROM openjdk:17-alpine | ||
|
||
EXPOSE 8080 | ||
|
||
ARG JAR_FILE=build/libs/*.jar | ||
|
||
COPY ${JAR_FILE} app.jar | ||
|
||
ENTRYPOINT ["nohup", "java", "-jar", "/app.jar", ">", "nohup-prod.out", "2>&1", "&"] |
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 |
---|---|---|
|
@@ -130,3 +130,7 @@ bootJar { | |
into 'static/docs' | ||
} | ||
} | ||
|
||
jar { | ||
enabled = false | ||
} |