.gitlab-ci.yml 7.53 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
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
18

Sven-Hendrik Haase's avatar
Debug    
Sven-Hendrik Haase committed
19
20
21
22
23
24
25
26
27
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
28
        echo "BUILD_VERSION=$(date +%Y%m%d).0.$CI_JOB_ID" > build.env
Sven-Hendrik Haase's avatar
Debug    
Sven-Hendrik Haase committed
29
30
      fi
    - export $(< build.env)
31
    - 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
32
33
34
35
  artifacts:
    reports:
      dotenv: build.env

Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
36
.rootfs:
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
37
38
39
40
41
  stage: rootfs
  before_script:
    - pacman -Syu --noconfirm make devtools fakechroot fakeroot
  artifacts:
    paths:
42
      - output/*
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
43
    expire_in: 2h
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
44

45
rootfs:
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
46
47
48
49
50
  extends: .rootfs
  except:
    - master
    - schedules
    - tags
51
52
53
  parallel:
    matrix:
      - GROUP: [base, base-devel]
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
54
  script:
55
    - make $PWD/output/$GROUP.tar.xz $PWD/output/Dockerfile.$GROUP
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
56

57
rootfs:secure:
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
58
59
60
61
62
63
  extends: .rootfs
  tags:
    - secure
  only:
    - master
    - schedules
64
  except:
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
65
    - tags
66
67
68
  parallel:
    matrix:
      - GROUP: [base, base-devel]
hashworks's avatar
hashworks committed
69
  script:
70
    - make $PWD/output/$GROUP.tar.xz $PWD/output/Dockerfile.$GROUP
hashworks's avatar
hashworks committed
71

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

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

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

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

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

148
149
150
151
test:base:
  extends: .test
  image: $CI_REGISTRY_IMAGE:base-$CI_COMMIT_REF_SLUG

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

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

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

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

Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
237
238
239
# 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