Skip to content

Commit

Permalink
Merge pull request #1043 from iruzo/main
Browse files Browse the repository at this point in the history
Download and build podman-compose using docker/podman locally
  • Loading branch information
p12tic authored Nov 3, 2024
2 parents 122a914 + 4203f79 commit 4ae6ccb
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Build and Release

on:
push:
tags:
- 'v*.*.*'

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Build binary
run: |
mkdir -p release/
docker build -t podman-compose-bin -v "$PWD/release:/result" .
mv "$PWD/release/podman-compose" "$PWD/release/podman-compose-linux-x86"
- name: Upload release asset
uses: softprops/action-gh-release@v1
with:
files: ./release/podman-compose-linux-x86
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30 changes: 30 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
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://raw.githubusercontent.com/containers/podman-compose/main/scripts/download_and_build_podman-compose.sh)"
```

### Manual

```bash
Expand Down
16 changes: 16 additions & 0 deletions scripts/download_and_build_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
57 changes: 57 additions & 0 deletions scripts/generate_binary_using_dockerfile.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4ae6ccb

Please sign in to comment.