.gitlab-ci.yml 9.6 KB
Newer Older
1
2
3
default:
  image: "archlinux:latest"

hashworks's avatar
hashworks committed
4
stages:
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
5
  - lint
hashworks's avatar
hashworks committed
6
  - rootfs
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
7
  - image
hashworks's avatar
hashworks committed
8
  - test
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
9
10
  - release
  - publish
hashworks's avatar
hashworks committed
11

Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
12
13
14
lint:
  stage: lint
  image: hadolint/hadolint:latest
15
  # DL3018: We don't need alpine version pins
16
  script: hadolint --ignore DL3018 Dockerfile.template
17
18
  except:
    - releases
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
19
    - tags
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
20

Sven-Hendrik Haase's avatar
Debug    
Sven-Hendrik Haase committed
21
22
23
24
25
26
27
28
29
get_version:
  stage: .pre
  script:
    - |
      # If we're building a tagged release, use the tag (without the 'v' prefix) as the
      # BUILD_VERSION. Otherwise, determine a new BUILD_VERSION.
      if [[ -n "$CI_COMMIT_TAG" ]]; then
        echo "BUILD_VERSION=${CI_COMMIT_TAG/v/}" > build.env
      else
30
        echo "BUILD_VERSION=$(date +%Y%m%d).0.$CI_JOB_ID" > build.env
Sven-Hendrik Haase's avatar
Debug    
Sven-Hendrik Haase committed
31
32
      fi
    - export $(< build.env)
33
    - echo "PACKAGE_REGISTRY_URL=${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/rootfs/${BUILD_VERSION}" >> build.env
Sven-Hendrik Haase's avatar
Debug    
Sven-Hendrik Haase committed
34
35
36
37
  artifacts:
    reports:
      dotenv: build.env

Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
38
.rootfs:
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
39
40
41
  stage: rootfs
  before_script:
    - pacman -Syu --noconfirm make devtools fakechroot fakeroot
hashworks's avatar
hashworks committed
42
43
  script:
    - make $PWD/output/Dockerfile.$GROUP
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
44
45
  artifacts:
    paths:
