diff --git a/.github/workflows/click-service-cd.yml b/.github/workflows/click-service-cd.yml index 4fe0420..15573da 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..aacc9d5 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/Dockerfile b/click-service/Dockerfile deleted file mode 100644 index 6973d0d..0000000 --- a/click-service/Dockerfile +++ /dev/null @@ -1,5 +0,0 @@ -FROM openjdk:17-jdk-slim -EXPOSE 8080 -ARG JAR_FILE -COPY ${JAR_FILE} app.jar -ENTRYPOINT ["java", "-jar", "-Dspring.profiles.active=prod", "/app.jar"] diff --git a/click-service/build.gradle b/click-service/build.gradle index 588a7b1..e7e3826 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 = "asia-northeast3-docker.pkg.dev/sanguine-theory-406607/clickme/click-service" + 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/Dockerfile b/transfer-service/Dockerfile deleted file mode 100644 index 2680153..0000000 --- a/transfer-service/Dockerfile +++ /dev/null @@ -1,5 +0,0 @@ -FROM openjdk:17-jdk-slim -EXPOSE 8080 -ARG JAR_FILE -COPY ${JAR_FILE} app.jar -ENTRYPOINT ["java", "-jar", "-Dspring.profiles.active=prod", "createAt=$createAt" ,"/app.jar"] diff --git a/transfer-service/build.gradle b/transfer-service/build.gradle index 0335a4d..7f1da49 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 = "asia-northeast3-docker.pkg.dev/sanguine-theory-406607/clickme/click-service" + 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' @@ -14,11 +35,3 @@ dependencies { testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.batch:spring-batch-test' } - -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/transfer-service/resources.yaml b/transfer-service/resources.yaml index eea7640..7a5ab09 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 - image: ${image}:latest + - name: transfer-service2 + image: ${image} + 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}