-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
44 lines (39 loc) · 1.58 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
# <------------- Continuous Deploy ------------->
default:
services:
- docker:dind
image: docker
before_script:
- echo "---------- Install git ----------"
- apk update
- apk add git
- export DOCKER_TAG=docker-${CI_COMMIT_SHORT_SHA}-dags-$(git ls-remote https://gitlab.com/lappis-unb/decidimbr/servicos-de-dados/airflow-dags refs/heads/development | cut -c 1-7)
build-image:
stage: build
artifacts:
paths:
- build.img
expire_in: 1 hour
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
- if: $CI_COMMIT_REF_PROTECTED == "true"
script:
- echo "---------- Docker pull for cache ----------"
- docker login $CI_REGISTRY -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD"
- docker pull $CI_REGISTRY_IMAGE:latest || true
- echo "--------- Building the image ----------"
- docker build --cache-from $CI_REGISTRY_IMAGE:latest --target airflow-deploy-infra -t $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_NAME:${DOCKER_TAG} .
- docker save -o build.img $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_NAME:${DOCKER_TAG}
push-image-to-registry:
stage: deploy
rules:
- if: $CI_COMMIT_REF_NAME == "development"
- if: $CI_COMMIT_REF_NAME == "main"
dependencies:
- build-image
script:
- docker load -i build.img
- docker login $CI_REGISTRY -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD"
- docker push $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_NAME:${DOCKER_TAG}
- docker tag $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_NAME:${DOCKER_TAG} $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_NAME:latest
- docker push $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_NAME:latest