Skip to content

Commit

Permalink
[MERGE] refactor/#28 -> dev
Browse files Browse the repository at this point in the history
[REFACTOR/#28] 배포 방식 변경
  • Loading branch information
yummygyudon authored Dec 29, 2024
2 parents 8a9ad25 + ffb88ba commit fce8b5b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 82 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.idea
*.md
appspec.yml
.github
!.github/script/pre-commit
.gitignore
Expand Down
94 changes: 53 additions & 41 deletions .github/workflows/cd-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
jobs:

build-and-push-image:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -20,10 +20,6 @@ jobs:
distribution: 'corretto'
cache: gradle

- name: 🤝 Grant execute permission for gradlew
run: chmod +x ./gradlew
shell: bash

- name: 🔒 Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
Expand All @@ -34,7 +30,6 @@ jobs:
- name: ⚙️ Create Property File
run: |
touch ./gradle.properties
echo "${{ secrets.PROPERTY_GRADLE }}" >> ./gradle.properties
- name: 🧱 Build Image and Push to ECR
Expand All @@ -47,10 +42,9 @@ jobs:
docker tag $AWS_ECR_REPO:latest public.ecr.aws/$AWS_ACCOUNT_ID/$AWS_ECR_REPO:latest
docker push public.ecr.aws/$AWS_ACCOUNT_ID/$AWS_ECR_REPO:latest
create-deploy:
deploy:
needs: build-and-push-image
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -70,50 +64,68 @@ jobs:
JWT_PRIVATE_KEY: ${{ secrets.JWT_PRIVATE_KEY }}
S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }}
run: |
mkdir ./pem
mkdir ./key
aws s3 cp --region $REGION \
s3://$S3_BUCKET/dev/static/$JWT_PUBLIC_KEY ./pem/$JWT_PUBLIC_KEY
s3://$S3_BUCKET/dev/static/$JWT_PUBLIC_KEY ./$JWT_PUBLIC_KEY
aws s3 cp --region $REGION \
s3://$S3_BUCKET/dev/static/$JWT_PRIVATE_KEY ./pem/$JWT_PRIVATE_KEY
s3://$S3_BUCKET/dev/static/$JWT_PRIVATE_KEY ./$JWT_PRIVATE_KEY
aws s3 cp --region $REGION \
s3://$S3_BUCKET/dev/static/$APPLE_KEY ./key/$APPLE_KEY
s3://$S3_BUCKET/dev/static/$APPLE_KEY ./$APPLE_KEY
- name: 📝 Copy Script File
- name: 📝 Copy Script and Property File
env:
REGION: ${{ secrets.AWS_REGION }}
S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }}
S3_ENV_FILE_NAME: ${{ secrets.ENV_FILE_NAME_DEV }}
run: |
mkdir ./script
aws s3 cp --region $REGION \
s3://$S3_BUCKET/dev/script/deploy.sh ./script/deploy.sh
s3://$S3_BUCKET/dev/script/deploy.sh ./deploy.sh
aws s3 cp --region $REGION \
s3://$S3_BUCKET/dev/script/switch.sh ./script/switch.sh
s3://$S3_BUCKET/dev/script/switch.sh ./switch.sh
aws s3 cp --region $REGION \
s3://$S3_BUCKET/dev/script/valid.sh ./script/valid.sh
s3://$S3_BUCKET/dev/script/valid.sh ./valid.sh
aws s3 cp --region $REGION \
s3://$S3_BUCKET/dev/$S3_ENV_FILE_NAME ./application.env

- name: 📁 Make files to zip
run: |
pwd
ls -l
zip -r ./$GITHUB_SHA.zip ./script ./pem ./key ./appspec.yml ./application.env
shell: bash

- name: 🚀 Upload Property Zip to S3 and Create Code Deploy
env:
REGION: ${{ secrets.AWS_REGION }}
DEPLOY_APPLICATION: ${{ secrets.AWS_DEPLOY_APPLICATION }}
DEPLOY_GROUP: ${{ secrets.AWS_DEPLOY_GROUP_DEV }}
S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }}
run: |
aws s3 cp --region $REGION ./$GITHUB_SHA.zip s3://$S3_BUCKET/dev/deploy/$GITHUB_SHA.zip
aws deploy create-deployment --application-name $DEPLOY_APPLICATION \
--deployment-config-name CodeDeployDefault.AllAtOnce \
--deployment-group-name $DEPLOY_GROUP \
--s3-location bucket=$S3_BUCKET,bundleType=zip,key=dev/deploy/$GITHUB_SHA.zip
- name: 🔄 Transfer Files to Server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST_DEV }}
username: ubuntu
key: ${{ secrets.PEM_KEY_DEV }}
port: 22
source: "deploy.sh,switch.sh,valid.sh,application.env,${{ secrets.APPLE_KEY }},${{ secrets.JWT_PUBLIC_KEY }},${{ secrets.JWT_PRIVATE_KEY }}"
target: /home/ubuntu/deploy-temp/auth

- name: 🚀SSH command deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST_DEV }}
username: ubuntu
key: ${{ secrets.PEM_KEY_DEV }}
port: 22
script: |
mkdir -p /home/ubuntu/script/auth
mkdir -p /home/ubuntu/property/auth/key
mkdir -p /home/ubuntu/property/auth/pem
mkdir -p /home/ubuntu/env/auth
mv /home/ubuntu/deploy-temp/auth/deploy.sh /home/ubuntu/script/auth/deploy.sh
mv /home/ubuntu/deploy-temp/auth/switch.sh /home/ubuntu/script/auth/switch.sh
mv /home/ubuntu/deploy-temp/auth/valid.sh /home/ubuntu/script/auth/valid.sh
mv /home/ubuntu/deploy-temp/auth/application.env /home/ubuntu/env/auth/application.env
mv /home/ubuntu/deploy-temp/auth/${{ secrets.APPLE_KEY_NAME }} /home/ubuntu/property/auth/key/${{ secrets.APPLE_KEY_NAME }}
mv /home/ubuntu/deploy-temp/auth/${{ secrets.JWT_PUBLIC_KEY }} /home/ubuntu/property/auth/pem/${{ secrets.JWT_PUBLIC_KEY }}
mv /home/ubuntu/deploy-temp/auth/${{ secrets.JWT_PRIVATE_KEY }} /home/ubuntu/property/auth/pem/${{ secrets.JWT_PRIVATE_KEY }}
sudo chmod +x /home/ubuntu/script/auth/deploy.sh
sudo chmod +x /home/ubuntu/script/auth/switch.sh
sudo chmod +x /home/ubuntu/script/auth/valid.sh
sudo chmod +r /home/ubuntu/env/auth/application.env
sudo chmod +r /home/ubuntu/property/auth/key/${{ secrets.APPLE_KEY }}
sudo chmod +r /home/ubuntu/property/auth/pem/${{ secrets.JWT_PUBLIC_KEY }}
sudo chmod +r /home/ubuntu/property/auth/pem/${{ secrets.JWT_PRIVATE_KEY }}
/home/ubuntu/script/op/deploy.sh
/home/ubuntu/script/op/switch.sh
/home/ubuntu/script/op/valid.sh
40 changes: 0 additions & 40 deletions appspec.yml

This file was deleted.

0 comments on commit fce8b5b

Please sign in to comment.