diff --git a/.github/workflows/cron-cicd.yaml b/.github/workflows/cron-cicd.yaml index 6e594f446..ac4cc16e2 100644 --- a/.github/workflows/cron-cicd.yaml +++ b/.github/workflows/cron-cicd.yaml @@ -49,3 +49,18 @@ jobs: chmod +x gradlew ./gradlew jar shell: bash + - name: Main S3에 업로드 + if: ${{ github.ref == 'refs/heads/main' }} + run: | + cp cron/build/libs/cron-*.jar deploy-cron/build + mkdir -p deploy && cp deploy-cron/* deploy/ + zip -r deploy.zip deploy + + aws s3 cp deploy.zip s3://${{ secrets.AWS_S3_MAIN_BUCKET_NAME }}/deploy.zip + + aws deploy create-deployment \ + --application-name ${{ secrets.AWS_CODEDEPLOY_MAIN_APP_NAME }} \ + --deployment-config-name CodeDeployDefault.AllAtOnce \ + --deployment-group-name ${{ secrets.AWS_CODEDEPLOY_MAIN_GROUP_NAME }} \ + --file-exists-behavior OVERWRITE \ + --s3-location bucket=${{ secrets.AWS_S3_MAIN_BUCKET_NAME }},bundleType=zip,key=deploy.zip diff --git a/deploy-cron/Dockerfile b/deploy-cron/Dockerfile new file mode 100644 index 000000000..16a636c2f --- /dev/null +++ b/deploy-cron/Dockerfile @@ -0,0 +1,10 @@ +FROM openjdk:17-jdk-slim + +WORKDIR /app + +RUN apt-get update +RUN apt-get -y install cron + +ADD build/cron-1.0-SNAPSHOT.jar cron.jar + +CMD tail -f /var/log/cron.log diff --git a/deploy-cron/appspec.yml b/deploy-cron/appspec.yml new file mode 100644 index 000000000..daba31f09 --- /dev/null +++ b/deploy-cron/appspec.yml @@ -0,0 +1,18 @@ +version: 0.0 +os: linux +files: + - source: / + destination: /home/ec2-user/cron/zip/ + overwrite: yes + +permissions: + - object: / + pattern: "**" + owner: ec2-user + group: ec2-user + +hooks: + ApplicationStart: + - location: deploy.sh + timeout: 60 + runas: ec2-user diff --git a/deploy-cron/deploy.sh b/deploy-cron/deploy.sh new file mode 100755 index 000000000..a23024628 --- /dev/null +++ b/deploy-cron/deploy.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +mkdir -p /home/ec2-user/cron/zip +cd /home/ec2-user/cron/zip/ + +docker compose down --rmi all +docker compose up -d diff --git a/deploy-cron/docker-compose.yml b/deploy-cron/docker-compose.yml new file mode 100644 index 000000000..d1e726724 --- /dev/null +++ b/deploy-cron/docker-compose.yml @@ -0,0 +1,11 @@ +version: "3.6" + +services: + cabi-cron: + build: + context: . + dockerfile: Dockerfile + container_name: "cabi-cron" + image: "cabi/cron" + volumes: + - ./log:/var/log/ diff --git a/deploy-cron/kotlin-cron b/deploy-cron/kotlin-cron new file mode 100644 index 000000000..f341a61af --- /dev/null +++ b/deploy-cron/kotlin-cron @@ -0,0 +1,2 @@ +* * 1 * * /usr/bin/java -jar /app/cron.jar get-ft-token &>> /var/log/cron.log +