From c93ca9e455891b4d6e5b6d001944d5d78fdac46e Mon Sep 17 00:00:00 2001 From: Seungrae Date: Tue, 12 Dec 2023 00:20:57 +0900 Subject: [PATCH] chore: test --- .github/workflows/click-service-cd.yml | 29 +++++------------ .github/workflows/transfer-service-cd.yml | 29 +++++------------ click-service/build.gradle | 31 +++++++++++++------ click-service/resources.yaml | 4 +-- .../clickme/svg/ui/SvgImageV1Controller.java | 3 +- transfer-service/build.gradle | 23 +++++++++++++- transfer-service/resources.yaml | 24 +++++++------- .../src/main/resources/application-prod.yml | 2 ++ 8 files changed, 75 insertions(+), 70 deletions(-) diff --git a/.github/workflows/click-service-cd.yml b/.github/workflows/click-service-cd.yml index 4fe0420..a759d54 100644 --- a/.github/workflows/click-service-cd.yml +++ b/.github/workflows/click-service-cd.yml @@ -13,6 +13,11 @@ env: WORKSTATION_IMAGE: click-service VERSION: '1.0.1' IMAGE: ${{ secrets.REGION }}-docker.pkg.dev/${{ secrets.PROJECT_ID }}/${{ secrets.DOCKER_REPO }}/click-service + REDIS_HOST: ${{secrets.REDIS_HOST}} + REDIS_PORT: ${{secrets.REDIS_PORT}} + DATASOURCE_URL: ${{secrets.DB_URL}} + DATASOURCE_USERNAME: ${{secrets.DB_USERNAME}} + DATASOURCE_PASSWORD: ${{secrets.DB_PASSWORD}} jobs: build: @@ -25,17 +30,6 @@ jobs: - name: Check out Repository uses: actions/checkout@v3 - - name: Set Application Yml - run : | - envsubst < ./src/main/resources/application-prod.yml > ./src/main/resources/application-prod.yml.temp - mv ./src/main/resources/application-prod.yml.temp ./src/main/resources/application-prod.yml - env: - REDIS_HOST: ${{secrets.REDIS_HOST}} - REDIS_PORT: ${{secrets.REDIS_PORT}} - DATASOURCE_URL: ${{secrets.DB_URL}} - DATASOURCE_USERNAME: ${{secrets.DB_USERNAME}} - DATASOURCE_PASSWORD: ${{secrets.DB_PASSWORD}} - - name: Set up google auth id: 'auth' uses: google-github-actions/auth@v1 @@ -61,22 +55,13 @@ jobs: java-version: '17' distribution: 'corretto' - - name: Run tests - run: ../gradlew test - - name: Docker Build if: success() - run: ../gradlew docker - - - name: Docker tag - run: docker tag click-me-${{env.WORKSTATION_IMAGE}}:${{env.VERSION}} ${{env.IMAGE}} - - - name: Docker Push - run: docker push ${{env.IMAGE}} + run: ../gradlew jib - name: Deploy run: | gcloud container clusters get-credentials autopilot-cluster-2 --region ${{env.REGION}} --project ${{env.PROJECT_ID}} - sed "s,\${image},${{ env.IMAGE }},g" resources.yaml > deployment.yaml + sed "s,\${image},${{ env.IMAGE }}:${{ env.IMAGE}},g" resources.yaml > deployment.yaml kubectl apply -f ./deployment.yaml diff --git a/.github/workflows/transfer-service-cd.yml b/.github/workflows/transfer-service-cd.yml index b3539c6..47e0e64 100644 --- a/.github/workflows/transfer-service-cd.yml +++ b/.github/workflows/transfer-service-cd.yml @@ -13,6 +13,11 @@ env: WORKSTATION_IMAGE: transfer-service VERSION: '1.0.1' IMAGE: ${{ secrets.REGION }}-docker.pkg.dev/${{ secrets.PROJECT_ID }}/${{ secrets.DOCKER_REPO }}/transfer-service + REDIS_HOST: ${{secrets.REDIS_HOST}} + REDIS_PORT: ${{secrets.REDIS_PORT}} + DATASOURCE_URL: ${{secrets.DB_URL}} + DATASOURCE_USERNAME: ${{secrets.DB_USERNAME}} + DATASOURCE_PASSWORD: ${{secrets.DB_PASSWORD}} jobs: build: @@ -25,17 +30,6 @@ jobs: - name: Check out Repository uses: actions/checkout@v3 - - name: Set Application Yml - run : | - envsubst < ./src/main/resources/application-prod.yml > ./src/main/resources/application-prod.yml.temp - mv ./src/main/resources/application-prod.yml.temp ./src/main/resources/application-prod.yml - env: - REDIS_HOST: ${{secrets.REDIS_HOST}} - REDIS_PORT: ${{secrets.REDIS_PORT}} - DATASOURCE_URL: ${{secrets.DB_URL}} - DATASOURCE_USERNAME: ${{secrets.DB_USERNAME}} - DATASOURCE_PASSWORD: ${{secrets.DB_PASSWORD}} - - name: Set up google auth id: 'auth' uses: google-github-actions/auth@v1 @@ -61,21 +55,12 @@ jobs: java-version: '17' distribution: 'corretto' - - name: Run tests - run: ../gradlew test - - name: Docker Build if: success() - run: ../gradlew docker - - - name: Docker tag - run: docker tag click-me-${{env.WORKSTATION_IMAGE}}:${{env.VERSION}} ${{env.IMAGE}} - - - name: Docker Push - run: docker push ${{env.IMAGE}} + run: ../gradlew jib - name: Deploy run: | gcloud container clusters get-credentials autopilot-cluster-2 --region ${{env.REGION}} --project ${{env.PROJECT_ID}} - sed "s,\${image},${{ env.IMAGE }},g" resources.yaml > cronJob.yaml + sed "s,\${image},${{ env.IMAGE }}:${{ env.VERSION}},g" resources.yaml > cronJob.yaml kubectl apply -f ./cronJob.yaml diff --git a/click-service/build.gradle b/click-service/build.gradle index 588a7b1..b62cff4 100644 --- a/click-service/build.gradle +++ b/click-service/build.gradle @@ -1,10 +1,31 @@ plugins { - id 'com.palantir.docker' version '0.35.0' + id 'com.google.cloud.tools.jib' version '3.4.0' } group = 'clickme.click' version = '1.0.1' +jib { + from { + image = "eclipse-temurin:17-jre" + } + to { + image = System.getenv("IMAGE") + tags = [version] + } + container { + jvmFlags = ["-Xms258m", "-Xmx1024m"] + environment = [ + 'REDIS_HOST': System.getenv('REDIS_HOST'), + 'REDIS_PORT': System.getenv('REDIS_PORT'), + 'DATASOURCE_URL': System.getenv('DATASOURCE_URL'), + 'DATASOURCE_USERNAME': System.getenv('DATASOURCE_USERNAME'), + 'DATASOURCE_PASSWORD': System.getenv('DATASOURCE_PASSWORD'), + 'SPRING_PROFILES_ACTIVE': 'prod' + ] + } +} + dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-redis' implementation 'org.springframework.boot:spring-boot-starter-data-jpa' @@ -20,11 +41,3 @@ dependencies { tasks.named('test') { useJUnitPlatform() } - -docker { - println(tasks.bootJar.outputs.files) - name rootProject.name+'-'+project.name + ":" + version - dockerfile file('./Dockerfile') - files tasks.bootJar.outputs.files - buildArgs(['JAR_FILE': tasks.bootJar.outputs.files.singleFile.name]) -} diff --git a/click-service/resources.yaml b/click-service/resources.yaml index 05bcf2e..d6975dc 100644 --- a/click-service/resources.yaml +++ b/click-service/resources.yaml @@ -14,7 +14,7 @@ spec: spec: containers: - name: core - image: ${image}:latest + image: ${image} imagePullPolicy: Always ports: - containerPort: 8080 @@ -22,4 +22,4 @@ spec: resources: requests: cpu: 500m - memory: 2000Mi + memory: 1024Mi diff --git a/click-service/src/main/java/clickme/clickme/svg/ui/SvgImageV1Controller.java b/click-service/src/main/java/clickme/clickme/svg/ui/SvgImageV1Controller.java index d2943b5..dc65137 100644 --- a/click-service/src/main/java/clickme/clickme/svg/ui/SvgImageV1Controller.java +++ b/click-service/src/main/java/clickme/clickme/svg/ui/SvgImageV1Controller.java @@ -12,13 +12,14 @@ import javax.xml.transform.TransformerException; import java.io.IOException; +import java.util.concurrent.TimeUnit; @RestController @RequiredArgsConstructor @RequestMapping("/api/v1/svg-image") public class SvgImageV1Controller { - private static final CacheControl DEFAULT_CACHE_CONTROL = CacheControl.noCache(); + private static final CacheControl DEFAULT_CACHE_CONTROL = CacheControl.maxAge(1, TimeUnit.SECONDS); private static final MediaType SVG = MediaType.valueOf("image/svg+xml"); private final SvgImageService svgImageService; diff --git a/transfer-service/build.gradle b/transfer-service/build.gradle index 0335a4d..1568d08 100644 --- a/transfer-service/build.gradle +++ b/transfer-service/build.gradle @@ -1,10 +1,31 @@ plugins { - id 'com.palantir.docker' version '0.35.0' + id 'com.google.cloud.tools.jib' version '3.4.0' } group = 'clickme.transfer' version = '1.0.1' +jib { + from { + image = "eclipse-temurin:17-jre" + } + to { + image = System.getenv("IMAGE") + tags = [version] + } + container { + jvmFlags = ["-Xms258m", "-Xmx1024m"] + environment = [ + 'REDIS_HOST': System.getenv('REDIS_HOST'), + 'REDIS_PORT': System.getenv('REDIS_PORT'), + 'DATASOURCE_URL': System.getenv('DATASOURCE_URL'), + 'DATASOURCE_USERNAME': System.getenv('DATASOURCE_USERNAME'), + 'DATASOURCE_PASSWORD': System.getenv('DATASOURCE_PASSWORD'), + 'SPRING_PROFILES_ACTIVE': 'prod' + ] + } +} + dependencies { implementation 'org.springframework.boot:spring-boot-starter-batch' implementation 'org.springframework.boot:spring-boot-starter-web' diff --git a/transfer-service/resources.yaml b/transfer-service/resources.yaml index eea7640..f719cfe 100644 --- a/transfer-service/resources.yaml +++ b/transfer-service/resources.yaml @@ -1,39 +1,37 @@ apiVersion: batch/v1 kind: CronJob metadata: - name: transfer-service + name: transfer-service1 spec: schedule: 0 15 * * * + successfulJobsHistoryLimit: 5 jobTemplate: spec: template: spec: containers: - - name: transfer-service - image: ${image}:latest + - name: transfer-service1 + image: ${image} + command: ["/bin/sh", "-c"] args: - - "--spring.batch.job.name=syncRedisToMysqlJob" - env: - - name: createAt - value: $(date -u +'%Y-%m-%dT%H:%M') + - "--spring.batch.job.name=syncRedisToMysqlJob createAt=$(date -u +'%Y-%m-%d)" restartPolicy: OnFailure --- apiVersion: batch/v1 kind: CronJob metadata: - name: transfer-service + name: transfer-service2 spec: schedule: 0 15 30 * * + successfulJobsHistoryLimit: 5 jobTemplate: spec: template: spec: containers: - - name: transfer-service + - name: transfer-service2 image: ${image}:latest + command: ["/bin/sh", "-c"] args: - - "--spring.batch.job.name=profileImageUpdateJob" - env: - - name: createAt - value: $(date -u +'%Y-%m-%dT%H:%M') + - "--spring.batch.job.name=profileImageUpdateJob createAt=$(date -u +'%Y-%m-%d)" restartPolicy: OnFailure diff --git a/transfer-service/src/main/resources/application-prod.yml b/transfer-service/src/main/resources/application-prod.yml index 8090d49..af5211b 100644 --- a/transfer-service/src/main/resources/application-prod.yml +++ b/transfer-service/src/main/resources/application-prod.yml @@ -1,4 +1,6 @@ spring: + main: + web-application-type: none data: redis: host: ${REDIS_HOST}