Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
docker-baseimage-ubuntu
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
JetBrains YouTrack
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Prosper
docker-baseimage-ubuntu
Commits
f32b3c97
Commit
f32b3c97
authored
3 years ago
by
Griefed
Browse files
Options
Downloads
Patches
Plain Diff
ci: Rework package versions job
parent
062ab92f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
.gitlab-ci.yml
+63
-32
63 additions, 32 deletions
.gitlab-ci.yml
with
63 additions
and
32 deletions
.gitlab-ci.yml
+
63
−
32
View file @
f32b3c97
...
...
@@ -24,6 +24,7 @@ test docker:
script
:
-
echo "**** Build amd64 ****"
-
docker build
--no-cache
--tag "index.docker.io/$DOCKERHUB_USER/$DOCKERHUB_REPO:amd64-develop"
--tag "ghcr.io/$DOCKERHUB_USER/$DOCKERHUB_REPO:amd64-develop"
--build-arg FOCAL_ARCH=amd64
...
...
@@ -36,6 +37,7 @@ test docker:
-
docker push "ghcr.io/$DOCKERHUB_USER/$DOCKERHUB_REPO:amd64-develop"
-
echo "**** Build armhf ****"
-
docker build
--no-cache
--tag "index.docker.io/$DOCKERHUB_USER/$DOCKERHUB_REPO:armhf-develop"
--tag "ghcr.io/$DOCKERHUB_USER/$DOCKERHUB_REPO:armhf-develop"
--build-arg FOCAL_ARCH=armhf
...
...
@@ -48,6 +50,7 @@ test docker:
-
docker push "ghcr.io/$DOCKERHUB_USER/$DOCKERHUB_REPO:armhf-develop"
-
echo "**** Build arm64 ****"
-
docker build
--no-cache
--tag "index.docker.io/$DOCKERHUB_USER/$DOCKERHUB_REPO:arm64-develop"
--tag "ghcr.io/$DOCKERHUB_USER/$DOCKERHUB_REPO:arm64-develop"
--build-arg FOCAL_ARCH=arm64
...
...
@@ -95,6 +98,7 @@ build:
script
:
-
echo "**** Build amd64 ****"
-
docker build
--no-cache
--tag "index.docker.io/$DOCKERHUB_USER/$DOCKERHUB_REPO:amd64-latest"
--tag "index.docker.io/$DOCKERHUB_USER/$DOCKERHUB_REPO:amd64-$CI_COMMIT_TAG"
--tag "ghcr.io/$DOCKERHUB_USER/$DOCKERHUB_REPO:amd64-latest"
...
...
@@ -111,6 +115,7 @@ build:
-
docker push "ghcr.io/$DOCKERHUB_USER/$DOCKERHUB_REPO:amd64-$CI_COMMIT_TAG"
-
echo "**** Build armhf ****"
-
docker build
--no-cache
--tag "index.docker.io/$DOCKERHUB_USER/$DOCKERHUB_REPO:armhf-latest"
--tag "index.docker.io/$DOCKERHUB_USER/$DOCKERHUB_REPO:armhf-$CI_COMMIT_TAG"
--tag "ghcr.io/$DOCKERHUB_USER/$DOCKERHUB_REPO:armhf-latest"
...
...
@@ -127,6 +132,7 @@ build:
-
docker push "ghcr.io/$DOCKERHUB_USER/$DOCKERHUB_REPO:armhf-$CI_COMMIT_TAG"
-
echo "**** Build arm64 ****"
-
docker build
--no-cache
--tag "index.docker.io/$DOCKERHUB_USER/$DOCKERHUB_REPO:arm64-latest"
--tag "index.docker.io/$DOCKERHUB_USER/$DOCKERHUB_REPO:arm64-$CI_COMMIT_TAG"
--tag "ghcr.io/$DOCKERHUB_USER/$DOCKERHUB_REPO:arm64-latest"
...
...
@@ -167,6 +173,7 @@ Check Packages:on-schedule:
-
schedules
before_script
:
-
|-
echo "Preparing package versions comparison."
# 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
...
...
@@ -177,63 +184,87 @@ Check Packages:on-schedule:
# Clean system of potentially interrupting images
docker image rm -f $DOCKERHUB_USER/$DOCKERHUB_REPO:latest
docker image rm -f
localbuild
docker image rm -f
$DOCKERHUB_REPO
rm -rf /tmp/$CI_PROJECT_PATH
rm -f /tmp/package_versions*
mkdir -p /tmp/$CI_PROJECT_PATH
echo "Preparations complete."
script
:
-
|-
echo "Comparing package versions."
# 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 . && \
if [ ! -s "package-versions.txt" ];then
# Get packages from newly build local image
docker run --rm --entrypoint /bin/sh -v /tmp:/tmp localbuild -c '\
apt list -qq --installed > /tmp/package_versions_new.txt && \
sort -o /tmp/package_versions_new.txt /tmp/package_versions_new.txt && \
chmod 777 /tmp/package_versions_new.txt' && \
# Gather package information from latest build
docker run --rm --entrypoint /bin/sh -v /tmp:/tmp $DOCKERHUB_USER/$DOCKERHUB_REPO:latest -c '\
apt list -qq --installed > /tmp/package_versions_old.txt && \
sort -o /tmp/package_versions_old.txt /tmp/package_versions_old.txt && \
chmod 777 /tmp/package_versions_old.txt' && \
# Get checksum of old packages
OLD_CHECKSUM=$(md5sum /tmp/package_versions_old.txt | cut -f1 -d" ") && \
# Get checksum of new packages
NEW_CHECKSUM=$(md5sum /tmp/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
# Gather package information from latest build
docker run --rm --entrypoint /bin/sh -v /tmp/$CI_PROJECT_PATH:/tmp $DOCKERHUB_USER/$DOCKERHUB_REPO:latest -c '\
apt list -qq --installed > /tmp/package_versions.txt && \
sort -o /tmp/package_versions.txt /tmp/package_versions.txt && \
chmod 777 /tmp/package_versions.txt' && \
# 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/package_versions_new.txt /tmp/$CI_PROJECT_PATH/package_versions.txt && \
wait && \
# Add and commit new file to repository
git add package_versions.txt && \
git commit -m '
build: Update installed package
s.' && \
git commit -m '
chore: Add list of package version
s.' && \
# 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."
echo "package_versions.txt added."
elif [ -s "package-versions.txt" ];then
# Build local image for new package versions list
docker build --no-cache --tag $DOCKERHUB_REPO . && \
# Get packages from newly build local image
docker run --rm --entrypoint /bin/sh -v /tmp/$CI_PROJECT_PATH:/tmp $DOCKERHUB_REPO -c '\
apt list -qq --installed > /tmp/package_versions_new.txt && \
sort -o /tmp/package_versions_new.txt /tmp/package_versions_new.txt && \
chmod 777 /tmp/package_versions_new.txt' && \
# Get checksum of old packages
OLD_CHECKSUM=$(md5sum package_versions.txt | cut -f1 -d" ") && \
# Get checksum of new packages
NEW_CHECKSUM=$(md5sum 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
mv -f package_versions_new.txt package_versions.txt && \
wait && \
# Add and commit new file to repository
git add 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
fi
echo "Comparison complete."
after_script
:
-
|-
echo "Cleaning up."
docker image rm -f $DOCKERHUB_USER/$DOCKERHUB_REPO:latest
docker image rm -f
localbuild
docker image rm -f
$DOCKERHUB_REPO
rm -rf /tmp/$CI_PROJECT_PATH
echo "Done."
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment