aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKunoiSayami <[email protected]>2022-10-26 01:58:41 +0800
committerKunoiSayami <[email protected]>2022-10-26 01:58:41 +0800
commit19520d7b1642cb47a01e906f03801c1ce0774ab9 (patch)
treea49e69311bda1c2c7b6d744b5efe4b18e7ce477e
parent685c74c4fa212b132c55be1c91e5b366a3593b83 (diff)
feat(script): Optimize local debug docker build
* fix(ci): Fix gitlab ci script Signed-off-by: KunoiSayami <[email protected]>
-rw-r--r--.gitlab-ci.yml17
-rwxr-xr-xdocker/dockerbuild.sh15
-rw-r--r--docker/dockerfile16
-rwxr-xr-xdocker/initfolder.sh10
-rw-r--r--docker/repos/.placehold0
-rwxr-xr-xutils/pkgbuild_bootstrap2
-rwxr-xr-xutils/update-db.py2
-rwxr-xr-xutils/upload.py6
8 files changed, 34 insertions, 34 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 0714912..4b3e1bf 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -40,20 +40,5 @@ build:
#- cp -r ../$CI_PROJECT_TITLE /home/build/
#- cd /home/build/$CI_PROJECT_TITLE
- chown -R build:build ../$CI_PROJECT_TITLE
- - su -c './utils/pkgbuild.sh --import-gpg' build
- - su -c './utils/pkgbuild.sh' build
+ - su -c './utils/pkgbuild_bootstrap' build
- "rm -rf build/ || true"
-
-# only push to master master trigger push
-post:
- stage: post
-
- rules:
- - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
- changes:
- - repo/**/*
- - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_COMMIT_TITLE =~ /REBUILD/
-
- script:
- - if [ -n "$TARGET_HOSTS" ]; then echo "$TARGET_HOSTS" | base64 -d >> /etc/hosts; fi;
- - bash -c './utils/ci-upload.sh'
diff --git a/docker/dockerbuild.sh b/docker/dockerbuild.sh
index add31c5..00b2250 100755
--- a/docker/dockerbuild.sh
+++ b/docker/dockerbuild.sh
@@ -4,13 +4,16 @@ set -Eeuo pipefail
sudo pacman -Sy
cd /home/build
-git clone --depth=3 https://github.com/kunoisayami/repos
+if [ ! -d repos ]; then
+ git clone --depth=3 https://github.com/kunoisayami/repos
-pushd repos
-git checkout "$CHECKOUT_BRANCH"
-git fetch --recurse-submodules -j2
-git submodule update --init
-popd
+
+ pushd repos
+ git checkout "$CHECKOUT_BRANCH"
+ git fetch --recurse-submodules -j2
+ git submodule update --init
+ popd
+fi
export DOCKER_SETUP_SCRIPT=1
diff --git a/docker/dockerfile b/docker/dockerfile
index bbc682f..d771945 100644
--- a/docker/dockerfile
+++ b/docker/dockerfile
@@ -2,12 +2,6 @@ FROM repobuildbase:latest
ARG REMOTE_ADDRESS
-RUN useradd -m build
-
-COPY dockerbuild.sh hook.sh* /home/build/
-
-RUN if [ -r /home/build/hook.sh ]; then /home/build/hook.sh; fi
-
RUN echo -n -e '\n[kunoisayami]\nServer = ' >> /etc/pacman.conf
RUN echo ${REMOTE_ADDRESS} >> /etc/pacman.conf
@@ -20,6 +14,12 @@ RUN pacman-key --finger 4A0F0C8BC709ACA4341767FB243975C8DB9656B9
RUN pacman-key --lsign-key 4A0F0C8BC709ACA4341767FB243975C8DB9656B9
+RUN useradd -m build
+
+COPY dockerbuild.sh initfolder.sh hook.sh* /home/build/
+
+RUN if [ -r /home/build/hook.sh ]; then /home/build/hook.sh; fi
+
RUN if [ ! -r /home/build/hook.sh ]; then pacman --noconfirm --needed -Sy reflector; fi
RUN if [ ! -r /home/build/hook.sh ]; then reflector --save /etc/pacman.d/mirrorlist --latest 2 --sort rate; fi
@@ -32,9 +32,9 @@ RUN pacman --noconfirm --needed -S python python-aiohttp python-aiofiles moreut
RUN echo 'build ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers
-# ADD repos /home/build/repos
+ADD repos /home/build/repos
-# RUN chown -R build:build /home/build/repos
+RUN /home/build/initfolder.sh
USER build
diff --git a/docker/initfolder.sh b/docker/initfolder.sh
new file mode 100755
index 0000000..6f88987
--- /dev/null
+++ b/docker/initfolder.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+if [ -f /home/build/repos/.placehold ]; then
+ rm /home/build/repos/.placehold
+ find /home/build/repos -maxdepth 0 -empty -exec rm -rf {} \;
+fi
+
+if [ -d /home/build/repos ]; then
+ chown -R build:build /home/build/repos
+fi \ No newline at end of file
diff --git a/docker/repos/.placehold b/docker/repos/.placehold
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/docker/repos/.placehold
diff --git a/utils/pkgbuild_bootstrap b/utils/pkgbuild_bootstrap
index 7f251f8..c84ea94 100755
--- a/utils/pkgbuild_bootstrap
+++ b/utils/pkgbuild_bootstrap
@@ -5,6 +5,7 @@ if [ -z "$DOCKER_SETUP_SCRIPT" ]; then
cd "$(dirname "$0")"
cd ../../
echo "Current pwd: $(pwd)"
+ sudo pacman -Sy
fi
set -Eeo pipefail
@@ -48,6 +49,5 @@ fi
curl -fL -o remote.db "$REMOTE_DATABASE"
-sudo pacman -Sy
./utils/pkgbuild.py remote.db $FLAGS
diff --git a/utils/update-db.py b/utils/update-db.py
index acdc8c8..394a9ad 100755
--- a/utils/update-db.py
+++ b/utils/update-db.py
@@ -62,4 +62,4 @@ if __name__ == "__main__":
level=logging.DEBUG,
format="%(asctime)s - %(levelname)s - %(funcName)s - %(lineno)d - %(message)s",
)
- main(args_.cwd, args_.basename, args_.sign_key)
+ asyncio.run(main(args_.cwd, args_.basename, args_.sign_key))
diff --git a/utils/upload.py b/utils/upload.py
index 07f8628..8bb3114 100755
--- a/utils/upload.py
+++ b/utils/upload.py
@@ -40,8 +40,10 @@ async def main(args: argparse.Namespace) -> int:
if ".pkg" in file:
pending_upload.append(file)
+ logger.debug("Pending upload (%d): %s", len(pending_upload), pending_upload)
+
if not len(pending_upload):
- logger.debug("Could not find any packaged packages, skip upload")
+ logger.info("Could not find any packaged packages, skip upload")
return 0
async with aiohttp.ClientSession(
@@ -52,7 +54,7 @@ async def main(args: argparse.Namespace) -> int:
):
pass
for file in pending_upload:
- logger.info("Start upload %s (%s)", sizeof_fmt(os.stat(file).st_size))
+ logger.info("Start upload %s (%s)", file, sizeof_fmt(os.stat(file).st_size))
await send_file(session, args, file)
async with session.post(args.remote_address, data=build_data(args, "UPLOADED")):
pass