-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.gitlab-ci.yml
84 lines (77 loc) · 3.2 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
image: docker:stable
services:
- docker:dind
before_script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
stages:
- build
- test
- release
variables:
IMAGE_TAG: $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG
build:
stage: build
tags:
- multicore
variables:
GIT_SUBMODULE_STRATEGY: recursive
script:
- docker pull $IMAGE_TAG:test || true
- docker build --pull
--cache-from $IMAGE_TAG:test
--tag $IMAGE_TAG:test
.
- docker push $IMAGE_TAG:test
retry: 2
test01:
stage: test
artifacts:
untracked: true
expire_in: 1 week
script:
- docker pull $IMAGE_TAG:test
- set +o pipefail # essential if return-value of pipe is used to determine job status
- docker run -t --rm
-v $(pwd)/distort/:/distort
-v $(pwd)/example/:/images
-w /images/
$IMAGE_TAG:test
python /distort/remap-blur.py lena.png lena_dl.png lena_dg.png
2>&1 | grep 'writing globally distorted file'
retry: 2
release:
stage: release
variables:
GIT_STRATEGY: none
dependencies: []
script:
- apk add --update --no-cache curl jq
- export ms='application/vnd.docker.distribution.manifest.v2+json'
- export APIURL=$( echo "https://$CI_REGISTRY/v2/$CI_PROJECT_PATH/$CI_COMMIT_REF_SLUG" | tr '[:upper:]' '[:lower:]' )
- 'export TOKEN=$(
curl https://gitlab.com/jwt/auth
-s -f
-u $GITLAB_USER_LOGIN:$REGISTRY_TOKEN
--get
-d client_id=docker
-d offline_token=true
-d service=container_registry
-d "scope=repository:$CI_PROJECT_PATH/$CI_COMMIT_REF_SLUG:*"
| sed -r "s/(\{\"token\":\"|\"\})//g"
)'
- ' curl -fs -H "Accept: $ms" -H "Authorization:Bearer $TOKEN" $APIURL/manifests/test
| curl -fsS -X PUT -H "Content-type: $ms" -H "Authorization:Bearer $TOKEN" -d @- $APIURL/manifests/latest '
- ' curl -fs -H "Accept: $ms" -H "Authorization:Bearer $TOKEN" $APIURL/manifests/test
| curl -fsS -X PUT -H "Content-type: $ms" -H "Authorization:Bearer $TOKEN" -d @- $APIURL/manifests/$CI_COMMIT_SHORT_SHA '
## remove old images (keep N) with GIT-SHA tag
- export URLENC=$( echo $CI_PROJECT_PATH | sed 's|/|%2F|g' ) # https://docs.gitlab.com/ce/api/README.html#namespaced-path-encoding
- export registryID=$( curl -fs "https://gitlab.com/api/v4/projects/$URLENC/registry/repositories" | jq ".[] | select(.location==\"$IMAGE_TAG\") | .id" ) # https://docs.gitlab.com/ce/api/container_registry.html#list-registry-repositories
- curl -fs "https://gitlab.com/api/v4/projects/$URLENC/registry/repositories/$registryID/tags" | jq '.[] | .name'
- 'curl -fs
--request DELETE
--data "name_regex=[0-9a-f]{8}"
--data "keep_n=5"
--header "PRIVATE-TOKEN: $REGISTRY_TOKEN"
"https://gitlab.com/api/v4/projects/$URLENC/registry/repositories/$registryID/tags" ' # https://docs.gitlab.com/ce/api/container_registry.html#delete-repository-tags-in-bulk
- sleep 30
- curl -fs "https://gitlab.com/api/v4/projects/$URLENC/registry/repositories/$registryID/tags" | jq '.[] | .name'