46
      - output/*
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
47
    expire_in: 2h
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
48

49
rootfs:
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
50
51
52
  extends: .rootfs
  except:
    - master
53
    - releases
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
54
55
    - schedules
    - tags
56
57
58
  parallel:
    matrix:
      - GROUP: [base, base-devel]
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
59

60
rootfs:secure:
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
61
62
63
64
65
66
  extends: .rootfs
  tags:
    - secure
  only:
    - master
    - schedules
67
  except:
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
68
    - tags
69
    - releases
70
71
72
  parallel:
    matrix:
      - GROUP: [base, base-devel]
hashworks's avatar
hashworks committed
73

Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
74
75
.image:
  stage: image
hashworks's avatar
hashworks committed
76
77
78
79
  image:
    name: gcr.io/kaniko-project/executor:debug
    entrypoint: [""]
  script:
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
80
81
    - /kaniko/executor
      --whitelist-var-run="false"
82
      --context $CI_PROJECT_DIR/output
83
84
      --dockerfile $CI_PROJECT_DIR/output/Dockerfile.$GROUP
      --destination $CI_REGISTRY_IMAGE:$GROUP-$CI_COMMIT_REF_SLUG
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
85

86
image:build:
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
87
88
89
  extends: .image
  except:
    - master
90
    - releases
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
91
92
    - schedules
    - tags
93
94
95
  parallel:
    matrix:
      - GROUP: [base, base-devel]
96
  before_script:
97
    - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
98

99
image:build:secure:
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
100
  extends: .image
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
101
102
  tags:
    - secure
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
103
104
105
  only:
    - master
    - schedules
106
  except:
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
107
    - tags
108
109
110
  parallel:
    matrix:
      - GROUP: [base, base-devel]
111
112
  before_script:
    - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$GITLAB_PROJECT_USER\",\"password\":\"$GITLAB_PROJECT_TOKEN\"}}}" > /kaniko/.docker/config.json
113

114
# Build and publish to the Arch Linux group namespace: https://hub.docker.com/r/archlinux/archlinux
115
image:publish:secure:
116
  extends: .image
117
  retry: 2
118
119
120
121
  tags:
    - secure
  only:
    - tags
122
123
124
  parallel:
    matrix:
      - GROUP: [base, base-devel]
125
  before_script:
126
    - echo "{\"auths\":{\"https://index.docker.io/v1/\":{\"username\":\"$DOCKERHUB_USERNAME\",\"password\":\"$DOCKERHUB_ACCESS_TOKEN\"}}}" > /kaniko/.docker/config.json
127
  script:
hashworks's avatar
hashworks committed
128
    - LATEST=""
129
    - if [[ "$GROUP" == "base" ]]; then
hashworks's avatar
hashworks committed
130
        LATEST="--destination archlinux/archlinux:latest";
131
      fi
132
133
    - /kaniko/executor
      --whitelist-var-run="false"
134
135
      --context $CI_PROJECT_DIR
      --dockerfile $CI_PROJECT_DIR/Dockerfile.$GROUP
hashworks's avatar
hashworks committed
136
137
138
      --destination archlinux/archlinux:$GROUP
      --destination archlinux/archlinux:$GROUP-$BUILD_VERSION
      $LATEST
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
139

140
.test:
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
141
  stage: test
142
  dependencies: []
143
144
145
146
147
148
149
  only:
    variables:
      # Workaround for https://gitlab.com/gitlab-org/gitlab/-/issues/259663
      # This is fine as at this point we're sure that the release works anyway.
      - $GITLAB_USER_EMAIL != "project10185_bot2@example.com"
  except:
    refs:
150
      - releases
151
      - tags
152
153

.test-script: &test-script
154
155
  - test "$(cat /etc/group | wc -l)" -gt 10
  - test "$(cat /etc/passwd | wc -l)" -gt 10
156
157
158
159
160
161
  - pacman -Sy
  - pacman -Qqk
  - pacman -Syu --noconfirm docker grep
  - docker -v
  - id -u http
  - locale | grep -q UTF-8
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
162

163
164
165
test:base:
  extends: .test
  image: $CI_REGISTRY_IMAGE:base-$CI_COMMIT_REF_SLUG
166
167
  script:
    - *test-script
168

Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
169
test:base-devel:
170
  extends: .test
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
171
  image: $CI_REGISTRY_IMAGE:base-devel-$CI_COMMIT_REF_SLUG
172
173
  script:
    - *test-script
174
175
176
177
    - gcc -v
    - g++ -v
    - make -v

Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
178
179
180
release:
  stage: release
  image: registry.gitlab.com/gitlab-org/release-cli:latest
181
182
183
184
185
  tags:
    - secure
  only:
    refs:
      - schedules
186
187
188
    variables:
      - $PUBLISH_ARCHLINUX_REPOSITORY == "TRUE"
      - $PUBLISH_OFFICIAL_LIBRARY == "TRUE"
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
189
  before_script:
190
    - apk update
191
    - apk add jq curl httpie
192
  script:
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
193
    - |
194
      # Update the description on https://hub.docker.com/r/archlinux/archlinux
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
195
196
      TOKEN="$(http --ignore-stdin POST https://hub.docker.com/v2/users/login username="${DOCKERHUB_USERNAME}" password="${DOCKERHUB_PASSWORD}" | jq -er .token)"
      http --ignore-stdin PATCH https://hub.docker.com/v2/repositories/archlinux/archlinux/ Authorization:"JWT ${TOKEN}" full_description="$(cat README.md)"
197
198

      # Upload rootfs to the Generic Packages Repository
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
199
      for group in base base-devel; do
200
        sed -i "s|${group}.tar.xz|${group}-${BUILD_VERSION}.tar.xz|" output/${group}.tar.xz.SHA256
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
201
202
203
204
        echo "Uploading ${group}.tar.xz"
        curl -sSf --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file output/${group}.tar.xz ${PACKAGE_REGISTRY_URL}/${group}-${BUILD_VERSION}.tar.xz
        echo "Uploading ${group}.tar.xz.SHA256"
        curl -sSf --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file output/${group}.tar.xz.SHA256 ${PACKAGE_REGISTRY_URL}/${group}-${BUILD_VERSION}.tar.xz.SHA256
205
        sed "/TEMPLATE_ROOTFS_FILE/d" Dockerfile.template > output/Dockerfile.${group}
206
        package_url=$(./ci/get-public-download-for-generic-package.sh ${group}-${BUILD_VERSION}.tar.xz)
207
        sed -i "s|TEMPLATE_ROOTFS_RELEASE_URL|https://gitlab.archlinux.org/archlinux/archlinux-docker/-/releases/v${BUILD_VERSION}|" output/Dockerfile.${group}
208
209
        sed -i "s|TEMPLATE_ROOTFS_URL|${package_url}|" output/Dockerfile.${group}
        sed -i "s|TEMPLATE_ROOTFS_HASH|$(cat output/${group}.tar.xz.SHA256)|" output/Dockerfile.${group}
210
      done
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
211
    - >
212
      curl -sSf --request POST -o commit-response.json
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
213
      --header "PRIVATE-TOKEN: ${GITLAB_PROJECT_TOKEN}"
214
      --form "branch=releases"
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
215
216
      --form "commit_message=Release ${BUILD_VERSION}"
      --form "actions[][action]=update"
217
      --form "actions[][file_path]=Dockerfile.base"
218
      --form "actions[][content]=<output/Dockerfile.base"
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
219
      --form "actions[][action]=update"
220
      --form "actions[][file_path]=Dockerfile.base-devel"
221
222
223
224
      --form "actions[][content]=<output/Dockerfile.base-devel"
      --form "actions[][action]=update"
      --form "actions[][file_path]=.gitlab-ci.yml"
      --form "actions[][content]=<.gitlab-ci.yml"
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
225
      "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/repository/commits"
226
    - echo "BUILD_COMMIT=$(jq -r '.id' commit-response.json)" >> build.env
227
    - |
228
      base_url=$(./ci/get-public-download-for-generic-package.sh base-${BUILD_VERSION}.tar.xz)
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
229
      echo "${base_url}"
230
      base_sha_url=$(./ci/get-public-download-for-generic-package.sh base-${BUILD_VERSION}.tar.xz.SHA256)
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
231
      echo "${base_sha_url}"
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
232
      base_devel_url=$(./ci/get-public-download-for-generic-package.sh base-devel-${BUILD_VERSION}.tar.xz)
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
233
      echo "${base_devel_url}"
234
      base_devel_sha_url=$(./ci/get-public-download-for-generic-package.sh base-devel-${BUILD_VERSION}.tar.xz.SHA256)
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
235
      echo "${base_devel_sha_url}"
236
237
238

      # TODO: We should actually be able to do something like \"url\":\"${PACKAGE_REGISTRY_URL}/base-${BUILD_VERSION}.tar.xz\"
      # But it doesn't appear that those downloads are public. I consider this a bug and hopefully it's fixed in a future version!
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
239
      echo "Creating release"
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
240
      release-cli create --name "Release ${BUILD_VERSION}" --description "Release ${BUILD_VERSION}" \
241
      --tag-name v${BUILD_VERSION} --ref "releases" \
242
243
244
245
      --assets-link "{\"name\":\"base-${BUILD_VERSION}.tar.xz\",\"url\":\"${base_url}\"}" \
      --assets-link "{\"name\":\"base-${BUILD_VERSION}.tar.xz.SHA256\",\"url\":\"${base_sha_url}\"}" \
      --assets-link "{\"name\":\"base-devel-${BUILD_VERSION}.tar.xz\",\"url\":\"${base_devel_url}\"}" \
      --assets-link "{\"name\":\"base-devel-${BUILD_VERSION}.tar.xz.SHA256\",\"url\":\"${base_devel_sha_url}\"}"
246
247
248
  artifacts:
    reports:
      dotenv: build.env
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
249
250

# Publish to the official Docker namespace: https://hub.docker.com/_/archlinux
251
publish:
252
253
254
255
256
  stage: publish
  only:
    refs:
      - schedules
    variables:
257
      - $PUBLISH_OFFICIAL_LIBRARY == "TRUE"
258
259
260
261
262
263
264
265
266
267
268
269
270
271
  before_script:
    - export | grep -q BUILD_VERSION=
    - export | grep -q BUILD_COMMIT=
    - test -n "$BUILD_VERSION"
    - test -n "$BUILD_COMMIT"
    - test -n "$GITHUB_TOKEN"
    - pacman -Syu --noconfirm github-cli git gettext
    - git config --global user.email "github@archlinux.org"
    - git config --global user.name "Arch Linux Technical User"
  script:
    - mkdir official-images
    - cd official-images
    - git init
    - 'git remote add origin "https://x-access-token:${GITHUB_TOKEN}@github.com/archlinux/official-images.git"'
272
    - git fetch https://github.com/docker-library/official-images.git
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
    - git reset --hard FETCH_HEAD
    - head="release/${BUILD_VERSION}"
    - git checkout -b "$head"
    - envsubst < ../docker-library.template > library/archlinux
    - git diff
    - git add library/archlinux
    - maintainers="$(grep \(@ ../docker-library.template | cut -d\( -f2 | cut -d\) -f1 | xargs)"
    - test -n "$maintainers"
    - 'git commit
        -m "archlinux: Release ${BUILD_VERSION}"
        -m "This is an automated release [1]."
        -m "Maintainers: ${maintainers}"
        -m "[1] ${CI_PROJECT_URL}/-/blob/master/.gitlab-ci.yml"'
    - git push -u origin "$head"
    - gh pr create
        --repo docker-library/official-images
        --fill
        --base master
        --head archlinux:"$head"