diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..17c04fc1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +# 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 + +# Export binary +RUN cp /app/dist/podman_compose /result/podman-compose diff --git a/README.md b/README.md index 7d075ea0..f030c7fd 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://github.com/raw/containers/podman-compose/main/scripts/download_podman-compose.sh)" +``` + ### Manual ```bash diff --git a/scripts/download_podman-compose.sh b/scripts/download_podman-compose.sh new file mode 100644 index 00000000..adbaacc0 --- /dev/null +++ b/scripts/download_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 00000000..937dc226 --- /dev/null +++ b/scripts/generate_binary_using_dockerfile.sh @@ -0,0 +1,61 @@ +#!/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) + +# Find the directory containing the dockerfile by traversing up the directory tree +find_dockerfile_dir() { + DIR=$(cd "$(dirname "$0")" && pwd)/$(basename "$0") + while [ "$DIR" != "/" ]; do + if ls "$DIR"/*Dockerfile 1> /dev/null 2>&1; then + echo "$DIR" + return + fi + DIR=$(dirname "$DIR") + done + echo "Error: Dockerfile not found in the directory hierarchy." >&2 + exit 1 +} + +# Locate the directory containing dockerfile (root) +PROJECT_ROOT_DIR=$(find_dockerfile_dir) + +# 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 podman-compose +$CONTAINER_TOOL build -v "$PROJECT_ROOT_DIR:/result$SELINUX" -t podman-compose $PROJECT_ROOT_DIR +$CONTAINER_TOOL image rm podman-compose