Skip to content

Commit

Permalink
Add Dockerfile to readme, build using build and installer modules to …
Browse files Browse the repository at this point in the history
…fix building on several systems

And revert the indent changes in Dockerfile to put tabs back
  • Loading branch information
C0rn3j committed Oct 2, 2024
1 parent b312dc6 commit 97a6de4
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 35 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
test.*
test[0-9].*
build/
build-output/
venv/
.atomignore
commit*
Expand Down
72 changes: 37 additions & 35 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@ FROM $BASE_OS:$BASE_CODENAME AS build-stage

# Download build dependencies
RUN <<EOR
set -eu

apt-get update
apt-get install -y --no-install-recommends \
gcc \
librsvg2-bin \
linux-headers-generic \
python3-dev \
python3-setuptools \
python-is-python3
apt-get clean && rm -rf /var/lib/apt/lists/*
set -eu

apt-get update
apt-get install -y --no-install-recommends \
gcc \
librsvg2-bin \
linux-headers-generic \
python3-dev \
python3-setuptools \
python-is-python3 \
python3-build \
python3-poetry \
python3-installer
apt-get clean && rm -rf /var/lib/apt/lists/*
EOR
# Prepare working directory and target
COPY . /work
Expand All @@ -24,30 +27,29 @@ ARG TARGET=/build/usr

# Build and install
RUN <<EOR
set -eu

python setup.py build --executable "/usr/bin/env python3"
python setup.py install --single-version-externally-managed --home "${TARGET}" --record /dev/null

# Provide input-event-codes.h as fallback for runtime systems without linux headers
cp -a \
"$(find /usr -type f -name input-event-codes.h -print -quit)" \
"$(find "${TARGET}" -type f -name uinput.py -printf '%h\n' -quit)"

# Create short name symlinks for static libraries
suffix=".cpython-*-$(uname -m)-linux-gnu.so"
find "${TARGET}" -type f -path "*/site-packages/*${suffix}" \
| while read -r path; do ln -sfr "${path}" "${path%${suffix}}.so"; done

# Put AppStream metadata to required location according to https://wiki.debian.org/AppStream/Guidelines
metainfo=/build/usr/share/metainfo
mkdir -p "${metainfo}"
cp -a scripts/sc-controller.appdata.xml "${metainfo}"

# Convert icon to png format (required for icons in .desktop file)
iconpath="${TARGET}/share/icons/hicolor/512x512/apps"
mkdir -p "${iconpath}"
rsvg-convert --background-color none -o "${iconpath}/sc-controller.png" images/sc-controller.svg
set -eu
python -m build --wheel
python -m installer --destdir="${TARGET}" dist/*.whl

# Provide input-event-codes.h as fallback for runtime systems without linux headers
cp -a \
"$(find /usr -type f -name input-event-codes.h -print -quit)" \
"$(find "${TARGET}" -type f -name uinput.py -printf '%h\n' -quit)"

# Create short name symlinks for static libraries
suffix=".cpython-*-$(uname -m)-linux-gnu.so"
find "${TARGET}" -type f -path "*/site-packages/*${suffix}" \
| while read -r path; do ln -sfr "${path}" "${path%${suffix}}.so"; done

# Put AppStream metadata to required location according to https://wiki.debian.org/AppStream/Guidelines
metainfo=/build/usr/share/metainfo
mkdir -p "${metainfo}"
cp -a scripts/sc-controller.appdata.xml "${metainfo}"

# Convert icon to png format (required for icons in .desktop file)
iconpath="${TARGET}/share/icons/hicolor/512x512/apps"
mkdir -p "${iconpath}"
rsvg-convert --background-color none -o "${iconpath}/sc-controller.png" images/sc-controller.svg
EOR

# Store build metadata
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ Windows:
- `python3 setup.py build`
- `python3 setup.py install`

### Docker
A test build with Docker can be created using the following way:

```bash
docker build -o build-output --build-arg BASE_CODENAME=noble .
```

## Running with non distro-specific package
- Download and extract [latest release](https://github.com/C0rn3j/sc-controller/releases/latest)
Expand Down

0 comments on commit 97a6de4

Please sign in to comment.