@@ -3,12 +3,21 @@ stages:
3
3
- release
4
4
- build
5
5
6
+ services :
7
+ - name : ghcr.io/griefed/gitlab-ci-cd:2.0.8
8
+ alias : docker
9
+
10
+ workflow :
11
+ rules :
12
+ - if : ' $CI_MERGE_REQUEST_EVENT_TYPE == "detached"'
13
+ when : never
14
+ - if : ' $CI_PIPELINE_SOURCE == "merge_request_event"'
15
+ when : never
16
+ - when : always
17
+
6
18
test docker :
7
19
stage : test
8
- image : griefed/gitlab-ci-cd:1.0.1
9
- services :
10
- - name : docker:dind
11
- alias : docker
20
+ image : ghcr.io/griefed/gitlab-ci-cd:2.0.8
12
21
variables :
13
22
project_name : $CI_PROJECT_NAME
14
23
SEMANTIC_RELEASE_PACKAGE : $CI_PROJECT_NAME
@@ -34,10 +43,7 @@ test docker:
34
43
release :
35
44
needs : ['test docker']
36
45
stage : release
37
- image : griefed/gitlab-ci-cd:1.0.1
38
- services :
39
- - name : docker:dind
40
- alias : docker
46
+ image : ghcr.io/griefed/gitlab-ci-cd:2.0.8
41
47
variables :
42
48
project_name : $CI_PROJECT_NAME
43
49
SEMANTIC_RELEASE_PACKAGE : $CI_PROJECT_NAME
@@ -53,10 +59,7 @@ release:
53
59
54
60
build :
55
61
stage : build
56
- image : griefed/gitlab-ci-cd:1.0.1
57
- services :
58
- - name : docker:dind
59
- alias : docker
62
+ image : ghcr.io/griefed/gitlab-ci-cd:2.0.8
60
63
variables :
61
64
project_name : $CI_PROJECT_NAME
62
65
SEMANTIC_RELEASE_PACKAGE : $CI_PROJECT_NAME
@@ -78,4 +81,108 @@ build:
78
81
--tag "index.docker.io/$DOCKERHUB_USER/$DOCKERHUB_REPO:$CI_COMMIT_TAG"
79
82
--tag "index.docker.io/$DOCKERHUB_USER/$DOCKERHUB_REPO:latest" .
80
83
only :
81
- - tags
84
+ - tags
85
+
86
+ Check Packages:on-schedule :
87
+ only :
88
+ - schedules
89
+ before_script :
90
+ - |-
91
+ echo "Preparing package versions comparison."
92
+ # Check and, if necessary, update git user and mail
93
+ if [[ "$(git config --list | grep user.name)" != "user.name=$GIT_USER" ]];then
94
+ git config --global user.name $GIT_USER
95
+ fi
96
+ if [[ "$(git config --list | grep user.email)" != "user.email=$GIT_MAIL" ]];then
97
+ git config --global user.email $GIT_MAIL
98
+ fi
99
+
100
+ # Clean system of potentially interrupting images
101
+ docker image rm -f $DOCKERHUB_USER/$DOCKERHUB_REPO:latest
102
+ docker image rm -f $DOCKERHUB_REPO
103
+ rm -rf /tmp/$CI_PROJECT_PATH
104
+ mkdir -p /tmp/$CI_PROJECT_PATH
105
+ echo "Preparations complete."
106
+ script :
107
+ - |-
108
+ echo "Comparing package versions."
109
+ # Clone the repository
110
+ git clone $CI_PROJECT_URL.git /tmp/$CI_PROJECT_PATH && \
111
+ cd /tmp/$CI_PROJECT_PATH && \
112
+
113
+ if [ ! -s "package_versions.txt" ];then
114
+ echo "No package_versions.txt present. Creating..."
115
+
116
+ # Gather package information from latest build
117
+ docker run --rm --entrypoint /bin/sh -v /tmp/$CI_PROJECT_PATH:/tmp $DOCKERHUB_USER/$DOCKERHUB_REPO:latest -c '\
118
+ apt list -qq --installed > /tmp/package_versions.txt && \
119
+ sort -o /tmp/package_versions.txt /tmp/package_versions.txt && \
120
+ chmod 777 /tmp/package_versions.txt' && \
121
+
122
+ # Checkout our branch
123
+ git checkout -f $CI_DEFAULT_BRANCH && \
124
+
125
+ wait && \
126
+
127
+ # Add and commit new file to repository
128
+ git add package_versions.txt && \
129
+ git commit -m 'chore: Add list of package versions.' && \
130
+
131
+ # Push the changes to the remote
132
+ echo "https://***:***@$CI_SERVER_HOST/$CI_PROJECT_PATH.git"
133
+ git push "https://$GIT_USER:$GITLAB_TOKEN@$CI_SERVER_HOST/$CI_PROJECT_PATH".git --all && \
134
+
135
+ # Nice
136
+ echo "package_versions.txt added."
137
+
138
+ elif [ -s "package_versions.txt" ];then
139
+ echo "package_versions.txt present. Comapring..."
140
+
141
+ # Build local image for new package versions list
142
+ docker build --no-cache --tag $DOCKERHUB_REPO . && \
143
+
144
+ # Get packages from newly build local image
145
+ docker run --rm --entrypoint /bin/sh -v /tmp/$CI_PROJECT_PATH:/tmp $DOCKERHUB_REPO -c '\
146
+ apt list -qq --installed > /tmp/package_versions_new.txt && \
147
+ sort -o /tmp/package_versions_new.txt /tmp/package_versions_new.txt && \
148
+ chmod 777 /tmp/package_versions_new.txt' && \
149
+
150
+ # Get checksum of old packages
151
+ OLD_CHECKSUM=$(md5sum package_versions.txt | cut -f1 -d" ") && \
152
+
153
+ # Get checksum of new packages
154
+ NEW_CHECKSUM=$(md5sum package_versions_new.txt | cut -f1 -d" ") && \
155
+
156
+ # If new checksum is not the same as old checksum, we have new versions
157
+ if [ "${OLD_CHECKSUM}" != "${NEW_CHECKSUM}" ]; then
158
+
159
+ # Checkout our branch
160
+ git checkout -f $CI_DEFAULT_BRANCH && \
161
+
162
+ # Copy the new package versions list to repository
163
+ mv -f package_versions_new.txt package_versions.txt && \
164
+
165
+ wait && \
166
+
167
+ # Add and commit new file to repository
168
+ git add package_versions.txt && \
169
+ git commit -m 'build: Update installed packages in Docker container.' && \
170
+
171
+ # Push the changes to the remote
172
+ git push "https://$GIT_USER:$GITLAB_TOKEN@$CI_SERVER_HOST/$CI_PROJECT_PATH.git" --all && \
173
+
174
+ # Nice
175
+ echo "Packages updated."
176
+ else
177
+ echo "No package updates available."
178
+ fi
179
+
180
+ fi
181
+ echo "Comparison complete."
182
+ after_script :
183
+ - |-
184
+ echo "Cleaning up."
185
+ docker image rm -f $DOCKERHUB_USER/$DOCKERHUB_REPO:latest
186
+ docker image rm -f $DOCKERHUB_REPO
187
+ rm -rf /tmp/$CI_PROJECT_PATH
188
+ echo "Done."
0 commit comments