forked from RedhawkSDR/rest-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
137 lines (126 loc) · 3.92 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# This CI script builds Docker-REDHAWK's webserver image and deploys it to
# dockerhub upon successful execution of its tests.
variables:
CONTAINER_TEST_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
CONTAINER_RELEASE_IMAGE: $CI_REGISTRY_IMAGE:latest
CONTAINER_TAGGED_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
DOCKERHUB_IMAGE: geontech/redhawk-webserver
REDHAWK_VERSION: 2.0.8
stages:
- build
- test
- release
- deploy
- cleanup
.dind: &dind
image: docker:latest
.container_registry: &container_registry
<<: *dind
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
after_script:
- docker logout $CI_REGISTRY
# Build the test image and push it to the registry, delete the runner-local
# image to avoid cluttering the runner.
build:
stage: build
except:
- tags
<<: *container_registry
script:
- sed -i -E "s/(geontech.+\:)(.+)/\1"$REDHAWK_VERSION"/g" Dockerfile
- docker build
--pull
--tag $CONTAINER_TEST_IMAGE .
- docker push $CONTAINER_TEST_IMAGE
- docker rmi $CONTAINER_TEST_IMAGE
test:
stage: test
<<: *container_registry
retry: 2
except:
- tags
script:
# Install docker-compose
- apk add --no-cache py2-pip && pip install docker-compose
# Pull the test image and start the stack without rebuilding it.
- cd tests
- docker pull ${CONTAINER_TEST_IMAGE}
- export REDHAWK_VERSION=$REDHAWK_VERSION
- export CONTAINER_TEST_IMAGE=$CONTAINER_TEST_IMAGE
- docker-compose -p ${CI_COMMIT_SHA} up -d --no-build
- docker-compose -p ${CI_COMMIT_SHA} images
- docker-compose -p ${CI_COMMIT_SHA} exec -T rest
bash -l -c 'yum install -y rh.SigGen rh.FileWriter'
- docker-compose -p ${CI_COMMIT_SHA} exec -T rest
bash -l -c './test.sh' || RESULT=$?
# Clean up and exit with the result
- docker-compose -p ${CI_COMMIT_SHA} down
- docker rmi ${CONTAINER_TEST_IMAGE}
- exit ${RESULT}
# Move the test image to internal 'latest' and clean up the worker's images
release:
stage: release
only:
- master
except:
- tags
<<: *container_registry
script:
- docker pull $CONTAINER_TEST_IMAGE
- docker tag $CONTAINER_TEST_IMAGE $CONTAINER_RELEASE_IMAGE
- docker push $CONTAINER_RELEASE_IMAGE
- docker rmi $CONTAINER_TEST_IMAGE $CONTAINER_RELEASE_IMAGE
# Deploy internally, tagged.
deploy-image:
stage: deploy
only:
- tags
<<: *container_registry
script:
# Pull the release image, re-tag it to the dockerhub name and push it.
- docker pull $CONTAINER_RELEASE_IMAGE
- docker tag $CONTAINER_RELEASE_IMAGE $CONTAINER_TAGGED_IMAGE
- docker push $CONTAINER_TAGGED_IMAGE
- docker rmi $CONTAINER_RELEASE_IMAGE $CONTAINER_TAGGED_IMAGE
# Push to GitHub
deploy-github:
stage: deploy
only:
- tags
image: alpine
script:
- apk add --no-cache openssh-client git bash
- eval $(ssh-agent -s)
- bash -c 'ssh-add <(echo "$GITHUB_TOKEN")'
- mkdir -p ~/.ssh
- echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
# Configure git and push w/ tag(s)
- git config user.name "${GITHUB_USER_NAME}"
- git config user.email "${GITHUB_USER_EMAIL}"
- git remote set-url origin ${GITHUB_REPO}
- git push origin ${GITHUB_BRANCH} --follow-tags
# Clean dev/test images not on master branch
clean-dev:
stage: cleanup
<<: *container_registry
when: always
except:
- master
- tags
script:
- apk add --no-cache git bash curl
- git clone ${DOCKER_UTILS} docker-util
- docker-util/delete-image.sh $CONTAINER_TEST_IMAGE
# Cleanup the locally stored image after tagging and pushing to public
# This has to be manual since deploying to Dockerhub is manual too.
clean-internal:
stage: cleanup
<<: *container_registry
when: manual
only:
- tags
script:
- apk add --no-cache git bash curl
- git clone ${DOCKER_UTILS} docker-util
- docker-util/delete-image.sh $CONTAINER_RELEASE_IMAGE