diff --git a/.github/workflows/cd-dev.yml b/.github/workflows/cd-dev.yml index 9b0e9fa9..0fd5988c 100644 --- a/.github/workflows/cd-dev.yml +++ b/.github/workflows/cd-dev.yml @@ -6,14 +6,14 @@ on: branches: [ develop ] jobs: - build-and-push-and-deploy: + build-and-push: runs-on: ubuntu-22.04 steps: - - name: Checkout + - name: ✅ Checkout uses: actions/checkout@v3 - - name: Set up JDK 17 + - name: ⚙️ Set up JDK 17 uses: actions/setup-java@v3 with: java-version: 17 @@ -27,16 +27,6 @@ jobs: aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }} aws-region: ${{ secrets.AWS_REGION }} - - name: Grant execute permission for gradlew - run: chmod +x ./gradlew - shell: bash - - - name: Create Property - run: | - - mkdir -p ./operation-api/src/main/resources/static - echo "${{ secrets.APPLE_KEY }}" | base64 --decode > ./operation-api/src/main/resources/static/${{ secrets.APPLE_KEY_NAME }} - - name: 🧱 Build Image and Push to ECR env: AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }} @@ -47,36 +37,63 @@ 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 - - name: 📝 Copy Script File + deploy: + needs: build-and-push + runs-on: ubuntu-latest + + steps: + - name: ✅ Checkout + uses: actions/checkout@v3 + + - 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: 📝 Copy Files from S3 env: REGION: ${{ secrets.AWS_REGION }} + APPLE_KEY_NAME: ${{ secrets.APPLE_KEY_NAME }} S3_BUCKET: ${{ secrets.AWS_BUCKET_NAME }} 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 - - aws s3 cp --region $REGION \ - s3://$S3_BUCKET/dev/dev.env application.env + s3://$S3_BUCKET/dev/script/valid.sh ./valid.sh - - name: Make zip file - run: zip -r ./$GITHUB_SHA.zip ./script ./appspec.yml ./application.env - shell: bash + aws s3 cp --region $REGION \ + s3://$S3_BUCKET/dev/dev.env ./application.env + aws s3 cp --region $REGION \ + s3://$S3_BUCKET/dev/static/$APPLE_KEY ./$APPLE_KEY_NAME - - 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_BUCKET_NAME }} - 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: 🚀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/op + mkdir -p /home/ubuntu/property/op + mkdir -p /home/ubuntu/env/op + + echo $(cat deploy.sh) > /home/ubuntu/script/op/deploy.sh + echo $(cat switch.sh) > /home/ubuntu/script/op/switch.sh + echo $(cat valid.sh) > /home/ubuntu/script/op/valid.sh + echo $(cat application.env) > /home/ubuntu/env/op/application.env + echo $(cat ${{ secrets.APPLE_KEY_NAME }}) > /home/ubuntu/property/op/key/${{ secrets.APPLE_KEY_NAME }} + + sudo chmod +x /home/ubuntu/script/op/deploy.sh + sudo chmod +x /home/ubuntu/script/op/switch.sh + sudo chmod +x /home/ubuntu/script/op/valid.sh + sudo chmod +r /home/ubuntu/env/op/application.env + sudo chmod +r /home/ubuntu/property/op/key/${{ secrets.APPLE_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