Skip to content

Merge pull request #70 from StartUpLight/SRLT-122-arm-기반-워크플로우-수정 #148

Merge pull request #70 from StartUpLight/SRLT-122-arm-기반-워크플로우-수정

Merge pull request #70 from StartUpLight/SRLT-122-arm-기반-워크플로우-수정 #148

Workflow file for this run

name: Deployment Workflow
on:
push:
branches: [ "develop" ]
pull_request:
branches: [ "develop" ]
jobs:
build-and-push:
runs-on: ubuntu-latest
env:
SPRING_PROFILES_ACTIVE: test
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
submodules: recursive
token: ${{ secrets.PAT }}
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v5
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle Wrapper
run: ./gradlew clean build --info --stacktrace --no-daemon
- name: Docker login
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set image tag
id: vars
run: echo "IMAGE_TAG=${GITHUB_SHA::7}" >> $GITHUB_ENV
# Multi-architecture 빌드 및 푸시
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: deploy/Dockerfile
platforms: linux/amd64,linux/arm64 # 두 아키텍처 모두 빌드
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/startuplight-be:${{ env.IMAGE_TAG }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Checkout manifest repository
uses: actions/checkout@v6
with:
repository: 'StartUpLight/STARLIGHT_MANIFEST'
token: ${{ secrets.PAT }}
path: 'manifest'
- name: Checkout manifest repository (oracle)
uses: actions/checkout@v6
with:
repository: 'StartUpLight/STARLIGHT_MANIFEST_ORACLE'
token: ${{ secrets.PAT }}
path: 'manifest-oracle'
- name: Update deployment.yml and push manifests
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
IMAGE_TAG: ${{ env.IMAGE_TAG }}
run: |
update_manifest() {
local dir="$1"
local file="$dir/staging/deployment.yml"
sed -i "s|image:.*|image: ${DOCKERHUB_USERNAME}/startuplight-be:${IMAGE_TAG}|g" "$file"
echo "Updated $file:"
cat "$file"
git -C "$dir" config --local user.email "[email protected]"
git -C "$dir" config --local user.name "SeongHo5356"
git -C "$dir" add staging/deployment.yml
if [ -z "$(git -C "$dir" status --porcelain)" ]; then
echo "No changes to commit in $dir"
return 0
fi
git -C "$dir" commit -m "Update image tag to $IMAGE_TAG"
for i in {1..3}; do
echo "Push attempt $i for $dir"
git -C "$dir" pull --rebase origin main && \
git -C "$dir" push && \
echo "Successfully pushed $dir" && \
break || {
echo "Push failed for $dir, retrying in 2 seconds..."
sleep 2
}
done
if ! git -C "$dir" diff --quiet origin/main HEAD; then
echo "ERROR: Failed to push $dir after 3 attempts"
return 1
fi
}
update_manifest manifest
update_manifest manifest-oracle