Skip to content
Snippets Groups Projects
Commit 3aaeebcc authored by Griefed's avatar Griefed :joystick:
Browse files

ci: Check packages for updates and trigger pack release when new packages are available

parent 946f038e
No related branches found
No related tags found
No related merge requests found
......@@ -174,4 +174,80 @@ build:
- docker manifest annotate "ghcr.io/$DOCKERHUB_USER/$DOCKERHUB_REPO:$CI_COMMIT_TAG" "ghcr.io/$DOCKERHUB_USER/$DOCKERHUB_REPO:arm64-$CI_COMMIT_TAG" --os linux --arch arm64 --variant v8
- docker manifest push --purge "ghcr.io/$DOCKERHUB_USER/$DOCKERHUB_REPO:$CI_COMMIT_TAG"
only:
- tags
\ No newline at end of file
- tags
Check Packages:on-schedule:
only:
- schedules
before_script:
- |-
# Check and, if necessary, update git user and mail
if [[ "$(git config --list | grep user.name)" != "user.name=$GIT_USER" ]];then
git config --global user.name $GIT_USER
fi
if [[ "$(git config --list | grep user.email)" != "user.email=$GIT_MAIL" ]];then
git config --global user.email $GIT_MAIL
fi
# Clean system of potentially interrupting images
docker image rm -f $DOCKERHUB_USER/$DOCKERHUB_REPO:latest
docker image rm -f localbuild
rm -rf /tmp/$CI_PROJECT_PATH
mkdir -p /tmp/$CI_PROJECT_PATH
script:
- |-
# Clone the repository
git clone $CI_PROJECT_URL.git /tmp/$CI_PROJECT_PATH && \
cd /tmp/$CI_PROJECT_PATH && \
# Build local image for new package versions list
docker build --tag localbuild . && \
# Get packages from newly build local image
docker run --rm --entrypoint /bin/sh -v /tmp/$CI_PROJECT_PATH:/tmp/$CI_PROJECT_PATH localbuild -c '\
apt list -qq --installed > /tmp/$CI_PROJECT_PATH/package_versions_new.txt && \
sort -o /tmp/$CI_PROJECT_PATH/package_versions_new.txt /tmp/$CI_PROJECT_PATH/package_versions_new.txt && \
chmod 777 /tmp/$CI_PROJECT_PATH/package_versions_new.txt' && \
# Gather package information from latest build
docker run --rm --entrypoint /bin/sh -v /tmp/$CI_PROJECT_PATH:/tmp/$CI_PROJECT_PATH $DOCKERHUB_USER/$DOCKERHUB_REPO:latest -c '\
apt list -qq --installed > /tmp/$CI_PROJECT_PATH/package_versions_old.txt && \
sort -o /tmp/$CI_PROJECT_PATH/package_versions_old.txt /tmp/$CI_PROJECT_PATH/package_versions_old.txt && \
chmod 777 /tmp/$CI_PROJECT_PATH/package_versions_old.txt' && \
# Get checksum of old packages
OLD_CHECKSUM=$(md5sum /tmp/$CI_PROJECT_PATH/package_versions_old.txt | cut -f1 -d" ") && \
# Get checksum of new packages
NEW_CHECKSUM=$(md5sum /tmp/$CI_PROJECT_PATH/package_versions_new.txt | cut -f1 -d" ") && \
# If new checksum is not the same as old checksum, we have new versions
if [ "${OLD_CHECKSUM}" != "${NEW_CHECKSUM}" ]; then
# Checkout our branch
git --git-dir /tmp/$CI_PROJECT_PATH.git checkout -f master && \
# Copy the new package versions list to repository
cp -f /tmp/$CI_PROJECT_PATH/package_versions_new.txt /tmp/$CI_PROJECT_PATH/package_versions.txt && \
rm -f /tmp/$CI_PROJECT_PATH/package_versions_new.txt /tmp/$CI_PROJECT_PATH/package_versions_old.txt && \
wait && \
# Add and commit new file to repository
git add /tmp/$CI_PROJECT_PATH/package_versions.txt && \
git commit -m 'build: Update installed packages.' && \
# Push the changes to the remote
git push "https://$GIT_USER:$GITLAB_TOKEN@$CI_SERVER_HOST/$CI_PROJECT_PATH.git" --all && \
# Nice
echo "Packages updated."
else
echo "No package updates available."
fi
after_script:
- |-
docker image rm -f $DOCKERHUB_USER/$DOCKERHUB_REPO:latest
docker image rm -f localbuild
rm -rf /tmp/$CI_PROJECT_PATH
echo "Done."
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment