forked from lmajano/modern-functional-fluent-cfml-rest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
102 lines (93 loc) · 3.22 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
image: ortussolutions/commandbox
stages:
- tests
- localStackCheck
- imageBuild
- remoteStackCheck
- imageDeploy
- imageTest
- artifacts
cfformat:
image: ortussolutions/commandbox:latest
stage: tests
except:
variables:
- $CI_COMMIT_MESSAGE =~ /skip-format/
before_script:
- echo 'skip before_script'
script:
- box install commandbox-cfformat
- box run-script format:check
create_staging_image:
image: docker:19.03.8
stage: imageBuild
services:
- docker:19.03.8-dind
only:
- development
script:
- docker run -v "${PWD}:/app" ortussolutions/commandbox box install --verbose
- rm -rf .env*
- echo "Logging in to Docker Hub Registry"
- docker login -u gpickin -p $DOCKER_REGISTRY_PASSWORD
#Build our compiled image using our Dockerfile
- docker build --no-cache -t ${CI_COMMIT_REF_NAME} -f ./Dockerfile ./
- echo "Docker image successfully built"
- docker tag ${CI_COMMIT_REF_NAME} gpickin/fluent-api:${CI_COMMIT_REF_NAME}
- docker tag ${CI_COMMIT_REF_NAME} gpickin/fluent-api
# Push our new image and tags to the registry
- echo "Pushing new image to registry - gpickin/fluent-api:${CI_COMMIT_REF_NAME}"
- docker push gpickin/fluent-api
- docker push gpickin/fluent-api:${CI_COMMIT_REF_NAME}
- echo "Image gpickin/fluent-api:${CI_COMMIT_REF_NAME} ( STAGING ) pushed successfully"
deploy_staging:
stage: imageDeploy
only:
- development
before_script:
- mkdir -p ~/.ssh
- echo "${SSH_PRIVATE_KEY}" > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- touch ~/.ssh/known_hosts
- apt-get update
- apt-get upgrade -y
- apt-get install -y ssh
script:
- export DOCKER_SERVICE_NAME=fluentAPIImage_cfml
# Override our SSH connection point for staging of our swarm master - this may also be provided as an environment variable
- export [email protected]
# Connect up via SSH to avoid any prompts to add the host key
- ssh -o 'StrictHostKeyChecking no' $SSH_CONNECT
# Note: The --with-registry-auth flag must be passed in order for the master to pass its authentication to the registry to all nodes
- ssh $SSH_CONNECT
"
sudo docker login -u gpickin -p $DOCKER_REGISTRY_PASSWORD &&
sudo docker service update
--update-order start-first
--detach=false
--with-registry-auth
--force
--image gpickin/fluent-api ${DOCKER_SERVICE_NAME}
"
rollback_staging:
stage: imageDeploy
when: manual
only:
- development
before_script:
- mkdir -p ~/.ssh
- echo "${SSH_PRIVATE_KEY}" > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- touch ~/.ssh/known_hosts
script:
- export DOCKER_SERVICE_NAME=fluentAPIImage_cfml
# Override our SSH connection point for staging of our swarm master - this may also be provided as an environment variable
- export [email protected]
# Connect up via SSH to avoid any prompts to add the host key
- ssh -o 'StrictHostKeyChecking no' $SSH_CONNECT
- echo "Rolling Back STAGING"
- ssh $SSH_CONNECT
"
sudo docker login -u gpickin -p $DOCKER_REGISTRY_PASSWORD &&
sudo docker service rollback --detach=false ${DOCKER_SERVICE_NAME}
"