-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
1,853 additions
and
270 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
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 |
---|---|---|
@@ -1,187 +1,183 @@ | ||
name: develop-CD | ||
|
||
on: | ||
push: | ||
branches: [ "develop" ] | ||
push: | ||
branches: [ "develop" ] | ||
|
||
permissions: | ||
contents: write | ||
contents: write | ||
|
||
jobs: | ||
move-files: | ||
name: move-files | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
submodules: true | ||
token: ${{ secrets.MOABAM_SUBMODULE_KEY }} | ||
|
||
- name: Github Actions IP 획득 | ||
id: ip | ||
uses: haythem/[email protected] | ||
|
||
- name: AWS Credentials 설정 | ||
uses: aws-actions/configure-aws-credentials@v4 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws-region: ${{ secrets.AWS_REGION }} | ||
|
||
- name: Github Actions IP 보안그룹 추가 | ||
run: | | ||
aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32 | ||
- name: 디렉토리 생성 | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.EC2_INSTANCE_HOST }} | ||
port: 22 | ||
username: ubuntu | ||
key: ${{ secrets.EC2_INSTANCE_PRIVATE_KEY }} | ||
script: | | ||
mkdir -p /home/ubuntu/moabam/nginx | ||
- name: Docker env 파일 생성 | ||
run: | ||
echo "${{secrets.DEV_ENV_FILE }}" > ./.env | ||
|
||
- name: 서버로 전송 기본 파일들 전송 | ||
uses: appleboy/scp-action@master | ||
with: | ||
host: ${{ secrets.EC2_INSTANCE_HOST }} | ||
port: 22 | ||
username: ${{ secrets.EC2_INSTANCE_USERNAME }} | ||
key: ${{ secrets.EC2_INSTANCE_PRIVATE_KEY }} | ||
source: "./.env, ./docker-compose-dev.yml, init-letsencrypt.sh, ./scripts/*" | ||
target: "/home/ubuntu/moabam" | ||
|
||
- name: 서버로 전송 "nginx conf 파일들" | ||
uses: appleboy/scp-action@master | ||
with: | ||
host: ${{ secrets.EC2_INSTANCE_HOST }} | ||
port: 22 | ||
username: ${{ secrets.EC2_INSTANCE_USERNAME }} | ||
key: ${{ secrets.EC2_INSTANCE_PRIVATE_KEY }} | ||
source: "./nginx/*" | ||
target: "/home/ubuntu/moabam" | ||
|
||
- name: 파일 세팅 | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.EC2_INSTANCE_HOST }} | ||
port: 22 | ||
username: ubuntu | ||
key: ${{ secrets.EC2_INSTANCE_PRIVATE_KEY }} | ||
script: | | ||
cd /home/ubuntu/moabam | ||
mv docker-compose-dev.yml docker-compose.yml | ||
chmod +x ./scripts/deploy-dev.sh | ||
chmod +x ./scripts/init-letsencrypt.sh | ||
chmod +x ./scripts/init-nginx-converter.sh | ||
- name: Github Actions IP 보안그룹에서 삭제 | ||
if: always() | ||
run: | | ||
aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32 | ||
deploy: | ||
name: deploy | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
submodules: true | ||
token: ${{ secrets.MOABAM_SUBMODULE_KEY }} | ||
|
||
- name: JDK 17 셋업 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '17' | ||
distribution: 'corretto' | ||
|
||
- name: Gradle 캐싱 | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/.gradle/caches | ||
~/.gradle/wrapper | ||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | ||
restore-keys: | | ||
${{ runner.os }}-gradle- | ||
- name: Gradle Grant 권한 부여 | ||
run: chmod +x gradlew | ||
|
||
- name: 테스트용 MySQL 도커 컨테이너 실행 | ||
run: | | ||
sudo docker run -d -p 3306:3306 --env MYSQL_DATABASE=test --env MYSQL_ROOT_PASSWORD=test mysql:8.0.33 | ||
- name: 테스트용 Redis 도커 컨테이너 실행 | ||
run: | | ||
sudo docker run --name redis-test -p 6379:6379 -d redis | ||
- name: Gradle 빌드 | ||
uses: gradle/gradle-build-action@bd5760595778326ba7f1441bcf7e88b49de61a25 # v2.6.0 | ||
with: | ||
arguments: build | ||
|
||
- name: 멀티플랫폼 위한 Docker Buildx 설정 | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Docker Hub 로그인 | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ secrets.DOCKER_HUB_USERNAME }} | ||
password: ${{ secrets.DOCKER_HUB_TOKEN }} | ||
|
||
- name: Docker Hub 빌드하고 푸시 | ||
uses: docker/build-push-action@v4 | ||
with: | ||
context: . | ||
push: true | ||
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPOSITORY }}:${{ secrets.DOCKER_HUB_DEV_TAG }} | ||
build-args: | | ||
"SPRING_ACTIVE_PROFILES=dev" | ||
platforms: | | ||
linux/amd64 | ||
linux/arm64 | ||
- name: Github Actions IP 획득 | ||
id: ip | ||
uses: haythem/[email protected] | ||
|
||
- name: AWS Credentials 설정 | ||
uses: aws-actions/configure-aws-credentials@v4 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws-region: ${{ secrets.AWS_REGION }} | ||
|
||
- name: Github Actions IP 보안그룹 추가 | ||
run: | | ||
aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32 | ||
- name: EC2 서버에 배포 | ||
uses: appleboy/ssh-action@master | ||
id: deploy-dev | ||
if: contains(github.ref, 'dev') | ||
with: | ||
host: ${{ secrets.EC2_INSTANCE_HOST }} | ||
port: 22 | ||
username: ubuntu | ||
key: ${{ secrets.EC2_INSTANCE_PRIVATE_KEY }} | ||
source: "docker-compose-dev.yml" | ||
script: | | ||
cd /home/ubuntu/moabam | ||
echo ${{ secrets.DOCKER_HUB_TOKEN }} | docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} --password-stdin | ||
sudo docker pull ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPOSITORY }}:${{ secrets.DOCKER_HUB_DEV_TAG }} | ||
./scripts/deploy-dev.sh | ||
docker rm `docker ps -a -q` | ||
docker rmi $(docker images -aq) | ||
echo "### 배포 완료 ###" | ||
- name: Github Actions IP 보안그룹에서 삭제 | ||
if: always() | ||
run: | | ||
aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32 | ||
move-files: | ||
name: move-files | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
submodules: true | ||
token: ${{ secrets.MOABAM_SUBMODULE_KEY }} | ||
|
||
- name: Github Actions IP 획득 | ||
id: ip | ||
uses: haythem/[email protected] | ||
|
||
- name: AWS Credentials 설정 | ||
uses: aws-actions/configure-aws-credentials@v4 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws-region: ${{ secrets.AWS_REGION }} | ||
|
||
- name: Github Actions IP 보안그룹 추가 | ||
run: | | ||
aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32 | ||
- name: 디렉토리 생성 | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.EC2_INSTANCE_HOST }} | ||
port: 22 | ||
username: ubuntu | ||
key: ${{ secrets.EC2_INSTANCE_PRIVATE_KEY }} | ||
script: | | ||
mkdir -p /home/ubuntu/moabam/nginx | ||
- name: Docker env 파일 생성 | ||
run: | ||
echo "${{secrets.DEV_ENV_FILE }}" > ./.env | ||
|
||
- name: 서버로 전송 기본 파일들 전송 | ||
uses: appleboy/scp-action@master | ||
with: | ||
host: ${{ secrets.EC2_INSTANCE_HOST }} | ||
port: 22 | ||
username: ${{ secrets.EC2_INSTANCE_USERNAME }} | ||
key: ${{ secrets.EC2_INSTANCE_PRIVATE_KEY }} | ||
source: "./.env, ./docker-compose-dev.yml, init-letsencrypt.sh, ./scripts/*" | ||
target: "/home/ubuntu/moabam" | ||
|
||
- name: 서버로 전송 "nginx conf 파일들" | ||
uses: appleboy/scp-action@master | ||
with: | ||
host: ${{ secrets.EC2_INSTANCE_HOST }} | ||
port: 22 | ||
username: ${{ secrets.EC2_INSTANCE_USERNAME }} | ||
key: ${{ secrets.EC2_INSTANCE_PRIVATE_KEY }} | ||
source: "./nginx/*" | ||
target: "/home/ubuntu/moabam" | ||
|
||
- name: 파일 세팅 | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.EC2_INSTANCE_HOST }} | ||
port: 22 | ||
username: ubuntu | ||
key: ${{ secrets.EC2_INSTANCE_PRIVATE_KEY }} | ||
script: | | ||
cd /home/ubuntu/moabam | ||
mv docker-compose-dev.yml docker-compose.yml | ||
chmod +x ./scripts/deploy-dev.sh | ||
chmod +x ./scripts/init-letsencrypt.sh | ||
chmod +x ./scripts/init-nginx-converter.sh | ||
- name: Github Actions IP 보안그룹에서 삭제 | ||
if: always() | ||
run: | | ||
aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32 | ||
deploy: | ||
name: deploy | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
submodules: true | ||
token: ${{ secrets.MOABAM_SUBMODULE_KEY }} | ||
|
||
- name: JDK 17 셋업 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '17' | ||
distribution: 'corretto' | ||
|
||
- name: Gradle 캐싱 | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/.gradle/caches | ||
~/.gradle/wrapper | ||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | ||
restore-keys: | | ||
${{ runner.os }}-gradle- | ||
- name: Gradle Grant 권한 부여 | ||
run: chmod +x gradlew | ||
|
||
- name: 테스트용 MySQL 도커 컨테이너 실행 | ||
run: | | ||
sudo docker run -d -p 3306:3306 --env MYSQL_DATABASE=test --env MYSQL_ROOT_PASSWORD=test mysql:8.0.33 | ||
- name: Gradle 빌드 | ||
uses: gradle/gradle-build-action@bd5760595778326ba7f1441bcf7e88b49de61a25 # v2.6.0 | ||
with: | ||
arguments: build | ||
|
||
- name: 멀티플랫폼 위한 Docker Buildx 설정 | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Docker Hub 로그인 | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ secrets.DOCKER_HUB_USERNAME }} | ||
password: ${{ secrets.DOCKER_HUB_TOKEN }} | ||
|
||
- name: Docker Hub 빌드하고 푸시 | ||
uses: docker/build-push-action@v4 | ||
with: | ||
context: . | ||
push: true | ||
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPOSITORY }}:${{ secrets.DOCKER_HUB_DEV_TAG }} | ||
build-args: | | ||
"SPRING_ACTIVE_PROFILES=dev" | ||
platforms: | | ||
linux/amd64 | ||
linux/arm64 | ||
- name: Github Actions IP 획득 | ||
id: ip | ||
uses: haythem/[email protected] | ||
|
||
- name: AWS Credentials 설정 | ||
uses: aws-actions/configure-aws-credentials@v4 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws-region: ${{ secrets.AWS_REGION }} | ||
|
||
- name: Github Actions IP 보안그룹 추가 | ||
run: | | ||
aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32 | ||
- name: EC2 서버에 배포 | ||
uses: appleboy/ssh-action@master | ||
id: deploy-dev | ||
if: contains(github.ref, 'dev') | ||
with: | ||
host: ${{ secrets.EC2_INSTANCE_HOST }} | ||
port: 22 | ||
username: ubuntu | ||
key: ${{ secrets.EC2_INSTANCE_PRIVATE_KEY }} | ||
source: "docker-compose-dev.yml" | ||
script: | | ||
cd /home/ubuntu/moabam | ||
echo ${{ secrets.DOCKER_HUB_TOKEN }} | docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} --password-stdin | ||
sudo docker pull ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPOSITORY }}:${{ secrets.DOCKER_HUB_DEV_TAG }} | ||
./scripts/deploy-dev.sh | ||
docker rm `docker ps -a -q` | ||
docker rmi $(docker images -aq) | ||
echo "### 배포 완료 ###" | ||
- name: Github Actions IP 보안그룹에서 삭제 | ||
if: always() | ||
run: | | ||
aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32 |
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 |
---|---|---|
|
@@ -122,3 +122,4 @@ logs/ | |
application-*.yml | ||
src/main/resources/config | ||
!application-test.yml | ||
dump.rdb |
Oops, something went wrong.