-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
120 lines (93 loc) · 2.95 KB
/
.gitlab-ci.yml
File metadata and controls
120 lines (93 loc) · 2.95 KB
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
stages:
- build
- deploy
variables:
DOCKER_IMAGE_NAME: "$CI_REGISTRY_IMAGE"
DOCKER_TLS_CERTDIR: ""
# =====================================================
# BUILD IMAGE
# =====================================================
docker-build:
image: docker:latest
stage: build
services:
- docker:dind
rules:
# Tags (v1.2.3)
- if: '$CI_COMMIT_TAG =~ /^v\d+\.\d+\.\d+$/'
when: on_success
# Staging
- if: '$CI_COMMIT_BRANCH == "staging"'
when: on_success
# Production
- if: '$CI_COMMIT_BRANCH == "main"'
when: on_success
- when: never
before_script:
- |
if [[ -n "$CI_COMMIT_TAG" ]]; then
DOCKER_IMAGE_TAG="$CI_COMMIT_TAG"
DOCKERFILE_PATH="docker/production/Dockerfile"
elif [[ "$CI_COMMIT_BRANCH" == "staging" ]]; then
DOCKER_IMAGE_TAG="staging"
DOCKERFILE_PATH="docker/staging/Dockerfile"
elif [[ "$CI_COMMIT_BRANCH" == "main" ]]; then
DOCKER_IMAGE_TAG="latest"
DOCKERFILE_PATH="docker/production/Dockerfile"
else
echo "Branch or tag not allowed"
exit 1
fi
export DOCKER_IMAGE_TAG
export DOCKERFILE_PATH
echo "================================="
echo "Building image: $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG"
echo "Dockerfile: $DOCKERFILE_PATH"
echo "================================="
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY"
script:
- docker build --pull -f "$DOCKERFILE_PATH" -t "$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG" .
- docker push "$DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG"
# =====================================================
# PUSH TO DOCKER HUB
# =====================================================
docker-push-hub:
image: docker:latest
stage: deploy
services:
- docker:dind
needs:
- docker-build
rules:
# Tags (v1.2.3)
- if: '$CI_COMMIT_TAG =~ /^v\d+\.\d+\.\d+$/'
when: on_success
# Staging
- if: '$CI_COMMIT_BRANCH == "staging"'
when: on_success
# Production
- if: '$CI_COMMIT_BRANCH == "main"'
when: on_success
- when: never
before_script:
- |
if [[ -n "$CI_COMMIT_TAG" ]]; then
TAG="$CI_COMMIT_TAG"
elif [[ "$CI_COMMIT_BRANCH" == "staging" ]]; then
TAG="staging"
elif [[ "$CI_COMMIT_BRANCH" == "main" ]]; then
TAG="latest"
else
echo "Invalid ref"
exit 1
fi
export TAG
echo "================================="
echo "Pushing image with tag: $TAG"
echo "================================="
- echo "$DOCKER_HUB_PASSWORD" | docker login -u "$DOCKER_HUB_USER" --password-stdin
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY"
script:
- docker pull "$DOCKER_IMAGE_NAME:$TAG"
- docker tag "$DOCKER_IMAGE_NAME:$TAG" "$DOCKER_HUB_USER/oauth2-passport-server:$TAG"
- docker push "$DOCKER_HUB_USER/oauth2-passport-server:$TAG"