-
Notifications
You must be signed in to change notification settings - Fork 1
/
.gitlab-ci.yml
90 lines (80 loc) · 2.5 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
# test runs test and lint jobs
# prepare sets the environment variables that can be passed to the other jobs (eg. build, deploy)
# build builds wm-request-queue docker image and push it to the registry.
# `latest` docker tag will be used for commits on main when the commit is not tagged
# deploy deploys the app to the openstack when there's new tag
stages:
- test
- lint
- prepare
- build
.test_common:
stage: test
only:
- main
- merge_requests
image: docker-hub.uncharted.software/python:3.11
before_script:
- echo "machine gitlab.uncharted.software login ${GITLAB_LOGIN} password ${GITLAB_TOKEN}" > ~/.netrc
# install dependencies
- pip install -e .[dev]
lint:
extends: .test_common
script:
- make lint
test:
extends: .test_common
script:
- make test
# Jobs don't share it's local env variables. So Setup up variables you want to share and save it to a file.
# The file can be passed to other jobs as an artifacts
environment:
stage: prepare
only:
- main
- tags
image: docker-hub.uncharted.software/alpine
artifacts:
paths:
- ci.env
expire_in: 1 week
script:
- echo "--- Preparing environment vars ---"
- >
case ${CI_COMMIT_REF_NAME} in
"${CI_COMMIT_TAG}") export DOCKER_TAG="${CI_COMMIT_TAG}" ;;
main) export DOCKER_TAG="latest" ;;
*) echo "Unknown build ref $CI_COMMIT_REF_NAME"; exit 1 ;;
esac
- 'echo "DOCKER_TAG: ${DOCKER_TAG}"'
# prepare should fail if the docker tag version is empty
- if [ -z "${DOCKER_TAG}" ]; then exit 1; fi
- echo "DOCKER_TAG=${DOCKER_TAG}" > ci.env
build:
stage: build
only:
- main
- tags
dependencies:
- environment
image: docker-hub.uncharted.software/docker:latest
services:
- name: docker-hub.uncharted.software/docker:dind
alias: docker
variables:
DOCKER_DRIVER: overlay2
before_script:
- docker info
# Set env vars passed from prepare stage
- export $(grep -v '^#' ci.env | xargs)
script:
- echo "--- Building wm-data-pipeline docker image ---"
- echo VERSION=${DOCKER_TAG}
- cd infra/docker
- mkdir -p src
- cp ../../setup.py src
- cp ../../version.py src
- cp -r ../../flows src
# Build and push the docker image
- docker build --build-arg GITLAB_LOGIN=${GITLAB_LOGIN} --build-arg GITLAB_TOKEN=${GITLAB_TOKEN} -t docker.uncharted.software/worldmodeler/wm-data-pipeline:${DOCKER_TAG} .
- docker push docker.uncharted.software/worldmodeler/wm-data-pipeline:${DOCKER_TAG}