diff --git a/.dockerignore b/.dockerignore index 9b93415..080e210 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,5 @@ .idea *.md -appspec.yml .github !.github/script/pre-commit .gitignore diff --git a/.github/workflows/cd-dev.yml b/.github/workflows/cd-dev.yml index 93fe690..71b5ec2 100644 --- a/.github/workflows/cd-dev.yml +++ b/.github/workflows/cd-dev.yml @@ -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 @@ -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: @@ -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 @@ -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 @@ -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 \ No newline at end of file + - 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 \ No newline at end of file diff --git a/appspec.yml b/appspec.yml deleted file mode 100644 index 27d0af5..0000000 --- a/appspec.yml +++ /dev/null @@ -1,40 +0,0 @@ -version: 0.0 -os: linux - -files: - - source: script/deploy.sh - destination: /home/ubuntu/script/auth - overwrite: yes - - source: script/switch.sh - destination: /home/ubuntu/script/auth - overwrite: yes - - source: script/valid.sh - destination: /home/ubuntu/script/auth - overwrite: yes - - source: pem - destination: /home/ubuntu/property/auth/pem - - source: key - destination: /home/ubuntu/property/auth/key - - source: application.env - destination: /home/ubuntu/env/auth - overwrite: yes -file_exists_behavior: OVERWRITE - -permissions: - - object: /home/ubuntu - pattern: '**' - owner: ubuntu - group: ubuntu - -hooks: - AfterInstall: - - location: script/deploy.sh - timeout: 120 - runas: root - - location: script/switch.sh - timeout: 120 - runas: root - ValidateService: - - location: script/valid.sh - timeout: 60 - runas: root \ No newline at end of file