From 382681820ee77b2673c504123dbb8f90d38c50ba Mon Sep 17 00:00:00 2001 From: Sergey Antropoff Date: Mon, 17 Mar 2025 14:58:29 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BE=D0=B1=C3=91=D0=B4=D0=BE=D0=BA=D0=B5=D1=80=D1=84=D0=B0?= =?UTF-8?q?=D0=B9=D0=BB.=20=D0=A2=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20=D0=B2?= =?UTF-8?q?=D0=BC=D0=B5=D1=81=D1=82=D0=BE=201000=20=D0=BC=D0=B1=20=D0=B2?= =?UTF-8?q?=D1=81=D0=B5=D0=B3=D0=BE=20262=20=D0=BC=D1=8C=C3=91=D0=B1=C3=91?= =?UTF-8?q?.=20=D0=98=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=81=D0=B1=D0=BE=D1=80=D0=BA=D1=83=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B7=D0=BD=D1=8B=D1=85=20=D0=BF=D0=BB=D0=B0=D1=82?= =?UTF-8?q?=D1=84=D0=BE=D1=80=D0=BC.=20ARM64=20=D0=B8=20AMD64.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 45 +++++++++++++++++++++++++++++---------------- Makefile | 9 ++++++--- 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/Dockerfile b/Dockerfile index ab9e76b..ff73520 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,17 @@ -# Use the official Python 3.12.9 Bullseye image as the base -FROM python:3.12.9-bullseye +# Используем более легкий базовый образ +FROM python:3.12.9-slim-bullseye AS builder -# Add metadata +# Добавляем метаданные LABEL maintainer="Сергей Антропов " LABEL description="Этот Dockerfile создан для внедрения подхода IaC в Ansible." LABEL version="0.1" LABEL contact.website="https://devops.org.ru" -# Set environment variables +# Устанавливаем переменные окружения ENV PYTHONUNBUFFERED=1 ENV EDITOR=nano -# Install system dependencies +# Устанавливаем системные зависимости RUN apt-get update && \ apt-get install -y --no-install-recommends \ git \ @@ -25,11 +25,6 @@ RUN apt-get update && \ openssh-client \ nano \ less \ - && rm -rf /var/lib/apt/lists/* - -# Install Docker CLI -RUN apt-get update && \ - apt-get install -y --no-install-recommends \ ca-certificates \ curl \ gnupg \ @@ -42,8 +37,7 @@ RUN apt-get update && \ docker-ce-cli \ && rm -rf /var/lib/apt/lists/* - -# Install Python dependencies for Ansible and Molecule +# Устанавливаем зависимости Python для Ansible и Molecule RUN pip install --upgrade pip && \ pip install \ ansible \ @@ -51,16 +45,35 @@ RUN pip install --upgrade pip && \ ansible-vault \ molecule \ molecule-docker \ - molecule-plugins ansible-compat \ + molecule-plugins \ + ansible-compat \ docker - # Копируем ssh ключ COPY id_rsa /root/.ssh/id_rsa RUN chmod 600 /root/.ssh/id_rsa -# Set the working directory +# Устанавливаем рабочую директорию WORKDIR /ansible -# Default command +# Команда по умолчанию +CMD ["/bin/bash"] + +# Используем многоэтапную сборку для уменьшения размера конечного образа +FROM python:3.12.9-slim-bullseye + +# Копируем только необходимые файлы из промежуточного образа +COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages +COPY --from=builder /usr/local/bin /usr/local/bin +COPY --from=builder /root/.ssh /root/.ssh +COPY --from=builder /ansible /ansible + +# Устанавливаем переменные окружения +ENV PYTHONUNBUFFERED=1 +ENV EDITOR=nano + +# Устанавливаем рабочую директорию +WORKDIR /ansible + +# Команда по умолчанию CMD ["/bin/bash"] \ No newline at end of file diff --git a/Makefile b/Makefile index 52ca20e..f937585 100644 --- a/Makefile +++ b/Makefile @@ -48,27 +48,30 @@ init: docker: @case "$(word 2, $(MAKECMDGOALS))" in \ build) \ + docker buildx create --use --name multiarch-builder --driver docker-container; \ cp ~/.ssh/id_rsa .; \ if [ "$(RUN_MODE)" = "docker-compose" ]; then \ docker compose build $(c); \ else \ - docker build -t $(REGISTRY)/ansible/$(IMAGE) .; \ + docker buildx build -t $(REGISTRY)/ansible/$(IMAGE) --platform linux/amd64,linux/arm64 .; \ fi; \ rm id_rsa;; \ rebuild) \ + docker buildx create --use --name multiarch-builder --driver docker-container; \ cp ~/.ssh/id_rsa .; \ if [ "$(RUN_MODE)" = "docker-compose" ]; then \ docker compose build --no-cache $(c); \ else \ - docker build --no-cache -t $(REGISTRY)/ansible/$(IMAGE) .; \ + docker buildx build --no-cache -t $(REGISTRY)/ansible/$(IMAGE) --platform linux/amd64,linux/arm64 .; \ fi; \ rm id_rsa;; \ prune) \ docker system prune -af;; \ release) \ + docker buildx create --use --name multiarch-builder --driver docker-container; \ cp ~/.ssh/id_rsa .; \ docker login $(REGISTRY); \ - docker buildx build -t $(REGISTRY)/ansible/$(IMAGE):$(TAG) --platform linux/amd64,linux/arm64 --push .; \ + docker buildx build -t $(REGISTRY)/ansible/$(IMAGE):$(TAG) -t $(REGISTRY)/ansible/$(IMAGE):latest --platform linux/amd64,linux/arm64 --push .; \ rm id_rsa;; \ *) echo "Unknown action. Available actions: build, rebuild, prune, release";; \ esac