From 8469125ea9e299d292a583176c861471de4e33c8 Mon Sep 17 00:00:00 2001 From: andy5995 Date: Sat, 23 Nov 2024 22:13:39 -0600 Subject: [PATCH] Add docker-compose example (closes #14) --- .env | 12 ++++++ .github/workflows/test.yml | 86 +++++++++----------------------------- README.md | 58 ++++++++++--------------- docker-compose.yml | 14 +++++++ entrypoint.sh | 1 + 5 files changed, 69 insertions(+), 102 deletions(-) create mode 100644 .env create mode 100644 docker-compose.yml diff --git a/.env b/.env new file mode 100644 index 0000000..aeb9999 --- /dev/null +++ b/.env @@ -0,0 +1,12 @@ +# Your numeric uid and gid +HOSTUID= +HOSTGID= + +# When run from the root of your project directory, this will be +# the location in the container +WORKSPACE="/workspace" + +# Absolute or relative path to your AppImage build script +SCRIPT="$WORKSPACE/path/to/script" + +ENTRYPOINT="/entrypoint.sh" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0933cbb..af2a349 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,12 +8,14 @@ on: push: branches: trunk paths: - - 'action.yml' + - '.env' + - 'docker-compose.yml' - '**test.yml' pull_request: branches: trunk paths: - - 'action.yml' + - '.env' + - 'docker-compose.yml' - '**test.yml' env: @@ -27,8 +29,6 @@ jobs: platform: - linux/amd64 - linux/arm64 - - linux/arm/v7 - steps: - name: Checkout rmw uses: actions/checkout@v4 @@ -44,16 +44,24 @@ jobs: echo "VERSION=${{ github.sha }}" >> $GITHUB_ENV fi + - name: Install docker-compose + run: | + #sudo apt update + #sudo apt upgrade -y + sudo apt install -y docker-compose + + - name: Checkout rmw + uses: actions/checkout@v4 + with: + path: _linuxdeploy_test + - name: Build AppImage run: | - docker run -t \ - --rm \ - --platform=${{ matrix.platform }} \ - -e HOSTUID=$(id -u) \ - -e VERSION \ - -v $GITHUB_WORKSPACE:/workspace \ - -w /workspace \ - andy5995/linuxdeploy:v2-focal packaging/appimage/pre-appimage.sh + export HOSTUID=$(id -u) HOSTGID=$(id -g) + docker-compose -f _linuxdeploy_test/docker-compose.yml run --rm build + env: + SCRIPT: 'packaging/appimage/pre-appimage.sh' + PLATFORM: ${{ matrix.platform }} - name: Create sha256sum run: | @@ -68,57 +76,3 @@ jobs: name: ${{ env.IMAGE_FILENAME }} path: ./out/* if-no-files-found: error - - #test-netpanzer: - #runs-on: ubuntu-latest - #strategy: - #matrix: - #platform: [amd64] - #steps: - #- name: Checkout - #uses: actions/checkout@v4 - #- name: Checkout netpanzer - #uses: actions/checkout@v4 - #with: - #repository: netpanzer/netpanzer - #path: netpanzer - #- name: Use action from self - #uses: ./ - #with: - #platform: ${{ matrix.platform }} - #pre_appimage_script: rmw/packaging/appimage/pre - #sudo apt install -y \ - #gettext \ - #liblua5.1-0-dev \ - #libphysfs-dev \ - #libsdl2-dev \ - #libsdl2-mixer-dev \ - #libsdl2-ttf-dev - #build_commands: | - #git clone --depth 1 https://github.com/netpanzer/netpanzer - #cd netpanzer - #meson setup _build -Dprefix=/usr - #cd _build - #ninja - #install_to_appdir_commands: | - #meson install --destdir=$APPDIR --skip-subprojects - #linuxdeploy_output_version: $VERSION - #linuxdeploy_args: | - #-d netpanzer/support/win32/netpanzer.desktop \ - #--custom-apprun=netpanzer/support/appimage/AppRun \ - #--icon-file=netpanzer/netpanzer.png \ - #--icon-filename=netpanzer \ - #--executable $APPDIR/usr/bin/netpanzer \ - #--output appimage - - #- name: Create sha256sum - #run: | - #cd out - #sha256sum $IMAGE_FILENAME > $IMAGE_FILENAME.sha256sum - - #- name: Upload AppImage - #uses: actions/upload-artifact@v4 - #with: - #name: ${{ env.IMAGE_FILENAME }} - #path: ./out/* - #if-no-files-found: error diff --git a/README.md b/README.md index 8b8e9b5..e3bc56b 100644 --- a/README.md +++ b/README.md @@ -17,63 +17,49 @@ version Ubuntu. (The appimage plugin doesn't yet support 'ppc64le' or 's390x') -## Example usage +## Usage - docker run -t \ - --rm \ - -e HOSTUID=$(id -u) \ - -e VERSION=test \ - -v $PWD:/workspace \ - -w /workspace \ - andy5995/linuxdeploy:v2-focal packaging/appimage/pre-appimage.sh +Make a `docker` sub-directory within your project and copy `.env` and +`docker-compose.yml` to it. Add custom variables to suit your needs. Add your +numeric user and group id to the corresponding variables in `.env`. You can +find them by using: + + id -u + id -g + +To build the AppImage: + + docker-compose -f docker/docker-compose.yml --rm build This is meant to be run from the source root of your project. Using the command above, your current directory will be mounted in the container at `/workspace`. +You can see an example of an AppImage build script at +[rmw/packaging/appimage/pre-appimage.sh](https://github.com/theimpossibleastronaut/rmw/blob/master/packaging/appimage/pre-appimage.sh). +Add the `/path/to/script` in your custom `.env` file. + When the container starts, 'root' changes the UID of user 'builder' (a user created during the build of the Dockerfile) to HOSTUID. This allows builder to build your project and create the AppImage without root privileges (the resulting files will be owned by you). -The only argument given after the name of the docker image in the `docker run` -command is the path/name of the script that builds your projects and includes -the command to call linuxdeploy. You can see an example at -[rmw/packaging/appimage/pre-appimage.sh](https://github.com/theimpossibleastronaut/rmw/blob/master/packaging/appimage/pre-appimage.sh). - You may use `sudo` in your script to install packages or do other things. If you would like to look around the container, you can use - docker run -it --rm --entrypoint sh andy5995/linuxdeploy:v2-focal + docker run -it --rm --entrypoint bash andy5995/linuxdeploy:v2-focal ## Locally -If you want to clean your project build directory, you can add `-e -CLEAN_BUILD=true` to the `docker run` arguments, and use something like this -in your script: - -```sh -# Clean build directory if specified and it exists -if [ "$CLEAN_BUILD" = "true" ] && [ -d "$BUILD_DIR" ]; then - rm -rf "$BUILD_DIR" -fi - -# Setup project for building, run ./configure, ./autogen.sh, cmake, etc -if [ ! -d "$BUILD_DIR" ]; then - meson setup "$BUILD_DIR" \ - -Dbuildtype=release \ - -Dstrip=true \ - -Db_sanitize=none \ - -Dprefix=/usr -fi -``` - To build for other architectures, you may need to use qemu with docker. There may be other ways, but you can check out [this document](https://www.stereolabs.com/docs/docker/building-arm-container-on-x86) -for starters. If you are set up to build on other architectures, add -`--platform=linux/` to the `docker run` arguments. +for starters. If you are set up to build on other architectures, edit the +**PLATFORM** variable in docker-compose.yml, or export it when running +`docker-compose`: + + PLATFORM=linux/arm64 docker-compose ... ## In a GitHub Runner diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..210d390 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,14 @@ +services: + build: + environment: + HOSTUID: ${HOSTUID} + HOSTGID: ${HOSTGID} + VERSION: ${VERSION} + image: andy5995/linuxdeploy:v2-focal + platform: ${PLATFORM:-linux/amd64} + entrypoint: $ENTRYPOINT + volumes: + - $PWD:$WORKSPACE + working_dir: $WORKSPACE + command: $SCRIPT + restart: "no" diff --git a/entrypoint.sh b/entrypoint.sh index 9cbc9d3..b8862b2 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -25,6 +25,7 @@ if [ -z "$1" ]; then fi usermod -u "$HOSTUID" builder +groupmod -g "$HOSTGID" builder chown -R "$HOSTUID:$HOSTGID" /home/builder # The docs state to use '-w /workdir when running the container, but switching