Skip to content

Commit

Permalink
chore: test
Browse files Browse the repository at this point in the history
  • Loading branch information
Seungpang committed Dec 13, 2023
1 parent feab441 commit 0e33101
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 89 deletions.
29 changes: 7 additions & 22 deletions .github/workflows/click-service-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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
29 changes: 7 additions & 22 deletions .github/workflows/transfer-service-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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
5 changes: 0 additions & 5 deletions click-service/Dockerfile

This file was deleted.

31 changes: 22 additions & 9 deletions click-service/build.gradle
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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])
}
4 changes: 2 additions & 2 deletions click-service/resources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ spec:
spec:
containers:
- name: core
image: ${image}:latest
image: ${image}
imagePullPolicy: Always
ports:
- containerPort: 8080
protocol: TCP
resources:
requests:
cpu: 500m
memory: 2000Mi
memory: 1024Mi
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 0 additions & 5 deletions transfer-service/Dockerfile

This file was deleted.

31 changes: 22 additions & 9 deletions transfer-service/build.gradle
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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])
}
26 changes: 12 additions & 14 deletions transfer-service/resources.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions transfer-service/src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
spring:
main:
web-application-type: none
data:
redis:
host: ${REDIS_HOST}
Expand Down

0 comments on commit 0e33101

Please sign in to comment.