Skip to main content

Build an Image with Poetry-enhanced repository

·203 words·1 min

Still using requirements.txt to install dependencies in building a docker iamge?

Create a Dockerfile #

  • Copy an actual project directory COPY nicegui_nutrition_manager /app
  • Copy Poetry pyproject.toml file COPY pyproject.toml /pyproject.toml
  • Command to install dependencies RUN poetry install --no-root
FROM python:3.11.3-slim
ARG VERSION

LABEL maintainer="Tat <tat@seriousexplosion.net>"

WORKDIR /app
COPY nicegui_nutrition_manager /app

ENV POETRY_HOME="/opt/poetry" \
    POETRY_VIRTUALENVS_CREATE=false \
    \
    PIP_NO_CACHE_DIR=off \
    PIP_DISABLE_PIP_VERSION_CHECK=on \
    PIP_DEFAULT_TIMEOUT=100 \
    \
    PYSETUP_PATH="/opt/pysetup"

ENV PATH="$POETRY_HOME/bin:$PATH"

RUN apt-get update && \
    apt-get install --no-install-recommends -y curl && \
    apt-get clean

RUN curl -sSL https://install.python-poetry.org/ | python -

# packages install
COPY pyproject.toml /pyproject.toml
RUN poetry install --no-root
RUN poetry run playwright install && playwright install-deps

EXPOSE 8080

CMD python3 main.py

Create yml file to build a Docker Image #

  • setup dockerhub username and password in repository secret settings
  • edit tags and destination_container_repo names
name: Publish Docker image

on:
  push:
    branches: main

jobs:
  push_to_registry:
    name: Push Docker image to Docker Hub
    runs-on: ubuntu-latest
    steps:
      - name: Check out the repo
        uses: actions/checkout@v3
      
      - name: Log in to Docker Hub
        uses: docker/login-action@v2
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}
      
      - name: Build and push Docker image
        uses: docker/build-push-action@v4
        with:
          context: .
          push: true
          tags: nuevocs/nicegui-nutrition-manager:latest
          destination_container_repo: nuevocs/nicegui-nutrition-manager
          provider: dockerhub
          short_description: "my nicegui image"