Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature/#313] CI/CD production 적용 #316

Merged
merged 3 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 48 additions & 46 deletions .github/workflows/depoly-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,59 +10,61 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Checkout sources
uses: actions/checkout@v4

- name: executing remote ssh commands using password
uses: appleboy/ssh-action@master
- name: Set up JDK 11
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'adopt'

- name: Setup Gradle
uses: gradle/gradle-build-action@v3

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Build with Gradle
run: ./gradlew build

- name: copy file via ssh
uses: appleboy/scp-action@master
with:
host: ${{ secrets.IBAS_PROD_HOST }}
username: ${{ secrets.IBAS_PROD_USERNAME }}
passphrase: ${{ secrets.IBAS_PROD_PASSWORD }}
key: ${{ secrets.IBAS_PROD_SSH_KEY }}
passphrase: ${{ secrets.IBAS_PROD_PASSWORD }}
# port: ${{ secrets.PORT }} # default : 22
script: |
set -e
REPO_PATH=${{ secrets.IBAS_PROD_PATH }}/Inhabas.com-api

if [ -d "$REPO_PATH" ]; then
cd $REPO_PATH
git checkout dev
git pull
else
echo "Error: Directory $REPO_PATH does not exist."
exit 1
fi

chmod u+x gradlew
./gradlew build -x test

CONTAINER_NAME=api-prod
IMAGE_NAME=api-prod

if [ $(docker ps -q -f name=$CONTAINER_NAME) ]; then
docker stop $CONTAINER_NAME
docker rm $CONTAINER_NAME
fi

if [ $(docker images -q $IMAGE_NAME) ]; then
docker rmi $IMAGE_NAME
fi

docker build -t $IMAGE_NAME .
docker run -d --name $CONTAINER_NAME --network host -p 8080:8080 -e SPRING_CONFIG_IMPORT=configserver:http://localhost:8888 $IMAGE_NAME

echo "Deployment done"
source: "docker-compose.yml"
target: ${{ secrets.IBAS_PROD_DEPLOY_PATH }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Notify Discord on Success
if: success()
uses: discord-actions/message@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
webhookUrl: ${{ secrets.DISCORD_WEBHOOK_URL }}
message: "Backend production deployment completed successfully!"
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Notify Discord on Failure
if: failure()
uses: discord-actions/message@v2
- name: Build and push
uses: docker/build-push-action@v6
with:
webhookUrl: ${{ secrets.DISCORD_WEBHOOK_URL }}
message: "Backend production deployment failed..."
context: .
push: true
tags: ${{ secrets.DOCKERHUB_STORAGE }}:prod

- name: execute deploy shell script via ssh
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.IBAS_PROD_HOST }}
username: ${{ secrets.IBAS_PROD_USERNAME }}
key: ${{ secrets.IBAS_PROD_SSH_KEY }}
passphrase: ${{ secrets.IBAS_PROD_PASSWORD }}
# port: ${{ secrets.PORT }} # default : 22
script: |
bash ${{ secrets.IBAS_PROD_DEPLOY_PATH }}/deploy.sh
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3'
services:
prod1:
image: whtmdgus56/ibas-config:prod
container_name: backend/prod1
container_name: backend-prod1
ports:
- "8080:8080"
environment:
Expand All @@ -11,7 +11,7 @@ services:

prod2:
image: whtmdgus56/ibas-config:prod
container_name: backend/prod2
container_name: backend-prod2
ports:
- "8081:8081"
environment:
Expand All @@ -20,7 +20,7 @@ services:

dev1:
image: whtmdgus56/ibas-config:dev
container_name: backend/dev1
container_name: backend-dev1
ports:
- "8082:8082"
environment:
Expand All @@ -29,7 +29,7 @@ services:

dev2:
image: whtmdgus56/ibas-config:dev
container_name: backend/dev2
container_name: backend-dev2
ports:
- "8083:8083"
environment:
Expand Down
Loading