From b6c59df765e01c65ee22e97563b1cb8305d07395 Mon Sep 17 00:00:00 2001 From: Leonid Pliushch Date: Thu, 23 Jan 2020 21:27:06 +0200 Subject: [PATCH] CI: use termux/package-builder Docker image as build environment --- .github/workflows/packages.yml | 9 +-------- scripts/run-docker.sh | 32 ++++++++++++++++++-------------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/.github/workflows/packages.yml b/.github/workflows/packages.yml index 00f3dda75..1fced6f58 100644 --- a/.github/workflows/packages.yml +++ b/.github/workflows/packages.yml @@ -24,13 +24,6 @@ jobs: uses: actions/checkout@v2 with: fetch-depth: 1000 - - name: Setup build environment - run: | - sudo mkdir -p /opt/termux - sudo chown $(id -u) /opt/termux - mkdir -p ./debs - ./scripts/setup-ubuntu.sh - ./scripts/setup-android-sdk.sh >/dev/null - name: Build run: | BASE_COMMIT=$(jq --raw-output .pull_request.base.sha "$GITHUB_EVENT_PATH") @@ -57,7 +50,7 @@ jobs: done PACKAGE_NAMES=$(sed 's/[[:blank:]]*$//' <<< "$PACKAGE_NAMES") ./scripts/lint-packages.sh $(echo "$PACKAGE_NAMES" | awk '{ print "./packages/"$0"/build.sh" }') - ./build-package.sh -a ${{ matrix.target_arch }} -I ${PACKAGE_NAMES} + ./scripts/run-docker.sh ./build-package.sh -a ${{ matrix.target_arch }} -I ${PACKAGE_NAMES} echo "${PACKAGE_NAMES}" > ./debs/built_packages.txt tar cf debs.tar debs - name: Store *.deb files diff --git a/scripts/run-docker.sh b/scripts/run-docker.sh index b773a930a..f5a9722f5 100755 --- a/scripts/run-docker.sh +++ b/scripts/run-docker.sh @@ -17,7 +17,14 @@ USER=builder echo "Running container '$CONTAINER_NAME' from image '$TERMUX_BUILDER_IMAGE_NAME'..." -docker start $CONTAINER_NAME > /dev/null 2> /dev/null || { +if [ -n "$GITHUB_EVENT_PATH" ]; then + # On CI/CD tty may not be available. + DOCKER_TTY="" +else + DOCKER_TTY=" --tty" +fi + +docker start $CONTAINER_NAME >/dev/null 2>&1 || { echo "Creating new container..." docker run \ --detach \ @@ -25,22 +32,19 @@ docker start $CONTAINER_NAME > /dev/null 2> /dev/null || { --volume $REPOROOT:$HOME/termux-packages \ --tty \ $TERMUX_BUILDER_IMAGE_NAME - if [ "$UNAME" != Darwin ]; then - if [ $(id -u) -ne 1000 -a $(id -u) -ne 0 ] - then - echo "Changed builder uid/gid... (this may take a while)" - docker exec --tty $CONTAINER_NAME sudo chown -R $(id -u) $HOME - docker exec --tty $CONTAINER_NAME sudo chown -R $(id -u) /data - docker exec --tty $CONTAINER_NAME sudo usermod -u $(id -u) builder - docker exec --tty $CONTAINER_NAME sudo groupmod -g $(id -g) builder + if [ "$UNAME" != Darwin ]; then + if [ $(id -u) -ne 1000 -a $(id -u) -ne 0 ]; then + echo "Changed builder uid/gid... (this may take a while)" + docker exec $DOCKER_TTY $CONTAINER_NAME sudo chown -R $(id -u) $HOME + docker exec $DOCKER_TTY $CONTAINER_NAME sudo chown -R $(id -u) /data + docker exec $DOCKER_TTY $CONTAINER_NAME sudo usermod -u $(id -u) builder + docker exec $DOCKER_TTY $CONTAINER_NAME sudo groupmod -g $(id -g) builder + fi fi - fi } if [ "$#" -eq "0" ]; then - docker exec --interactive --tty $CONTAINER_NAME bash + docker exec --interactive $DOCKER_TTY $CONTAINER_NAME bash else - docker exec --interactive --tty $CONTAINER_NAME $@ + docker exec --interactive $DOCKER_TTY $CONTAINER_NAME "$@" fi - -