Skip to content

Commit

Permalink
add Dockerfile and related scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
iruzo committed Sep 21, 2024
1 parent 229650c commit 5142b5c
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions scripts/download_podman-compose.sh
Original file line number Diff line number Diff line change
@@ -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
61 changes: 61 additions & 0 deletions scripts/generate_binary_using_dockerfile.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5142b5c

Please sign in to comment.