Wookim

github action으로 CD하기 (2) 본문

CI_CD

github action으로 CD하기 (2)

개발자인 경우 2020. 12. 14. 14:19

진행할 절차

1. python flask 앱 생성하기

2. github에 올리기

3. github action 설정

 

 

1, 2번 절차는 다른 글에서 자세히 다루었다.

 

1. 간단한 python flask 웹 api 서버 만들기 부터 읽으면 된다.

wookim789.tistory.com/35

 

AWS 프로젝트 올리기 (6)

지난 글에서 EC2에 window terminal을 이용해 접속하는 방법에 대해 작성했다. 이번엔 웹서버를 EC2에 저장하고 실행시켜 외부에서 접속해보자. 내용을 앞서 정리하자면 다음과 같다. 1. 간단한 python fl

wookim789.tistory.com

혹은 필자 github repository를 이용해보는것도 좋을듯

github.com/wookim789/wookim_tistory

 

wookim789/wookim_tistory

wookim_tistory 예제 프로젝트. Contribute to wookim789/wookim_tistory development by creating an account on GitHub.

github.com

 


github action

본인이 만든 github repositroy로 이동하자.

다음 Actions 탭을 클릭하자.

 

Actions에서 set up workflow yourself 클릭

 

좌측 초록색 start commit 버튼을 클릭한다.

 

 

적당한 커밋메세지를 쓰고 Commit new File 버튼을 클릭하자

 

다시 레포지터리로 이동하면 .github/workflows 폴더가 생성된것이 보인다.

이제 로컬에 적용하기 위해 pull하여 최신화 하자.

 

로컬 레포지터리에 추가한 파일을 받았다.

 

.github > workflows 폴더로 이동한다.

 

위 파일을 아래의 코드로 수정한다.

 

# This workflows will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

# Actions 작업명
name: Upload Python Package

# 이벤트 바인딩 : master 브랜치에 push 이벤트 발생 시 실행
on:
  push:
    branches: 
      - master

# 이벤트가 발생시 해당 작업들 실행
jobs:
  # 작업 분류 : 배포 (빌드와 배포를 분류 가능)
  deploy:
    # 작업 명
    name: test and deploy flask app to S3 bucket
    # 운영체제 설정 : 우분트 -> 빌드나 테스트, 압축등을 실행할 os 선택
    runs-on: ubuntu-latest

    # 위 작업의 세부 단계 설정
    steps:
    # 사용할 actioms의 가상머신
    - uses: actions/checkout@v2
    
    # 스탭 명
    - name: Set up Python
    # python 가상머신 사용 - 부정확함 
      uses: actions/setup-python@v2
      with:
        python-version: '3.x'
    
    # 파이썬 유닛테스트 스텝
    - name: run unittest
      # run 명령어로 위 가상머신에서 작업 수행함
      run: |
        pwd \
        cd ./test/ \
        python -m unittest ./test/test.py \
        cd ..\
        pwd \
    
    # 폴더 만드는 스탭
    - name: make artifacts dir
      run: mkdir ./artifacts/

    # 소스 파일 압축
    - name: zip artifacts
      run: zip -r ./artifacts/build.zip ./app/* appspec.yml
    
    # AWS S3에 압축파일을 전달하는 설정 및 명령어
    - name: deploy to s3
      uses: jakejarvis/s3-sync-action@master
      with:
        args: --acl public-read --follow-symlinks --delete
      env:
        AWS_S3_BUCKET: ${{secrets.AWS_PRODUCTION_BUCKET_NAME}}
        AWS_ACCESS_KEY_ID: ${{ secrets.AWS_IAM_MANAGER_KEY_ID }}
        AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_IAM_MANAGER_SECRET_ACCESS_KEY }}
        AWS_REGION: ap-northeast-2
        SOURCE_DIR: './artifacts'
        DEST_DIR: 'backend/'

 

주석에 설명을 달아두었다.

github에 push 하기전에 

AWS S3의 버킷생성과 AWS IAM의 github를 등록해야 한다.

해당 부분은 다음글에서 다루겠다.

 

다음글 

https://wookim789.tistory.com/43?category=990545

 

'CI_CD' 카테고리의 다른 글

github action으로 CD하기 (5)  (6) 2020.12.23
github action으로 CD하기 (4)  (0) 2020.12.23
github action으로 CD하기 (3)  (0) 2020.12.23
AWS와 github을 이용한 CI/CD 적용하기 (1)  (0) 2020.12.14
Comments