app.py
-> flask의 메인 함수가 있고 커맨드라인으로 받은 포트에 바인드하고 요청 들어오기를 기다림
requirements.txt
-> pip3 install -r requirements.txt
flask 모듈들을 설치함
test.py
-> app.py 코드에 유닛 테스트 로직이 들어가 있음. CI/CD 구성 시 실행이 되게 구성할 예정
README.md
Flask==2.3.2
Flask-HTTPAuth==4.5.0
Flask-Login==0.6.2
Flask-SQLAlchemy==3.0.3
-> pip3 freeze > requirements.txt
from flask import Flask,session
app = Flask(__name__)
…
app.secret_key = "Python Study"
if __name__ == "__main__":
app.run()
keeyong hangman % docker run -p 4000:4000 keeyong/hangman
* Debug mode: off
WARNING: This is a development server. Do not use it in a
production deployment. Use a production WSGI server instead.
* Running on all addresses (0.0.0.0)
* Running on http://127.0.0.1:4000
* Running on http://172.17.0.3:4000
Press CTRL+C to quit
● Github에서는 이전에 master라 불렀고 지금은 main이라 부르는 source of truth가 되는 특별한 branch
● 특정한 기능을 구현하기 위해 만들어진 mainline의 복사본. 구현과 테스트가 이뤄진 후에 main branch와 merge 됨.
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
sample.py :
def lower(a)
return a.lower()
lower("aBC") # 테스트 출력 예
flake8 sample.py
-> sample.py:3:12: E999 SyntaxError: invalid syntax
# Comments start with a #
# Key-value pairs are separated by a colon and a space
name: John Doe
age: 30
# Lists are denoted by a hyphen and a space
hobbies:
- reading
- hiking
# Nested key-value pairs are indented with two spaces
contact:
email: john.doe@example.com
phone:
home: 555-1234
work: 555-5678
# multi-line string
description: |
This is a
multi-line
string
on:
push:
branches: [ "main" ] # 모든 브랜치에 적용하고 싶다면 [ "main", "dev"]
pull_request:
branches: [ "main" ] # 모든 브랜치에 적용하고 싶다면 [ "main", "dev"]
● Docker Image이란 Template을 사용할 예정
Github Actions 사용 #2: 테스트 추가
=> 위의 과정을 .github/workflows/docker-image.yml에 기술 (steps 밑에 name)
name: Docker Image CI
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: docker login
env:
DOCKER_USER: ${{secrets.DOCKER_USER}}
DOCKER_PASSWORD: ${{secrets.DOCKER_PASSWORD}}
run: |
docker login -u $DOCKER_USER -p $DOCKER_PASSWORD
- name: Build the Docker image
run: docker build --tag ${{secrets.DOCKER_USER}}/hangman:latest .
- name: docker push
run: docker push ${{secrets.DOCKER_USER}}/hangman:latest