Skip to content

Commit

Permalink
Merge pull request #327 from Team-Smeme/chore/#296-docker-cicd
Browse files Browse the repository at this point in the history
chore: Docker CICD 환경 구축 (test)
  • Loading branch information
thguss authored Aug 26, 2024
2 parents 9477645 + e87ff55 commit 6f27afb
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 194 deletions.
61 changes: 0 additions & 61 deletions .github/workflows/cd-dev.yml

This file was deleted.

88 changes: 88 additions & 0 deletions .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: deploy-dev

on:
push:
branches: [ develop ] #TODO: change trigger

jobs:
build:
runs-on: ubuntu-20.04

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'temurin'
cache: gradle

- name: Create application-secret.yml
run: |
pwd
cd ./smeem-bootstrap/src/main/resources
touch ./application-secret.yml
echo "${{ secrets.APPLICATION_SECRET_YML }}" >> ./application-secret.yml
cat ./application-secret.yml
- 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_KEY }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Create FireBase JSON file From AWS
run: |
aws s3 cp --region ap-northeast-2 s3://${{ secrets.AWS_BUCKET_NAME }}/json/smeem_fcm.json smeem-notification/src/main/resources/firebase-config/smeem_fcm.json
- name: Build with Gradle
run: |
chmod +x ./gradlew
./gradlew build -x test
shell: bash

- name: Set docker
uses: docker/[email protected]

- name: Login docker
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKERHUB_LOGIN_USERNAME_DEV }}
password: ${{ secrets.DOCKERHUB_LOGIN_ACCESSTOKEN_DEV }}

- name: Build docker image
run: |
docker build --platform linux/amd64 -t smeemdev/smeem-dev:latest -f Dockerfile-prod .
docker push smeemdev/smeem-dev:latest
deploy-cd:
needs: build
runs-on: ubuntu-20.04

steps:
- name: SSH로 서버 접속
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.RELEASE_SERVER_IP_DEV }}
username: ${{ secrets.RELEASE_SERVER_USER_DEV }}
key: ${{ secrets.RELEASE_SERVER_KEY_DEV }}
script: |
cd ~
# deploy.sh 파일 다운로드
wget https://raw.githubusercontent.com/Team-Smeme/Smeme-server-renewal/develop/script/deploy.sh -O deploy.sh
chmod +x deploy.sh
# .env 파일 추가
if ! grep -q "REGISTRY_URL=" .env; then
echo "REGISTRY_URL=${{ secrets.IMAGE_NAME_DEV }}" >> .env
fi
if ! grep -q "IMAGE_NAME=" .env; then
echo "IMAGE_NAME=${{ secrets.REGISTRY_URL_DEV }}" >> .env
fi
# 배포 스크립트 실행
sudo ./deploy.sh
File renamed without changes.
25 changes: 0 additions & 25 deletions appspec.yml

This file was deleted.

49 changes: 49 additions & 0 deletions script/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash
source .env

REGISTRY_URL=${REGISTRY_URL}
IMAGE_NAME=${IMAGE_NAME}
TAG="latest"
CONTAINER_NAME="smeem"
HEALTH_CHECK_URI="/actuator/health"

echo "> Pull docker image"
sudo docker pull "${REGISTRY_URL}"/"${IMAGE_NAME}":"${TAG}"

echo "> Stop running docker container"
if [ "$(docker ps -a -q -f name=${CONTAINER_NAME})" ]; then
sudo docker stop ${CONTAINER_NAME}
sudo docker rm ${CONTAINER_NAME}
fi

echo "> Run docker"
sudo docker run -d --name ${CONTAINER_NAME} -p 80:8080 "${REGISTRY_URL}"/${IMAGE_NAME}:${TAG}

echo "----------------------------------------------------------------------"

sleep 15
for RETRY_COUNT in {1..15}
do
echo "> Health check"

RESPONSE=$(curl -s http://localhost:8080${HEALTH_CHECK_URI})
# shellcheck disable=SC2126
UP_COUNT=$(echo "${RESPONSE}" | grep 'UP' | wc -l)

if [ "${UP_COUNT}" -ge 1 ]
then
echo "> Success"
break
else
echo "> Not run yet"
echo "> 응답 결과: ${RESPONSE}"
fi
if [ "${RETRY_COUNT}" -eq 15 ]
then
echo "> Failed to running server"
sudo docker rm -f ${CONTAINER_NAME}
exit 1
fi
sleep 2
done
echo "----------------------------------------------------------------------"
33 changes: 0 additions & 33 deletions scripts/health_check.sh

This file was deleted.

37 changes: 0 additions & 37 deletions scripts/run_new_was.sh

This file was deleted.

37 changes: 0 additions & 37 deletions scripts/switch.sh

This file was deleted.

1 change: 1 addition & 0 deletions smeem-bootstrap/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies {
implementation project(':smeem-output-oauth:kakao')

implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
}

tasks.bootJar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ private void setHttp(HttpSecurity http) throws Exception {
.authorizeHttpRequests(authorizeHttpRequests ->
authorizeHttpRequests
.requestMatchers(new AntPathRequestMatcher("/api/v2/auth", "POST")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/api/v2/test")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/actuator/health")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/api/v2/test")).permitAll() //TODO: 삭제
.requestMatchers(new AntPathRequestMatcher("/api/v2/versions/client/app")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/api/v2/goals/{type}")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/api/v2/goals")).permitAll()
Expand Down

0 comments on commit 6f27afb

Please sign in to comment.