From 258e65dc9f194177ad9ae8965a77946f4d6ba8f2 Mon Sep 17 00:00:00 2001 From: Seungrae Date: Fri, 1 Dec 2023 23:34:44 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20CI/CD=EB=A5=BC=20=EA=B5=AC=EC=B6=95?= =?UTF-8?q?=ED=95=9C=EB=8B=A4.=20(#61)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: github action ci파일 작성 * feat: github action cd파일 작성 * fix: 경로 설정 수정 * fix: 잘못된 부분 수정 * fix: 잘못된 부분 수정 * feat: GKE 관련 부분 추가 --- .github/workflows/click-service-cd.yml | 81 +++++++++++++++++++++++ .github/workflows/click-service-ci.yml | 34 ++++++++++ .github/workflows/transfer-service-cd.yml | 65 ++++++++++++++++++ .github/workflows/transfer-service-ci.yml | 34 ++++++++++ Dockerfile | 2 +- click-service/resources.yaml | 31 +++++++++ 6 files changed, 246 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/click-service-cd.yml create mode 100644 .github/workflows/click-service-ci.yml create mode 100644 .github/workflows/transfer-service-cd.yml create mode 100644 .github/workflows/transfer-service-ci.yml create mode 100644 click-service/resources.yaml diff --git a/.github/workflows/click-service-cd.yml b/.github/workflows/click-service-cd.yml new file mode 100644 index 0000000..f584c90 --- /dev/null +++ b/.github/workflows/click-service-cd.yml @@ -0,0 +1,81 @@ +name: cd for click-service +on: + push: + branches: [ "main" ] + +env: + PROJECT_ID: ${{ secrets.PROJECT_ID }} + DOCKER_REPO: ${{ secrets.DOCKER_REPO }} + REGION: ${{ secrets.REGION }} + WORKSTATION_IMAGE: click-service + VERSION: '1.0.0' + +jobs: + build: + runs-on: ubuntu-22.04 + defaults: + run: + working-directory: ./click-service + + steps: + - name: Check out Repository + uses: actions/checkout@v3 + + - name: Set Kubernetes Yaml + uses: microsoft/variable-substitution@v1 + with: + files: ./resources.yaml + env: + image: ${{env.REGION}}-docker.pkg.dev/${{env.PROJECT_ID}}/${{env.DOCKER_REPO}}/${{env.WORKSTATION_IMAGE}} + spec.template.spec.containers.image: ${{env.image}} + + - name: Set Application Yml + uses: microsoft/variable-substitution@v1 + with: + files: ./src/main/resources/application-prod.yml + env: + spring.data.redis.host: ${{secrets.REDIS_HOST}} + spring.data.redis.port: ${{secrets.REDIS_PORT}} + spring.datasource.url: ${{secrets.DB_URL}} + spring.datasource.username: ${{secrets.DB_USERNAME}} + spring.datasource.password: ${{secrets.DB_PASSWORD}} + spec.template.spec.containers.image: ${{env.image}} + + - name: Set up google auth + id: 'auth' + uses: google-github-actions/auth@v1 + with: + credentials_json: ${{ secrets.GCE_SA_KEY }} + + - id: get-credentials + uses: google-github-actions/get-gke-credentials@v1 + with: + cluster_name: autopilot-cluster-1 + location: ${{env.REGION}} + + - name: Set up Cloud SDK + uses: google-github-actions/setup-gcloud@v1 + with: + project_id: ${{ env.PROJECT_ID }} + + - name: Set up Java version + uses: actions/setup-java@v1 + with: + java-version: '17' + + - 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}} + + - name: Deploy + run: kubectl apply -f ./resources.yaml + diff --git a/.github/workflows/click-service-ci.yml b/.github/workflows/click-service-ci.yml new file mode 100644 index 0000000..90d285c --- /dev/null +++ b/.github/workflows/click-service-ci.yml @@ -0,0 +1,34 @@ +name: CI-click-service + +on: + pull_request: + branches: [ main ] + paths: + - click-service/** + - .github/** + +jobs: + ci: + runs-on: ubuntu-22.04 + + defaults: + run: + working-directory: ./click-service + + steps: + - name: Check out Repository + uses: actions/checkout@v3 + + - name: set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'corretto' + + - name: Grant execute permission gradlew + run: chmod +x ../gradlew + + - name: Test with Gradle + run: ../gradlew test + + diff --git a/.github/workflows/transfer-service-cd.yml b/.github/workflows/transfer-service-cd.yml new file mode 100644 index 0000000..634191b --- /dev/null +++ b/.github/workflows/transfer-service-cd.yml @@ -0,0 +1,65 @@ +name: cd for transfer-service +on: + push: + branches: [ "main" ] + +env: + PROJECT_ID: ${{ secrets.PROJECT_ID }} + DOCKER_REPO: ${{ secrets.DOCKER_REPO }} + REGION: ${{ secrets.REGION }} + WORKSTATION_IMAGE: transfer-service + VERSION: '1.0.0' + +jobs: + build: + runs-on: ubuntu-22.04 + defaults: + run: + working-directory: ./transfer-service + + steps: + - name: Check out Repository + uses: actions/checkout@v3 + + - name: Set Application Yml + uses: microsoft/variable-substitution@v1 + with: + files: ./src/main/resources/application-prod.yml + env: + spring.data.redis.host: ${{secrets.REDIS_HOST}} + spring.data.redis.port: ${{secrets.REDIS_PORT}} + spring.datasource.url: ${{secrets.DB_URL}} + spring.datasource.username: ${{secrets.DB_USERNAME}} + spring.datasource.password: ${{secrets.DB_PASSWORD}} + spec.template.spec.containers.image: ${{env.image}} + + - name: Set up google auth + id: 'auth' + uses: google-github-actions/auth@v1 + with: + credentials_json: ${{ secrets.GCE_SA_KEY }} + + - name: Set up Cloud SDK + uses: google-github-actions/setup-gcloud@v1 + with: + project_id: ${{ env.PROJECT_ID }} + + - name: Set up Java version + uses: actions/setup-java@v1 + with: + java-version: '17' + + - name: Run tests + run: ../gradlew test + + - name: Docker Build + if: success() + run: ../gradlew docker + + - name: Docker tag + env: + image: ${{env.REGION}}-docker.pkg.dev/${{env.PROJECT_ID}}/${{env.DOCKER_REPO}}/${{env.WORKSTATION_IMAGE}} + run: docker tag click-me-${{env.WORKSTATION_IMAGE}}:${env.VERSION} ${{env.image}} + + - name: Docker Push + run: docker push ${{env.image}} diff --git a/.github/workflows/transfer-service-ci.yml b/.github/workflows/transfer-service-ci.yml new file mode 100644 index 0000000..b610f14 --- /dev/null +++ b/.github/workflows/transfer-service-ci.yml @@ -0,0 +1,34 @@ +name: CI-transfer-service + +on: + pull_request: + branches: [ main ] + paths: + - transfer-service/** + - .github/** + +jobs: + ci: + runs-on: ubuntu-22.04 + + defaults: + run: + working-directory: ./transfer-service + + steps: + - name: Check out Repository + uses: actions/checkout@v3 + + - name: set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'corretto' + + - name: Grant execute permission gradlew + run: chmod +x ../gradlew + + - name: Test with Gradle + run: ../gradlew test + + diff --git a/Dockerfile b/Dockerfile index 8a0a467..4d4f6a2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,4 +2,4 @@ FROM openjdk:17-jdk-slim EXPOSE 8080 ARG JAR_FILE COPY ${JAR_FILE} app.jar -ENTRYPOINT ["java", "-jar", "/app.jar"] +ENTRYPOINT ["java", "-jar", "-Dspring.profiles.active=prod" ,"/app.jar"] diff --git a/click-service/resources.yaml b/click-service/resources.yaml new file mode 100644 index 0000000..818c780 --- /dev/null +++ b/click-service/resources.yaml @@ -0,0 +1,31 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: click-service +spec: + selector: + matchLabels: + app: click-service + replicas: 1 + template: + metadata: + labels: + app: click-service + spec: + containers: + - name: core + image: ${image} +--- +apiVersion: v1 +kind: Service +metadata: + name: click-me-nginx +spec: + type: NodePort + ports: + - port: 80 + protocol: TCP + targetPort: 8080 + selector: + app: click-service +