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

59
rootfs:secure:
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
60
61
62
63
64
65
  extends: .rootfs
  tags:
    - secure
  only:
    - master
    - schedules
66
  except:
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
67
    - tags
68
69
70
  parallel:
    matrix:
      - GROUP: [base, base-devel]
hashworks's avatar
hashworks committed
71
  script:
72
    - make $PWD/output/$GROUP.tar.xz $PWD/output/Dockerfile.$GROUP
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
90
91
  extends: .image
  except:
    - master
    - schedules
    - tags
92
93
94
  parallel:
    matrix:
      - GROUP: [base, base-devel]
95
  before_script:
96
    - 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
97

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

113
image:publish:secure:
114
115
116
117
118
  extends: .image
  tags:
    - secure
  only:
    - tags
119
120
121
  parallel:
    matrix:
      - GROUP: [base, base-devel]
122
  before_script:
123
    - echo "{\"auths\":{\"https://index.docker.io/v1/\":{\"username\":\"$DOCKER_USERNAME\",\"password\":\"$DOCKER_ACCESS_TOKEN\"}}}" > /kaniko/.docker/config.json
124
125
126
  script:
    - /kaniko/executor
      --whitelist-var-run="false"
127
128
      --context $CI_PROJECT_DIR
      --dockerfile $CI_PROJECT_DIR/Dockerfile.$GROUP
129
      --destination archlinux/archlinux:$GROUP-$BUILD_VERSION
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
130

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

150
151
152
153
test:base:
  extends: .test
  image: $CI_REGISTRY_IMAGE:base-$CI_COMMIT_REF_SLUG

Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
154
test:base-devel:
155
  extends: .test
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
156
  image: $CI_REGISTRY_IMAGE:base-devel-$CI_COMMIT_REF_SLUG
157
158
159
160
161
  after_script:
    - gcc -v
    - g++ -v
    - make -v

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

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

222
# Publish base to the Arch Linux group namespace: https://hub.docker.com/r/archlinux/archlinux
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
223
publish:
224
225
226
227
228
229
230
231
  stage: publish
  tags:
    - secure
  image:
    name: gcr.io/go-containerregistry/crane:debug
    entrypoint: [""]
  variables:
    GIT_STRATEGY: none
232
233
  only:
    - tags
234
  before_script:
235
    - echo $DOCKER_ACCESS_TOKEN | crane auth login -u $DOCKER_USERNAME --password-stdin index.docker.io
236
  script:
237
238
239
    - 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
240

Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
241
242
243
# 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