-
Notifications
You must be signed in to change notification settings - Fork 2
/
.gitlab-ci.yml
78 lines (69 loc) · 2.08 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
stages:
- prep
- build
# only- parts that only targets releases (and manual start)
.only_releases_template: &only_releases
only:
- /^release.+$/
- master
- web
create_folders:
stage: prep
image: python:3-alpine
before_script:
- apk add git
script:
- git diff-tree --no-commit-id --name-only -r $CI_COMMIT_SHA > files.txt
- |
python - << 'EOF'
import os
if os.getenv('ALL', 'False').lower() in ['1', 'true', 'y']:
folders = [f for f in os.listdir('.') if os.path.isdir(f) ]
else:
files = open('files.txt', 'r').readlines()
folders = [ s.strip().split('/')[0] for s in files if '/' in s]
folders = list(set(folders))
folders = [ s for s in folders if os.path.isfile(s+'/Dockerfile')]
if len(folders)!=0:
print('Found folders: ', folders)
open('folders.txt', 'w').writelines( (f+'\n') for f in folders )
else:
print('Nothing to build')
import sys
sys.exit(1)
EOF
artifacts:
paths: [folders.txt]
<<: *only_releases
build:
stage: build
dependencies: [ create_folders ]
image: docker
services:
- docker:dind
variables:
DOCKER_HOST: tcp://docker:2375/
GITHUB_SHA: $CI_COMMIT_SHA
REGISTRY: $CI_REGISTRY_IMAGE
before_script:
- mkdir folder-list
- mv folders.txt folder-list/folders.txt
- echo CI_REGISTRY_IMAGE
- env
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
script:
- |
echo "Will build these directories:"
cat folder-list/folders.txt
echo '=================='
while read f; do
TAG=$REGISTRY/$f
VER=$(date +%F)-${GITHUB_SHA::8}
echo '==================='
echo Folder $f, will be tagged as $TAG:$VER
docker build $f/ --tag $TAG:$VER --tag $TAG:latest
docker history $TAG:$VER
docker push $TAG:$VER
docker push $TAG:latest
done < folder-list/folders.txt
<<: *only_releases