diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..61ed224 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,30 @@ +# Use a base image with necessary build tools +FROM python:3.11-slim AS builder + +# Install required packages for building +RUN apt-get update && apt-get install -y \ + gcc \ + musl-dev \ + build-essential \ + python3-dev \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +# Set the working directory +WORKDIR /app + +# Copy the application code +COPY . . + +# Install PyInstaller +RUN pip install pyinstaller +RUN pip install -r requirements.txt + +# Create a binary with PyInstaller +RUN pyinstaller --onefile --clean podman_compose.py + +# Create /result dir in case it is not mounted +RUN mkdir -p /result + +# Export binary +RUN cp /app/dist/podman_compose /result/podman-compose diff --git a/README.md b/README.md index 7d075ea..1c5523a 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,12 @@ pip3 install https://github.com/containers/podman-compose/archive/main.tar.gz brew install podman-compose ``` +### Generate binary using docker/podman locally +This script will download the repo, generate the binary using [this Dockerfile](https://github.com/containers/podman-compose/blob/main/Dockerfile.md) and let the binary in the directory where you called this script. +```bash +sh -c "$(curl -sSL https://raw.githubusercontent.com/containers/podman-compose/main/scripts/download_and_build_podman-compose.sh)" +``` + ### Manual ```bash diff --git a/scripts/download_and_build_podman-compose.sh b/scripts/download_and_build_podman-compose.sh new file mode 100644 index 0000000..adbaacc --- /dev/null +++ b/scripts/download_and_build_podman-compose.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +# Delete repository dir +rm -rf podman-compose-src + +# Clone repository +git clone https://github.com/containers/podman-compose podman-compose-src + +# Generate binary +sh podman-compose-src/scripts/generate_binary_using_dockerfile.sh + +# Move binary outside repo's dir +mv podman-compose-src/podman-compose . + +# Delete repository dir +rm -rf podman-compose-src diff --git a/scripts/generate_binary_using_dockerfile.sh b/scripts/generate_binary_using_dockerfile.sh new file mode 100644 index 0000000..0c742b5 --- /dev/null +++ b/scripts/generate_binary_using_dockerfile.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +# Find an available container tool (docker or podman) +find_container_tool() { + if command -v docker > /dev/null 2>&1; then + echo "sudo docker" + elif command -v podman > /dev/null 2>&1; then + echo "podman" + else + echo "Error: Neither docker nor podman is available." >&2 + exit 1 + fi +} + +# Determine which container tool to use +CONTAINER_TOOL=$(find_container_tool) + +# Locate the directory containing dockerfile (root) +PROJECT_ROOT_DIR="$(cd "$(dirname "$0")" && pwd)/.." + +# Check SELinux status and set appropriate mount option +check_selinux() { + if command -v getenforce > /dev/null 2>&1; then + SELINUX_STATUS=$(getenforce) + if [ "$SELINUX_STATUS" = "Enforcing" ] || [ "$SELINUX_STATUS" = "Permissive" ]; then + echo ":z" + else + echo "" + fi + elif [ -f /sys/fs/selinux/enforce ]; then + if [ "$(cat /sys/fs/selinux/enforce)" = "1" ]; then + echo ":z" + else + echo "" + fi + else + echo "" + fi +} + +# Get the SELinux option for volume mounts if SELinux is enforcing or permissive +SELINUX=$(check_selinux) + +# Build binary +$CONTAINER_TOOL image rm build-podman-compose + +if expr "$CONTAINER_TOOL" : '.*docker.*' >/dev/null; then + $CONTAINER_TOOL build -t build-podman-compose "$PROJECT_ROOT_DIR" + $CONTAINER_TOOL run --name build-podman-compose build-podman-compose + $CONTAINER_TOOL cp build-podman-compose:/result/podman-compose "$PROJECT_ROOT_DIR/podman-compose" + $CONTAINER_TOOL container stop build-podman-compose + $CONTAINER_TOOL container rm -f build-podman-compose +else + $CONTAINER_TOOL build -v "$PROJECT_ROOT_DIR:/result$SELINUX" -t build-podman-compose "$PROJECT_ROOT_DIR" +fi +$CONTAINER_TOOL image rm python:3.11-slim +$CONTAINER_TOOL image rm build-podman-compose