✨ test : 도커 이미지 빌드 시간 최적화 테스트 #18
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: MAIN CI/CD Pipeline | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
# 1. Checkout code | |
- name: Checkout code | |
uses: actions/checkout@v3 # 최신 버전 사용 | |
# 2. Cache Gradle dependencies | |
- name: Cache Gradle dependencies | |
uses: actions/cache@v4 | |
with: | |
path: ~/.gradle/caches | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradlew') }} | |
restore-keys: | | |
${{ runner.os }}-gradle- | |
# 3. Set up Docker Buildx | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 # 최신 버전 사용 | |
# 4. Cache Docker layers | |
- name: Cache Docker layers | |
uses: actions/cache@v3 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-buildx- | |
# 5. Log in to Google Cloud | |
- name: Log in to Google Cloud | |
uses: google-github-actions/auth@v1 | |
with: | |
credentials_json: ${{ secrets.GCP_CREDENTIALS }} | |
# 6. Configure docker for gcloud | |
- name: Configure docker for gcloud | |
run: gcloud auth configure-docker asia-northeast3-docker.pkg.dev | |
# 7. Build and push Docker image | |
- name: Build and push Docker image | |
run: | | |
docker buildx build --push \ | |
--cache-from=type=local,src=/tmp/.buildx-cache \ | |
--cache-to=type=local,dest=/tmp/.buildx-cache \ | |
--build-arg GRADLE_USER_HOME=/home/gradle/.gradle \ | |
--tag asia-northeast3-docker.pkg.dev/symbolic-yen-441710-h6/practice-main/kafka-user:${{ github.sha }} . | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
# 1. Checkout deployment repo | |
- name: Checkout deployment repo | |
uses: actions/checkout@v3 | |
with: | |
repository: kafka-practice/kafka-manifest | |
path: manifests | |
token: ${{ secrets.DEPLOY_KEY }} | |
# 2. Update manifest | |
- name: Update manifest | |
run: | | |
sed -i "s|image: .*|image: asia-northeast3-docker.pkg.dev/symbolic-yen-441710-h6/practice-main/kafka-user:${{ github.sha }}|" manifests/kafka-user/deployment.yaml | |
# 3. Commit and push changes | |
- name: Commit and push changes | |
working-directory: manifests | |
run: | | |
git config --global user.name 'github-actions' | |
git config --global user.email '[email protected]' | |
git add . | |
git commit -m "Update image to asia-northeast3-docker.pkg.dev/symbolic-yen-441710-h6/practice-main/kafka-user:${{ github.sha }}" | |
git push |