-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path.gitlab-ci.yml
120 lines (115 loc) · 3.45 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
# .gitlab-ci.yml for pubs-services
#
# == Reference:
# - https://sas.cr.usgs.gov/
# - https://docs.gitlab.com/ee/ci/yaml/
# - https://docs.gitlab.com/ee/ci/multi_project_pipelines.html
#
# == CI Variables:
# The following CI variables are expected to be set outside of this file in
# GitLab group variables.
#
# DOCKER_REGISTRY
# Address to the Docker image registry.
# Docker Image registry.
#
# DOCKER_REGISTRY_USER
# The username for authenticating with the Docker image registry.
#
# DOCKER_REGISTRY_PASS
# The password. for authenticating with the Docker image registry.
#
# DEPLOY_TRIGGER_TOKEN
# The API token for the deployment pipeline as configured on the deployment
# repository.
#
# DEPLOY_TRIGGER_URL
# The API URL for the deployment pipeline as configured on the deployment
# repository.
#
# SAS_IMAGES_URL
# The base URL for USGS SAS Docker images.
#
stages:
- Docker Build
- Trigger Deployment
variables:
# The full name of the Docker image to produce, including the registry address.
# In most cases, this should be left alone.
IMAGE_NAME: ${DOCKER_REGISTRY}/pubs-docker/pubs-services
# How to tag the docker image. For now, tag an image per commit.
IMAGE_TAG: ${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHORT_SHA}
#
# == Docker Build
#
Build Docker Image:
image: docker:19
stage: Docker Build
services:
- docker:dind
tags:
- docker
only:
variables:
# We must run on a protected branch to access the DOCKER_REGISTRY_PASS
# variable.
- $CI_COMMIT_REF_PROTECTED == "true"
before_script:
- docker login -u ${DOCKER_REGISTRY_USER} -p ${DOCKER_REGISTRY_PASS} ${DOCKER_REGISTRY}
script:
# Use locally sourced images for building
# These imagess are based on the official upstream images.
# SAS_IMAGES_URL is a GitLab group variable set to the base URL for our
# internal image registry.
- docker build --pull
-t ${IMAGE_NAME}:${IMAGE_TAG}
--build-arg maven_image=${SAS_IMAGES_URL}/base-images/maven
--build-arg openjdk_image=openjdk
--build-arg maven_image_tag=3.6.0-jdk-11
--build-arg openjdk_image_tag=11.0.4-jre
-f Dockerfile .
- docker push ${IMAGE_NAME}:${IMAGE_TAG}
#
# == Deployment Triggers
#
# These jobs use 'curl' to make a request to the GitLab API to trigger the
# deployment repository's pipeline. The pipeline trigger is configured on
# the deployment repository under "Settings -> CI/CD -> Pipeline Triggers",
# which provides an API URL and token.
#
# References:
# - https://docs.gitlab.com/ee/ci/triggers/README.html
#
.deploy_trigger:
image: ${SAS_IMAGES_URL}/base-images/curl:latest
stage: Trigger Deployment
tags:
- docker
only:
variables:
# Limit the deployment triggers to protected refs.
- $CI_COMMIT_REF_PROTECTED == "true"
script:
# In the trigger, pass along our image variables.
- curl -X POST
-F variables[PUBSWH_SERVICES_IMAGE]=${IMAGE_NAME}
-F variables[PUBSWH_SERVICES_IMAGE_TAG]=${IMAGE_TAG}
-F token=${DEPLOY_TRIGGER_TOKEN}
-F ref=${DEPLOY_TRIGGER_REF}
${DEPLOY_TRIGGER_URL}
Development deployment:
extends: .deploy_trigger
only:
refs:
- master
variables:
# The branch on the deployment repository to trigger.
DEPLOY_TRIGGER_REF: develop
Staging deployment:
extends: .deploy_trigger
only:
refs:
- master
variables:
# The branch on the deployment repository to trigger.
DEPLOY_TRIGGER_REF: release