Skip to content

Dependency Check 수정 #31

Dependency Check 수정

Dependency Check 수정 #31

name: ticketaka-backend-performance
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'zulu'
- name: Cache SonarQube packages
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Gradle packages
uses: actions/cache@v4
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle
- name: Build and analyze with SonarQube
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
run: |
chmod +x ./gradlew
./gradlew build sonar --info
# Dependency Check (Java 프로젝트)
- name: Dependency Check (Java)
uses: dependency-check/Dependency-Check_Action@main
env:
JAVA_HOME: /opt/jdk
id: Depcheck
with:
project: "Ticketaka"
path: "./"
format: "HTML"
# args: >
# --failOnCVSS 7
# --enableRetired
- name: Upload Test results
uses: actions/upload-artifact@master
with:
name: Depcheck report
path: ${{github.workspace}}/reports
# Trivy 사용해 Harbor에 Push한 이미지 취약점 검사
- name: Run Trivy vulnerability scanner (pre-build)
uses: aquasecurity/trivy-action@master
with:
scan-type: 'fs'
format: 'table'
exit-code: '1'
ignore-unfixed: true
severity: 'CRITICAL'
# 취약점이 발견되면 배포 중단
- name: Check Trivy Scan Result
if: failure()
run: |
echo "보안 취약점이 감지되었습니다. 배포를 중단합니다."
exit 1
# Auto-tagging 및 Release 생성
- name: Bump version and push tag
id: tag_version
uses: mathieudutour/[email protected] # 가져다 쓸 auto tagging 프로그램
with:
github_token: ${{ secrets.GITHUB_TOKEN }} # secrets.GITHUB_TOKEN 는 자동생성됨
- name: Create a GitHub release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.tag_version.outputs.new_tag }}
release_name: Release ${{ steps.tag_version.outputs.new_tag }}
body: ${{ steps.tag_version.outputs.changelog }}
# Docker 이미지 빌드 및 Harbor에 Push
- name: Docker meta
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
with:
images: harbor.hotsun.store/ticketaka/ticketaka-performance
tag-semver: |
{{version}}
{{major}}.{{minor}}
- name: Login to Harbor
run: |
echo "${{ secrets.HARBOR_PASSWORD }}" | docker login harbor.hotsun.store -u "${{ secrets.HARBOR_USERNAME }}" --password-stdin
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build and Push Docker Image
id: build-and-push
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
platforms: linux/amd64
push: true
tags: harbor.hotsun.store/ticketaka/ticketaka-performance:${{ steps.tag_version.outputs.new_tag }}
- name: Get Image Digest
run: echo "DIGEST=${{ steps.build-and-push.outputs.digest }}" >> $GITHUB_ENV
- name: Install Cosign
uses: sigstore/[email protected]
- name: Sign Image with Cosign (Using Digest)
env:
COSIGN_PRIVATE_KEY: ${{ secrets.COSIGN_PRIVATE_KEY }}
COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }}
run: |
cosign sign --yes --key env://COSIGN_PRIVATE_KEY harbor.hotsun.store/ticketaka/ticketaka-performance@${{ env.DIGEST }}
# Kubernetes 배포를 위한 Kustomize 업데이트
- name: Checkout for Kustomize repository
uses: actions/checkout@v2
with:
# kubernetes yaml 파일 저장
repository: F1T4-HOTSUN/manifest # k8s yaml 파일이 있는 repo
ref: main # branch 이름
# 내 repository에 push 하기 위한 Personal Access Token이 필요
token: ${{ secrets.PAT }} # Github Action token을 발급받아서 repo secrect에 등록해줘야한다
path: manifest # 최상위 경로로 repository와 동일하게 설정
# 새 이미지 버전으로 파일의 태그값 수정
# cd path 수정
# kustomize로 image tag 값 변경
- name: Update Kubernetes resources
run: |
pwd
cd manifest/resources/performance
kustomize edit set image harbor.hotsun.store/ticketaka/ticketaka-performance:${{ steps.tag_version.outputs.new_tag }}
cat kustomization.yaml
# 수정된 kustomization.yaml 파일(manifest) commit push
- name: Commit manifest files
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
run: |
cd manifest
git config --global user.email ${{ secrets.USER_EMAIL_MJ }}
git config --global user.name ${{ secrets.USER_NAME_MJ }}
git config --global github.token ${{ secrets.PAT }}
git commit -am "Update image tag harbor.hotsun.store/ticketaka/ticketaka-performance:${{ steps.tag_version.outputs.new_tag }}"
git push -u origin main