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
728x90
'CLOUD > AWS' 카테고리의 다른 글
aws | eks, gitaction, argoCD 작업 (1) | 2023.01.05 |
---|---|
aws | efs 동적 스토리지 배포 (0) | 2023.01.04 |
aws | 테라폼을 이용한 EKS 환경구성 컨트롤러 배포까지 (0) | 2022.12.31 |
AWS | Secrets manager (0) | 2022.12.14 |
aws | efs 생성해보기 | console (0) | 2022.12.07 |