Update image tag to a3a0550a270f975af27f87788dc42433185f4590 #33
This file contains 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: Continuous Integration | |
on: | |
push: | |
branches: ["main"] | |
paths-ignore: | |
- .xinfra/* | |
permissions: | |
id-token: write | |
contents: read | |
env: | |
REPOSITORY: ${{ secrets.REPOSITORY }} | |
IMAGE_TAG: :${{ github.ref_name }}-${{ github.sha }} | |
REGISTRY_USERNAME: ${{ github.actor }} | |
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }} | |
AWS_REGION: ${{ secrets.AWS_REGION }} | |
AWS_ROLE: ${{ secrets.AWS_ROLE }} | |
jobs: | |
Build: | |
name: Build & Delivery | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
token: ${{secrets.TOKEN_GITHUB}} | |
submodules: true | |
- name: Git Submodule Update | |
run: | | |
git submodule update --remote --recursive | |
- name: Set up Java JDK | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'temurin' | |
java-version: 17 | |
- name: Grant execute permission for gradlew | |
run: chmod +x ./gradlew | |
shell: bash | |
- name: Setup Gradle | |
uses: gradle/actions/setup-gradle@v3 | |
- name: Build with Gradle | |
id: buildWithGradle | |
run: ./gradlew clean build -x test | |
shell: bash | |
- name: lowercase the image tag & repository | |
run: | | |
echo "REPOSITORY=$(echo $REPOSITORY | tr '[:upper:]' '[:lower:]')" >> ${GITHUB_ENV} | |
echo "IMAGE_TAG=$(echo $IMAGE_TAG | tr '[:upper:]' '[:lower:]')" >> ${GITHUB_ENV} | |
- name: Set Spring Image Environment Variable | |
run: | | |
echo "SPRING_IMAGE=${{ env.AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/${{ env.REPOSITORY }}${{ env.IMAGE_TAG }}" >> ${GITHUB_ENV} | |
echo "LATEST_IMAGE=${{ env.AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/${{ env.REPOSITORY }}:latest" >> ${GITHUB_ENV} | |
- name: Configure AWS Credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-region: ${{env.AWS_REGION}} | |
role-to-assume: ${{ env.AWS_ROLE }} | |
role-session-name: GitHubActionsSession | |
- name: Login to AWS ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v2 | |
- name: Build Image | |
run: docker build --no-cache -t ${{ env.SPRING_IMAGE }} -f ./xinfra/docker/Dockerfile . | |
- name: Push to ECR | |
run: | | |
docker push ${{ env.SPRING_IMAGE }} | |
docker tag ${{ env.SPRING_IMAGE }} ${{ env.LATEST_IMAGE }} | |
docker push ${{ env.LATEST_IMAGE }} | |
# 새로운 이미지 태그를 kustomization.yaml에 반영 | |
- name: Update Kustomize Image Tag | |
run: | | |
sed -i "s/newTag: .*/newTag: ${GITHUB_SHA}/" xinfra/eks/overlays/production/kustomization.yaml | |
# 변경된 kustomization.yaml 파일을 Git에 커밋하고 푸시 | |
- name: Commit and Push Changes | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "tjdgns8439" | |
git add xinfra/eks/overlays/production/kustomization.yaml | |
git commit -m "Update image tag to ${GITHUB_SHA}" | |
git push origin main |