Skip to content

Commit

Permalink
Merge branch 'production' into BE/test
Browse files Browse the repository at this point in the history
  • Loading branch information
reddevilmidzy authored Oct 24, 2024
2 parents 484dbe2 + 02fbd9b commit ff776c3
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 23 deletions.
89 changes: 68 additions & 21 deletions .github/workflows/be_cd-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ jobs:

- name: Image build and push
run: |
docker build --build-arg PROFILE=prod --build-arg DEPENDENCY=build/dependency -t ${{ secrets.DOCKER_REPO_NAME }}/springboot-app:test-latest --platform linux/arm64 .
docker push ${{ secrets.DOCKER_REPO_NAME }}/springboot-app:test-latest
docker build --build-arg PROFILE=prod --build-arg DEPENDENCY=build/dependency -t ${{ secrets.DOCKER_REPO_NAME }}/springboot-app:latest --platform linux/arm64 .
docker push ${{ secrets.DOCKER_REPO_NAME }}/springboot-app:latest
- name: Upload docker-compose yaml script to artifact
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -69,13 +69,21 @@ jobs:
- name: Extract secrets as .be_app-env file
run: |
echo $(pwd)
chmod +x ./deploy.sh # 스크립트에 실행 권한 부여
echo chmod ok
source ./deploy.sh
echo source ok
echo "BLUE_PORT=$BLUE_PORT" >> $GITHUB_ENV
echo "GREEN_PORT=$GREEN_PORT" >> $GITHUB_ENV
cat <<EOF > ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/.be_app-env
# Docker Hub info from Github Secrets
DOCKER_REPO_NAME=${{ secrets.DOCKER_REPO_NAME }}
DOCKER_IMAGE_VERSION=latest
# DB Configuration secrets info from Github Secrets
MYSQL_DB_NAME=${{ secrets.MYSQL_DB_NAME }}
MYSQL_TIME_ZONE=${{ secrets.MYSQL_TIME_ZONE }}
DB_BINDING_PORT=${{ secrets.DB_BINDING_PORT }}
DOCKER_DATA_PATH=${{ secrets.DOCKER_DATA_PATH }}
Expand All @@ -97,21 +105,39 @@ jobs:
INSTANCE_NAME=${{ secrets.INSTANCE_A_NAME }}
# Server App
SERVER_BINDING_PORT=${{ secrets.PRODUCTION_SERVER_BINDING_PORT }}
BLUE_SERVER_BINDING_PORT=${BLUE_PORT}
GREEN_SERVER_BINDING_PORT=${GREEN_PORT}
SERVER_LOGS_PATH=${{ secrets.SERVER_LOGS_PATH }}
EOF
- name: Stop and remove existing containers
- name: remove old spring-app image
run: |
sudo docker image rm -f ${{ secrets.DOCKER_REPO_NAME }}/springboot-app;
- name: Start the new (green/blue) environment
run: |
sudo docker-compose --env-file ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/.be_app-env -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/be_app-docker-compose.yml -p $GREEN_PORT up -d
- name: Wait for new environment to be healthy
run: |
sudo docker-compose --env-file ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/.be_app-env -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/be_app-docker-compose.yml down --rmi all
- name: Deploy docker container
until curl -sf http://localhost:${GREEN_PORT}/api/actuator/health | grep "UP"; do sleep 5; done
- name: Reload NGINX
run: |
sudo docker-compose --env-file ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/.be_app-env -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/be_app-docker-compose.yml up -d
sudo systemctl reload nginx
- name: Stop and remove the old environment
run: |
sudo docker-compose --env-file ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/.be_app-env -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/be_app-docker-compose.yml -p $BLUE_PORT down
- name: Delete Dangling docker images
run: |
sudo docker image prune -a -f
deployB:
environment: production
runs-on: production-ec2-B-runner
needs: deployA
needs: build
defaults:
run:
working-directory: ./backend
Expand All @@ -126,15 +152,20 @@ jobs:
run: |
sudo mv be_app-docker-compose.yml ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/
- name: waiting deployA complete
run: |
sudo ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/scheduler.sh
- name: Extract secrets as .be_app-env file
run: |
echo $(pwd)
chmod +x ./deploy.sh # 스크립트에 실행 권한 부여
echo chmod ok
source ./deploy.sh
echo source ok
echo "BLUE_PORT=$BLUE_PORT" >> $GITHUB_ENV
echo "GREEN_PORT=$GREEN_PORT" >> $GITHUB_ENV
cat <<EOF > ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/.be_app-env
# Docker Hub info from Github Secrets
DOCKER_IMAGE_VERSION=latest
DOCKER_REPO_NAME=${{ secrets.DOCKER_REPO_NAME }}
# DB Configuration secrets info from Github Secrets
Expand All @@ -150,7 +181,6 @@ jobs:
SLAVE_DB_PASSWORD=${{ secrets.SLAVE_DB_PASSWORD }}
DDL_AUTO=${{ secrets.DDL_AUTO }}
# OAUTH & JWT
CLIENT_ID=${{ secrets.CLIENT_ID }}
CLIENT_SECRET=${{ secrets.CLIENT_SECRET }}
Expand All @@ -160,15 +190,32 @@ jobs:
# INSTANCE NAME
INSTANCE_NAME=${{ secrets.INSTANCE_B_NAME }}
# Server App
SERVER_BINDING_PORT=${{ secrets.PRODUCTION_SERVER_BINDING_PORT }}
BLUE_SERVER_BINDING_PORT=${BLUE_PORT}
GREEN_SERVER_BINDING_PORT=${GREEN_PORT}
SERVER_LOGS_PATH=${{ secrets.SERVER_LOGS_PATH }}
EOF
- name: Stop and remove existing containers
- name: remove old spring-app image
run: |
sudo docker image rm -f ${{ secrets.DOCKER_REPO_NAME }}/springboot-app;
- name: Start the new (green/blue) environment
run: |
sudo docker-compose --env-file ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/.be_app-env -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/be_app-docker-compose.yml -p $GREEN_PORT up -d
- name: Wait for new environment to be healthy
run: |
until curl -sf http://localhost:${GREEN_PORT}/api/actuator/health | grep "UP"; do sleep 5; done
- name: Reload NGINX
run: |
sudo systemctl reload nginx
- name: Stop and remove the old environment
run: |
sudo docker-compose --env-file ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/.be_app-env -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/be_app-docker-compose.yml down --rmi all
- name: Deploy docker container
sudo docker-compose --env-file ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/.be_app-env -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/be_app-docker-compose.yml -p $BLUE_PORT down
- name: Delete Dangling docker images
run: |
sudo docker-compose --env-file ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/.be_app-env -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/be_app-docker-compose.yml up -d
sudo docker image prune -a -f
6 changes: 5 additions & 1 deletion .github/workflows/be_cd-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,8 @@ jobs:
- name: Delete Dangling docker images
run: |
sudo docker image prune -a -f
sudo docker-compose --env-file ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/.be_app-env -f ${{ secrets.DOCKER_COMPOSE_YAML_PATH }}/be_app-docker-compose.yml up -d
- name: Delete Dangling docker images
run: |
sudo docker image prune
3 changes: 2 additions & 1 deletion backend/src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ management:
endpoints:
web:
exposure:
include: prometheus
include: prometheus, health
base-path: /api/actuator

server:
tomcat:
accept-count: 300
mbeanregistry:
enabled: true

Expand Down

0 comments on commit ff776c3

Please sign in to comment.