.gitlab-ci.yml 7.75 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
9
  - upload
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
10
11
  - release
  - publish
hashworks's avatar
hashworks committed
12

Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
13
14
15
lint:
  stage: lint
  image: hadolint/hadolint:latest
16
17
  # DL3007: We use the latest tag for multistage build
  script: hadolint --ignore DL3007 --ignore DL3020 Dockerfile.template
18
19
  except:
    - releases
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
42
43
  stage: rootfs
  before_script:
    - pacman -Syu --noconfirm make devtools fakechroot fakeroot
  artifacts:
    paths:
44
      - output/*
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
45
    expire_in: 2h
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
46

47
rootfs:
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
48
49
50
  extends: .rootfs
  except:
    - master
51
    - releases
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
52
53
    - schedules
    - tags
54
55
56
  parallel:
    matrix:
      - GROUP: [base, base-devel]
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
57
  script:
58
    - make $PWD/output/$GROUP.tar.xz $PWD/output/Dockerfile.$GROUP
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
  script:
74
    - make $PWD/output/$GROUP.tar.xz $PWD/output/Dockerfile.$GROUP
hashworks's avatar
hashworks committed
75

Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
76
77
.image:
  stage: image
hashworks's avatar
hashworks committed
78
79
80
81
  image:
    name: gcr.io/kaniko-project/executor:debug
    entrypoint: [""]
  script:
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
82
83
    - /kaniko/executor
      --whitelist-var-run="false"
84
      --context $CI_PROJECT_DIR/output
85
86
      --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
87

88
image:build:
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
89
90
91
  extends: .image
  except:
    - master
92
    - releases
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
93
94
    - schedules
    - tags
95
96
97
  parallel:
    matrix:
      - GROUP: [base, base-devel]
98
  before_script:
99
    - 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
100

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

116
image:publish:secure:
117
118
119
120
121
  extends: .image
  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\":\"$DOCKER_USERNAME\",\"password\":\"$DOCKER_ACCESS_TOKEN\"}}}" > /kaniko/.docker/config.json
127
128
129
  script:
    - /kaniko/executor
      --whitelist-var-run="false"
130
131
      --context $CI_PROJECT_DIR
      --dockerfile $CI_PROJECT_DIR/Dockerfile.$GROUP
132
      --destination archlinux/archlinux:$GROUP-$BUILD_VERSION
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
133

134
.test:
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
135
  stage: test
136
  dependencies: []
137
138
139
140
141
142
143
  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:
144
      - releases
145
      - tags
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
146
147
148
149
150
151
152
153
  script:
    - pacman -Sy
    - pacman -Qqk
    - pacman -Syu --noconfirm docker grep
    - docker -v
    - id -u http
    - locale | grep -q UTF-8

154
155
156
157
test:base:
  extends: .test
  image: $CI_REGISTRY_IMAGE:base-$CI_COMMIT_REF_SLUG

Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
158
test:base-devel:
159
  extends: .test
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
160
  image: $CI_REGISTRY_IMAGE:base-devel-$CI_COMMIT_REF_SLUG
161
162
163
164
165
  after_script:
    - gcc -v
    - g++ -v
    - make -v

Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
166
167
168
release:
  stage: release
  image: registry.gitlab.com/gitlab-org/release-cli:latest
169
170
171
172
173
174
175
  tags:
    - secure
  only:
    refs:
      - schedules
    variables:
      - $SCHEDULED_PUBLISH == "TRUE"
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
176
177
  before_script:
    - apk add jq curl
178
  script:
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
179
180
    - |
      for group in base base-devel; do
181
        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
182
183
184
185
        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
186
        sed "/TEMPLATE_ROOTFS_FILE/d" Dockerfile.template > output/Dockerfile.${group}
187
        package_url=$(./ci/get-public-download-for-generic-package.sh ${group}-${BUILD_VERSION}.tar.xz)
188
189
        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}
190
      done
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
191
    - >
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
192
      curl -sSf --request POST
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
193
      --header "PRIVATE-TOKEN: ${GITLAB_PROJECT_TOKEN}"
194
      --form "branch=releases"
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
195
196
      --form "commit_message=Release ${BUILD_VERSION}"
      --form "actions[][action]=update"
197
      --form "actions[][file_path]=Dockerfile.base"
198
      --form "actions[][content]=<output/Dockerfile.base"
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
199
      --form "actions[][action]=update"
200
      --form "actions[][file_path]=Dockerfile.base-devel"
201
202
203
204
      --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
205
      "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/repository/commits"
206
    - |
207
      base_url=$(./ci/get-public-download-for-generic-package.sh base-${BUILD_VERSION}.tar.xz)
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
208
      echo "${base_url}"
209
      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
210
      echo "${base_sha_url}"
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
211
      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
212
      echo "${base_devel_url}"
213
      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
214
      echo "${base_devel_sha_url}"
215
216
217

      # 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
218
      echo "Creating release"
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
219
      release-cli create --name "Release ${BUILD_VERSION}" --description "Release ${BUILD_VERSION}" \
220
      --tag-name v${BUILD_VERSION} --ref "releases" \
221
222
223
224
      --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}\"}"
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
225

226
# Publish base to the Arch Linux group namespace: https://hub.docker.com/r/archlinux/archlinux
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
227
publish:
228
229
230
231
232
233
234
235
  stage: publish
  tags:
    - secure
  image:
    name: gcr.io/go-containerregistry/crane:debug
    entrypoint: [""]
  variables:
    GIT_STRATEGY: none
236
237
  only:
    - tags
238
  before_script:
239
    - echo $DOCKER_ACCESS_TOKEN | crane auth login -u $DOCKER_USERNAME --password-stdin index.docker.io
240
  script:
241
242
243
    - crane tag archlinux/archlinux:base-$BUILD_VERSION base
    - crane tag archlinux/archlinux:base-$BUILD_VERSION latest
    - crane tag archlinux/archlinux:base-devel-$BUILD_VERSION base-devel
hashworks's avatar
hashworks committed
244

Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
245
246
247
# Publish to the official Docker namespace: https://hub.docker.com/_/archlinux
# publish:official:
# TODO No idea right now how we're going to automatically do the official Docker Hub pull request