From 9c067e9f0de57182d41404d6e20145041ae364a6 Mon Sep 17 00:00:00 2001 From: donggyu Date: Tue, 5 Sep 2023 14:27:55 +0900 Subject: [PATCH] =?UTF-8?q?[BE]=20ci-cd=20=EC=83=9D=EC=84=B1=20=EB=8B=A8,?= =?UTF-8?q?=20aws=EB=82=B4=EB=B6=80=EC=97=90=EC=84=9Ccron=EC=84=A4?= =?UTF-8?q?=EC=A0=95=EC=9D=84=20=ED=95=98=EC=97=AC=EC=95=BC=ED=95=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cron-cicd.yaml | 15 +++++++++++++++ deploy-cron/Dockerfile | 10 ++++++++++ deploy-cron/appspec.yml | 18 ++++++++++++++++++ deploy-cron/deploy.sh | 7 +++++++ deploy-cron/docker-compose.yml | 11 +++++++++++ deploy-cron/kotlin-cron | 2 ++ 6 files changed, 63 insertions(+) create mode 100644 deploy-cron/Dockerfile create mode 100644 deploy-cron/appspec.yml create mode 100755 deploy-cron/deploy.sh create mode 100644 deploy-cron/docker-compose.yml create mode 100644 deploy-cron/kotlin-cron 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 +