728x90
    
    
  반응형
    
    
    
  SMALL
    Poetry
https://python-poetry.org/docs#installing-with-the-official-installer에서 Poetry를 새로운 가상 환경에 설치하고 Poetry가 자체 환경을 관리할 수 있도록 OS에 맞게 설치한다.
# window powershell
(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | py -
poetry --version
pip install poetry
Docker Hub


GitHub Actions
GitHub Actions는 빌드, 테스트 및 배포 파이프라인을 자동화할 수 있는 지속적 통합 및 지속적 배포 (CI/CD) 플랫폼이다 이 저장소에 대한 공동 작업자 액세스 권한이 있는 누구나 secrets과 variables를 작업에 사용할 수 있다. 이는 fork의 full 요청으로 트리거되는 workflow에 전달되지 않는다.
Docker Hub에 가입한 user name을 DOCKERHUB_USER으로 생성한다.



다음으로, 발급받은 토큰을 DOCKERHUB_TOKEN으로 생성한다.

repo
GitHub에서 mlflow 프로젝트를 위한 레포지토리를 생성하 로컬에 clone한다.

git init # mlflow 프로젝트로 이동
그 다음, .github/workflows 디렉토리를 생성하고 checks.yml을 만든다.

name: Checks
on: [push] # trigger
jobs: # 실행 workflow management
  test-lint:
    name: Test and Lint
    runs-on: ubuntu-20.04
    steps:
      - name: Login in to Docker Hub
        uses: docker/login-action@v1 # actions에서 docker container로 접근하기 위한 패키지 설치
        with:
          username: ${{ secrets.DOCKERHUB_USER }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      - name: Checkout
        uses: actions/checkout@v2
      - name: Test
        run: docker compose run --rm app sh -c "python manage.py test"
      - name: Lint(Flake8)
        run: docker compose run --rm app sh -c "flake8"
.gitignore
# Django #
*.log
*.pot
*.pyc
__pycache__
db.sqlite3
media
# Backup files # 
*.bak 
# If you are using PyCharm # 
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# AWS User-specific
.idea/**/aws.xml
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# File-based project format
*.iws
# IntelliJ
out/
# JIRA plugin
atlassian-ide-plugin.xml
# Python # 
*.py[cod] 
*$py.class 
# Distribution / packaging 
.Python build/ 
develop-eggs/ 
dist/ 
downloads/ 
eggs/ 
.eggs/ 
lib/ 
lib64/ 
parts/ 
sdist/ 
var/ 
wheels/ 
*.whl
*.egg-info/ 
.installed.cfg 
*.egg 
*.manifest 
*.spec 
# Installer logs 
pip-log.txt 
pip-delete-this-directory.txt 
# Unit test / coverage reports 
htmlcov/ 
.tox/ 
.coverage 
.coverage.* 
.cache 
.pytest_cache/ 
nosetests.xml 
coverage.xml 
*.cover 
.hypothesis/ 
# Jupyter Notebook 
.ipynb_checkpoints 
# pyenv 
.python-version 
# celery 
celerybeat-schedule.* 
# SageMath parsed files 
*.sage.py 
# Environments 
.env 
.venv 
env/ 
venv/ 
ENV/ 
env.bak/ 
venv.bak/ 
# mkdocs documentation 
/site 
# mypy 
.mypy_cache/ 
# Sublime Text # 
*.tmlanguage.cache 
*.tmPreferences.cache 
*.stTheme.cache 
*.sublime-workspace 
*.sublime-project 
# sftp configuration file 
sftp-config.json 
# Package control specific files Package 
Control.last-run 
Control.ca-list 
Control.ca-bundle 
Control.system-ca-bundle 
GitHub.sublime-settings 
# Visual Studio Code # 
.vscode/* 
!.vscode/settings.json 
!.vscode/tasks.json 
!.vscode/launch.json 
!.vscode/extensions.json 
.history
requirements.txt
의존성 관리를 위해 txt 파일을 생성한다.
django>=5.1.0,<6.0.0
requirements_dev.txt
코딩컨벤션을 준수하는 Lint를 위한 패키지인 flake를 배포 환경이 아닌 개발 환경에서만 사용하기 위해 txt를 생성한다.
flake8>=7.0.0,<8.0.0
.flake
# 파이썬 코드 스타일 강제
[.flake8]
exclude =
    migrations,
    __pychache__,
    manage.py,
    settings.py
Dockerfile
FROM python:3.11-alpine3.19
LABEL maintainer='mlops-test'
ENV PYTHONUNBUFFERED 1
COPY ./requirements.txt /tmp/requirements.txt
COPY ./requirements.dev.txt /tmp/requirements.dev.txt
COPY ./app /app
WORKDIR /app
EXPOSE 8000
ARG DEV=false
# && \: Enter
RUN python -m venv /py && \
    /py/bin/pip install --upgrade pip && \
    /py/bin/pip install -r /tmp/requirements.txt && \
    rm -rf /tmp && \
    if [ $DEV = 'true']; \
        then /py/bin/pip install -r /tmp/requirements.dev.txt ; \
    fi && \
    adduser \
        --disabled-password \
        --no-create-home \
        django-user
        
# RUN chmod -R 755 /app && chown -R django-user:django-user /app
ENV PATH="/py/bin:$PATH"
USER django-user
.dockerignore
# Git
.git
.gitignore
# Docker
.docker
# Python
app/__pycache__/
app/*/__pycache__/
app/*/*/__pycache__/
app/*/*/*/__pycache__/
.env/
.venv/
venv/
728x90
    
    
  반응형
    
    
    
  LIST
    'App Programming > MLops' 카테고리의 다른 글
| [MLops] MLflow (0) | 2024.08.19 | 
|---|---|
| [MLops] 데이터베이스 (0) | 2024.08.13 | 
| [MLops] 모델 추론 (0) | 2024.08.13 | 
| [MLops] 학습 결과 기록하기 (0) | 2024.08.12 | 
| [MLops] 모델 저장하기 (0) | 2024.08.12 |