티스토리 뷰

1. Terraform ECR 배포.

repository Name : app

 

2. gitaction 설정

ci를 위한 저장소의 하위 경로에 .github/workflows/build.yaml 생성

아래는 예시 내용. 숨기는 변수값은 gitaction의 settings의 Secrets에서 설정.

name: Django CI

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      max-parallel: 4
      matrix:
        python-version: [3.8]

    steps:
    # git에서 설정한 비공개 변수
    - name: checkout source code
      uses: actions/checkout@v3
    
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v3
      with:
        python-version: ${{ matrix.python-version }}
    
    - name: Install Dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -r requirements.txt
    
    - name: Configure AWS credentials
      uses: aws-actions/configure-aws-credentials@v1
      with:
        aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
        aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        aws-region: "ap-northeast-2"

    - name: Login to Amazon ECR
      id: login-ecr
      uses: aws-actions/amazon-ecr-login@v1

    # - name: Set var
    #   id: set-var
    #   run: |
    #     echo ::set-output name=ECR_REGISTRY::${{ steps.login-ecr.outputs.registry }}
    #     echo ::set-output name=ECR_REPOSITORY::web
    #     echo ::set-output name=IMAGE_TAG::$(cat VERSION)
    
    - name: Get image tag(verion)
      id: image
      run: |
        VERSION=$(echo ${{ github.sha }} | cut -c1-8)
        echo VERSION=$VERSION
        echo "::set-output name=version::$VERSION"
    
    - name: Build, tag, and push image to Amazon ECR
      id: image-info
      env:
        ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
        ECR_REPOSITORY: ${{ secrets.ECR_REPO_NAME }}
        IMAGE_TAG: ${{ steps.image.outputs.version }}
      run: |
        echo "::set-output name=ecr_repository::$ECR_REPOSITORY"
        echo "::set-output name=image_tag::$IMAGE_TAG"
        docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
        docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG

3. django 앱 git으로 push

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
글 보관함