-
Notifications
You must be signed in to change notification settings - Fork 68
/
.gitlab-ci.yml
68 lines (65 loc) · 2.83 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
stages:
- build
- publish
before_script:
- export BRANCH_NAME=${BRANCH_NAME:-master}
- export DOCKER_REPOSITORY="canyan/janus-gateway"
- export DOCKER_TAG=${DOCKER_TAG:-$BRANCH_NAME}
- export DOCKER_IMAGE=$DOCKER_REPOSITORY:$DOCKER_TAG
build:
image: docker
stage: build
services:
- docker:dind
script:
- apk add git
- git clone https://github.com/meetecho/janus-gateway.git --branch $BRANCH_NAME
- cd janus-gateway
- export BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
- export GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
- export GIT_COMMIT=$(git rev-parse HEAD)
- export VERSION=$(git name-rev --tags --name-only $GIT_COMMIT | cut -d"^" -f1 | sed -e 's/^v//g')
- echo "BUILD_DATE=${BUILD_DATE} GIT_BRANCH=${GIT_BRANCH} GIT_COMMIT=${GIT_COMMIT} VERSION=${VERSION}"
- docker build -f ../Dockerfile -t $DOCKER_IMAGE --no-cache=true --build-arg BUILD_DATE=${BUILD_DATE} --build-arg GIT_BRANCH=${GIT_BRANCH} --build-arg GIT_COMMIT=${GIT_COMMIT} --build-arg VERSION=${VERSION} .
- docker save $DOCKER_IMAGE > ../image.tar
artifacts:
expire_in: 2w
paths:
- image.tar
tags:
- docker
publish:
image: docker
stage: publish
services:
- docker:dind
dependencies:
- build
script:
- docker load -i image.tar
- echo -n $DOCKER_HUB_PASSWORD | docker login -u $DOCKER_HUB_USERNAME --password-stdin
- export GIT_BRANCH=$(docker inspect $DOCKER_IMAGE | grep git_branch | head -n1 | cut -d'"' -f4)
- export GIT_COMMIT=$(docker inspect $DOCKER_IMAGE | grep git_commit | head -n1 | cut -d'"' -f4)
- export VERSION=$(docker inspect $DOCKER_IMAGE | grep version | head -n1 | cut -d'"' -f4)
- export VERSION_MAJOR=$(echo $VERSION | cut -d"." -f 1,2)
- if [ "${GIT_BRANCH}" != "HEAD" ]; then
echo "Tagging and uploading $DOCKER_REPOSITORY:${GIT_BRANCH}";
docker tag $DOCKER_IMAGE $DOCKER_REPOSITORY:${GIT_BRANCH};
docker push $DOCKER_REPOSITORY:${GIT_BRANCH};
echo "Tagging and uploading $DOCKER_REPOSITORY:${GIT_BRANCH}_${GIT_COMMIT}";
docker tag $DOCKER_IMAGE $DOCKER_REPOSITORY:${GIT_BRANCH}_${GIT_COMMIT};
docker push $DOCKER_REPOSITORY:${GIT_BRANCH}_${GIT_COMMIT};
fi
- if [ -n "${VERSION}" ] && [ "${VERSION}" != "undefined" ]; then
echo "Tagging and uploading $DOCKER_REPOSITORY:${VERSION}";
docker tag $DOCKER_IMAGE $DOCKER_REPOSITORY:${VERSION};
docker push $DOCKER_REPOSITORY:${VERSION};
echo "Tagging and uploading $DOCKER_REPOSITORY:${VERSION_MAJOR}";
docker tag $DOCKER_IMAGE $DOCKER_REPOSITORY:${VERSION_MAJOR};
docker push $DOCKER_REPOSITORY:${VERSION_MAJOR};
echo "Tagging and uploading $DOCKER_REPOSITORY:latest";
docker tag $DOCKER_IMAGE $DOCKER_REPOSITORY:latest;
docker push $DOCKER_REPOSITORY:latest;
fi
tags:
- docker