Skip to content

Commit 69e95be

Browse files
iruzop12tic
authored andcommitted
add Dockerfile and related scripts
1 parent 122a914 commit 69e95be

4 files changed

+109
-0
lines changed

Dockerfile

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Use a base image with necessary build tools
2+
FROM python:3.11-slim AS builder
3+
4+
# Install required packages for building
5+
RUN apt-get update && apt-get install -y \
6+
gcc \
7+
musl-dev \
8+
build-essential \
9+
python3-dev \
10+
&& apt-get clean \
11+
&& rm -rf /var/lib/apt/lists/*
12+
13+
# Set the working directory
14+
WORKDIR /app
15+
16+
# Copy the application code
17+
COPY . .
18+
19+
# Install PyInstaller
20+
RUN pip install pyinstaller
21+
RUN pip install -r requirements.txt
22+
23+
# Create a binary with PyInstaller
24+
RUN pyinstaller --onefile --clean podman_compose.py
25+
26+
# Create /result dir in case it is not mounted
27+
RUN mkdir -p /result
28+
29+
# Export binary
30+
RUN cp /app/dist/podman_compose /result/podman-compose

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ pip3 install https://github.com/containers/podman-compose/archive/main.tar.gz
7474
brew install podman-compose
7575
```
7676

77+
### Generate binary using docker/podman locally
78+
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.
79+
```bash
80+
sh -c "$(curl -sSL https://raw.githubusercontent.com/containers/podman-compose/main/scripts/download_and_build_podman-compose.sh)"
81+
```
82+
7783
### Manual
7884

7985
```bash
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh
2+
3+
# Delete repository dir
4+
rm -rf podman-compose-src
5+
6+
# Clone repository
7+
git clone https://github.com/containers/podman-compose podman-compose-src
8+
9+
# Generate binary
10+
sh podman-compose-src/scripts/generate_binary_using_dockerfile.sh
11+
12+
# Move binary outside repo's dir
13+
mv podman-compose-src/podman-compose .
14+
15+
# Delete repository dir
16+
rm -rf podman-compose-src
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/sh
2+
3+
# Find an available container tool (docker or podman)
4+
find_container_tool() {
5+
if command -v docker > /dev/null 2>&1; then
6+
echo "sudo docker"
7+
elif command -v podman > /dev/null 2>&1; then
8+
echo "podman"
9+
else
10+
echo "Error: Neither docker nor podman is available." >&2
11+
exit 1
12+
fi
13+
}
14+
15+
# Determine which container tool to use
16+
CONTAINER_TOOL=$(find_container_tool)
17+
18+
# Locate the directory containing dockerfile (root)
19+
PROJECT_ROOT_DIR="$(cd "$(dirname "$0")" && pwd)/.."
20+
21+
# Check SELinux status and set appropriate mount option
22+
check_selinux() {
23+
if command -v getenforce > /dev/null 2>&1; then
24+
SELINUX_STATUS=$(getenforce)
25+
if [ "$SELINUX_STATUS" = "Enforcing" ] || [ "$SELINUX_STATUS" = "Permissive" ]; then
26+
echo ":z"
27+
else
28+
echo ""
29+
fi
30+
elif [ -f /sys/fs/selinux/enforce ]; then
31+
if [ "$(cat /sys/fs/selinux/enforce)" = "1" ]; then
32+
echo ":z"
33+
else
34+
echo ""
35+
fi
36+
else
37+
echo ""
38+
fi
39+
}
40+
41+
# Get the SELinux option for volume mounts if SELinux is enforcing or permissive
42+
SELINUX=$(check_selinux)
43+
44+
# Build binary
45+
$CONTAINER_TOOL image rm build-podman-compose
46+
47+
if expr "$CONTAINER_TOOL" : '.*docker.*' >/dev/null; then
48+
$CONTAINER_TOOL build -t build-podman-compose "$PROJECT_ROOT_DIR"
49+
$CONTAINER_TOOL run --name build-podman-compose build-podman-compose
50+
$CONTAINER_TOOL cp build-podman-compose:/result/podman-compose "$PROJECT_ROOT_DIR/podman-compose"
51+
$CONTAINER_TOOL container stop build-podman-compose
52+
$CONTAINER_TOOL container rm -f build-podman-compose
53+
else
54+
$CONTAINER_TOOL build -v "$PROJECT_ROOT_DIR:/result$SELINUX" -t build-podman-compose "$PROJECT_ROOT_DIR"
55+
fi
56+
$CONTAINER_TOOL image rm python:3.11-slim
57+
$CONTAINER_TOOL image rm build-podman-compose

0 commit comments

Comments
 (0)