-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
121 lines (110 loc) · 3.32 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
image: docker:latest
variables:
CONTAINER_IMAGE: $CI_REGISTRY_IMAGE:$CI_PIPELINE_ID
CONTAINER_RELEASE_IMAGE: $CI_REGISTRY_IMAGE:latest
CONTAINER_RELEASE_IMAGE_GCP: $GCP_ECR_URI:latest
DOCKER_DRIVER: overlay
DOCKER_HOST: tcp://localhost:2375/
stages:
- build
- test
- release
- deploy
services:
- docker:18.09.7-dind
build:
stage: build
variables:
GIT_SUBMODULE_STRATEGY: recursive
before_script:
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.gitlab.com
script:
- docker build -f Dockerfile -t $CONTAINER_IMAGE .
- docker push $CONTAINER_IMAGE
wheel:
stage: build
image: python:3.8
script:
- pip install ckanapi
- "pip install -r requirements.txt --only-binary :all:"
- python3 setup.py bdist_wheel
artifacts:
paths:
- dist/
expire_in: 1 day
pypi for development:
stage: release
image: python:3.8
when: manual
script:
- pip install twine
- pip install ckanapi
- "pip install -r requirements.txt --only-binary :all:"
- python3 setup.py sdist
- TWINE_PASSWORD=${CI_JOB_TOKEN} TWINE_USERNAME=gitlab-ci-token python -m twine upload --repository-url https://gitlab.com/api/v4/projects/${CI_PROJECT_ID}/packages/pypi dist/*.whl
only:
- development
dependencies:
- wheel
pypi:
stage: release
image: python:3.8
when: manual
script:
- pip install twine
- pip install ckanapi
- "pip install -r requirements.txt --only-binary :all:"
- python3 setup.py sdist
- twine upload --repository-url $PYPI_SERVER --username $PYPI_USERNAME --password $PYPI_PASSWORD dist/*.whl
only:
- master
dependencies:
- wheel
test:
stage: test
image: python:3.8
script:
- pip3 install dist/*.whl
- python3 setup.py test
dependencies:
- wheel
release:
stage: release
before_script:
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.gitlab.com
script:
# NGINX
- docker pull $CONTAINER_IMAGE
- docker tag $CONTAINER_IMAGE $CONTAINER_RELEASE_IMAGE
- docker tag $CONTAINER_IMAGE $CONTAINER_RELEASE_IMAGE_GCP
- docker tag $CONTAINER_RELEASE_IMAGE $GCP_ECR_URI:$CI_PIPELINE_ID
# Login to GCP container Registry
- docker login -u _json_key -p "$(echo $GCP_KEY_JSON)" $GCP_ECR_URI
# Push release versions to repository.
- docker push $CONTAINER_RELEASE_IMAGE
- docker push $CONTAINER_RELEASE_IMAGE_GCP
- docker push $GCP_ECR_URI:$CI_PIPELINE_ID
only:
- master
- development
dependencies: []
# WARNING: Prefer using --context=$CI_PROJECT_ID else concurrent builds may fail.
.deploy: &deploy
image: google/cloud-sdk:300.0.0
before_script:
# In gitlab operation -> kubernetes needs to be setup for this to work so you get the KUBE variables
- kubectl config set-cluster "$CI_PROJECT_ID" --server="$KUBE_URL" --certificate-authority="$KUBE_CA_PEM_FILE"
- kubectl config set-credentials "$CI_PROJECT_ID" --token="$KUBE_TOKEN"
- kubectl config set-context "$CI_PROJECT_ID" --cluster="$CI_PROJECT_ID" --user="$CI_PROJECT_ID" --namespace="$KUBE_NAMESPACE"
- kubectl config use-context "$CI_PROJECT_ID"
stage: deploy
script:
- kubectl set image deployment/$CI_ENVIRONMENT_SLUG-lintol-doorstep lintol-doorstep=$CONTAINER_IMAGE
dependencies: []
deploy_development:
<<: *deploy
environment:
name: ltl-doorstep-dev
url: http://$CI_ENVIRONMENT_SLUG.$CI_TARGET_DOMAIN
only:
- development