Skip to content

[FEAT] Controller CrossOrigin 추가 #81

[FEAT] Controller CrossOrigin 추가

[FEAT] Controller CrossOrigin 추가 #81

Workflow file for this run

name: Backend CI / CD
# master 브랜치에 push 되면 workflow 작동
on:
push:
branches:
- "main"
env:
AWS_REGION: ap-northeast-2
ECR_REPOSITORY_NAME: "team-4"
ENV_NAME: "prod"
APP: "686710509719.dkr.ecr.ap-northeast-2.amazonaws.com/team-4"
jobs:
build-and-push-image:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
# 1. Java 17 세팅
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew clean build -x test
# Github Secret과 local env 에 저장된 값 불러오기
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
# access key와 secret를 사용하여 ECR에 push할 수 있도록 인증
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
# Dockerfile 을 기준으로 이미지 빌드 후 ecr로 push
- name: Set up Docker Buildx
id: docker_build
uses: docker/setup-buildx-action@v2
- name: main Environment Docker build & Push Docker image to Amazon ECR
uses: docker/build-push-action@v2
if: contains(github.ref, 'main')
env:
ECR: ${{ steps.login-ecr.outputs.registry }}
TAG: ${{ github.sha }}
with:
context: .
push: true
tags: |
${{env.ECR}}/${{env.ECR_REPOSITORY_NAME}}:back-${{env.TAG}}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
ENV=main
- name: Checkout for Kustomize repository
uses: actions/checkout@v2
with:
# kubernetes yaml 파일 저장
repository: PDA4-Phoenix/kkanbustock-server-cicd # k8s yaml 파일이 있는 repo
ref: main # branch 이름
# 내 repository에 push 하기 위한 Personal Access Token이 필요
token: ${{ secrets.ACTION_TOKEN }} # Github Action token을 발급받아서 repo secrect에 등록해줘야한다
path: kkanbustock-server-cicd # 최상위 경로로 repository와 동일하게 설정.
# 새 이미지 버전으로 파일의 태그값 수정.
# cd path 수정
# kustomize 로 image tag 값 변경.
- name: Update Kubernetes resources
run: |
pwd
cd kkanbustock-server-cicd/overlays/${{ env.ENV_NAME }}/
kustomize edit set image ${{ env.APP }}:back-${{ github.sha }}
# 수정된 kustomization.yaml 파일 commit push
- name: Commit minifest files
run: |
cd kkanbustock-server-cicd
git config --global user.email "[email protected]"
git config --global user.name "ghdeo"
git commit -am "Update image"
git push -u origin main
# build-docker-image:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# # 1. Java 17 세팅
# - name: Set up JDK 17
# uses: actions/setup-java@v3
# with:
# java-version: '17'
# distribution: 'temurin'
#
# # 2. Spring Boot 애플리케이션 빌드
# - name: Build with Gradle
# uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1
# with:
# arguments: clean bootJar
#
# # 3. Docker 이미지 빌드
# - name: docker image build
# run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/kkanbustock-v0 .
#
# # 4. DockerHub 로그인
# - name: docker login
# uses: docker/login-action@v2
# with:
# username: ${{ secrets.DOCKERHUB_USERNAME }}
# password: ${{ secrets.DOCKERHUB_PASSWORD }}
#
# # 5. Docker Hub 이미지 푸시
# - name: docker Hub push
# run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/kkanbustock-v0
#
# # 위 과정에서 푸시한 이미지를 ec2에서 풀받아서 실행시키는 과정
# run-docker-image-on-ec2:
# # build-docker-image (위)과정이 완료되어야 실행됩니다.
# needs: build-docker-image
# runs-on: self-hosted
#
# steps:
# # 1. 최신 이미지를 풀받습니다
# - name: docker pull
# run: sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/kkanbustock-v0
#
# # 2. 기존의 컨테이너를 중지시킵니다
# - name: docker stop container
# run: sudo docker stop $(sudo docker ps -q) 2>/dev/null || true
#
# # 3. 최신 이미지를 컨테이너화하여 실행시킵니다
# - name: docker run new container
# run: sudo docker run --name github-actions-demo --rm -d -p 8080:8080 ${{ secrets.DOCKERHUB_USERNAME }}/kkanbustock-v0
#
# # 4. 미사용 이미지를 정리합니다
# - name: delete old docker image
# run: sudo docker system prune -f