-
Notifications
You must be signed in to change notification settings - Fork 9
/
.gitlab-ci.yml
879 lines (829 loc) · 25.1 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
variables:
PYTHON_VER: '3.10'
APP_NETWORK: webgnome_net
UPSTREAM_BRANCH: $CI_COMMIT_BRANCH
# Ok, here is the strategy I believe we want for our pipeline.
# - First, we test our sources.
#
# - Next, we build a temporarily named docker image. We don't want to have
# an officially named image that isn't passing the tests.
#
# - Next, we test the docker image that was built.
#
# - Next, we rename the docker image to its official name in the registry.
#
# - Next, we deploy the docker image
#
# Note: we would like to cleanup the temporary docker tag from the container
# registry, but the solution provided by the GitLab docs cleans everything
# up, including the tag we want to keep.
stages:
- util
- test_src
- build_temp_img
- test_img
- rename_temp_img
#- remove_temp_img
- deploy
- maintenance
services:
- redis:latest
test_src:
stage: test_src
rules:
- if:
($CI_COMMIT_BRANCH != "develop" && $CI_COMMIT_BRANCH != "main" &&
$CI_COMMIT_BRANCH != "production")
variables:
UPSTREAM_BRANCH: "develop"
- if: $CI_PIPELINE_SOURCE == "pipelines"
when: never
- if: $CI_PIPELINE_SOURCE == "schedules"
when: never
tags:
- docker
- linux
image: registry.orr.noaa.gov/gnome/pygnome:$UPSTREAM_BRANCH
script:
- apt-get install -y redis
- redis-server --daemonize yes
- git clone --depth 1 -b develop
https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.orr.noaa.gov/gnome/libgoods.git
- conda install -y python=$PYTHON_VER --file conda_requirements.txt
--file conda_requirements_test.txt --file libgoods/conda_requirements.txt
--file /pygnome/py_gnome/conda_requirements.txt
- pushd libgoods && pip install . && popd
- pip install .
- python setup.py compilejson # is this duplicating what happens already in the setup.py?
- conda env export > webgnome_api/views/deployed_environment.yaml
- pytest webgnome_api/tests
- conda list > conda_packages.txt
artifacts:
when: always
expire_in: 15 days
paths:
- ./conda_packages.txt
build_temp_img:
stage: build_temp_img
only:
- main
- develop
- production
except:
- pipelines
- schedules
tags:
- shell
- build
script:
- git clone --depth 1 -b develop
https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.orr.noaa.gov/gnome/libgoods.git
- git clone --depth 1 -b $CI_COMMIT_BRANCH
https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.orr.noaa.gov/gnome/gnome-deploy.git
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- >
docker build -f dockerfile --build-arg CI_COMMIT_BRANCH --build-arg
PYTHON_VER=$PYTHON_VER --no-cache -t
registry.orr.noaa.gov/gnome/webgnomeapi:$CI_COMMIT_BRANCH.temp .
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker push registry.orr.noaa.gov/gnome/webgnomeapi:$CI_COMMIT_BRANCH.temp
test_img:
stage: test_img
only:
- develop
- main
- production
except:
- pipelines
- schedules
tags:
- docker
- linux
image:
name: registry.orr.noaa.gov/gnome/webgnomeapi:$CI_COMMIT_BRANCH.temp
entrypoint: [""]
script:
- cd /webgnomeapi
- conda install -y --file conda_requirements_test.txt
- redis-server --daemonize yes
- pytest webgnome_api/tests
rename_temp_img:
stage: rename_temp_img
only:
- develop
- main
- production
except:
- pipelines
- schedules
tags:
- shell
- build
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker pull registry.orr.noaa.gov/gnome/webgnomeapi:$CI_COMMIT_BRANCH.temp
- >
docker image tag
registry.orr.noaa.gov/gnome/webgnomeapi:$CI_COMMIT_BRANCH.temp
registry.orr.noaa.gov/gnome/webgnomeapi:$CI_COMMIT_BRANCH
- docker push registry.orr.noaa.gov/gnome/webgnomeapi:$CI_COMMIT_BRANCH
- docker image rm
registry.orr.noaa.gov/gnome/webgnomeapi:$CI_COMMIT_BRANCH.temp
# Ok, this almost works, but there is a problem, in that /bin/reg will remove
# the image and all tags associated with it, including the one we wanted to keep.
# It looks like there will be a new tagging API soon, but not yet.
# So we will hold off on running this task for now.
#remove_temp_img:
# stage: remove_temp_img
# only:
# - develop
# - main
# - production
# image: docker:stable
# tags:
# - docker
# services:
# - docker:stable-dind
# variables:
# REG_SHA256: 97ca5b3105ef32fcc124c362d87721af549da444f2bb4550f7a2ecd4c9206ebe
# REG_VERSION: 0.16.1
# before_script:
# - apk add --no-cache curl
# - >
# curl --fail --show-error
# --location "https://github.com/genuinetools/reg/releases/download/v$REG_VERSION/reg-linux-386"
# --output /usr/local/bin/reg
# - echo "$REG_SHA256 /usr/local/bin/reg" | sha256sum -c -
# - chmod a+x /usr/local/bin/reg
# script:
# - >
# /usr/local/bin/reg rm -d --auth-url $CI_REGISTRY
# -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD
# registry.orr.noaa.gov/gnome/webgnomeapi:$CI_COMMIT_BRANCH.temp
###
###
### Deployment tasks on gnome-dev.orr.noaa.gov
###
### - The deployment for gnome-dev.orr.noaa.gov will be such that any change
### in the develop branch will be automatically deployed to this host.
### - In addition, the develop branch deployment can be triggered from the
### gnome-deploy project
###
###
deploy_redis_dev:
stage: deploy
rules:
- if:
$CI_COMMIT_BRANCH == "develop" && $CI_PIPELINE_SOURCE =~
/\b(push|merge_request_event|pipeline|schedule|web)\b/
tags:
- gnome-dev
- deploy
environment:
name: dev-deployment
url: https://gnome-dev.orr.noaa.gov
on_stop: stop_redis_dev
variables:
IMAGE_TAG: redis:latest
CONTAINER_NAME: redis
DB_VOLUME: redisdata
GIT_STRATEGY: none
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker pull $IMAGE_TAG
- docker service rm $CONTAINER_NAME || true
- docker service create --name $CONTAINER_NAME --network $APP_NETWORK
$IMAGE_TAG
stop_redis_dev:
stage: deploy
rules:
- if:
$CI_COMMIT_BRANCH == "develop" && $CI_PIPELINE_SOURCE =~
/\b(push|merge_request_event|pipeline|schedule|web)\b/
when: manual
tags:
- gnome-dev
- deploy
environment:
name: dev-deployment
action: stop
variables:
CONTAINER_NAME: redis
GIT_STRATEGY: none
script:
- docker stop $CONTAINER_NAME && docker container rm --volumes
$CONTAINER_NAME
deploy_proxy_dev:
stage: deploy
rules:
- if:
$CI_COMMIT_BRANCH == "develop" && $CI_PIPELINE_SOURCE =~
/\b(push|merge_request_event|pipeline|schedule|web)\b/
tags:
- gnome-dev
- deploy
environment:
name: dev-deployment
url: https://gnome-dev.orr.noaa.gov
on_stop: stop_proxy_dev
variables:
IMAGE_TAG: nginx:latest
GIT_STRATEGY: none
CONTAINER_NAME: webgnome_proxy
PORT_MAPPING1: 443:443
PORT_MAPPING2: 80:80
GNOME_DEPLOY_FOLDER: /data/webgnome/gnome-deploy
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker pull $IMAGE_TAG
- if [ -d $GNOME_DEPLOY_FOLDER ]; then rm -rf $GNOME_DEPLOY_FOLDER; fi
- git clone --depth 1 -b $CI_COMMIT_BRANCH
https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.orr.noaa.gov/gnome/gnome-deploy.git
$GNOME_DEPLOY_FOLDER
- >
chmod go+rx $GNOME_DEPLOY_FOLDER $GNOME_DEPLOY_FOLDER/config
$GNOME_DEPLOY_FOLDER/config/nginx
- chmod go+rw $GNOME_DEPLOY_FOLDER/config/nginx/*
- ls -la $GNOME_DEPLOY_FOLDER
- ls -la $GNOME_DEPLOY_FOLDER/config/nginx
- ls -la /etc/ssl/certs/*
- docker service rm webgnome_api_loadbalancer || true
- docker service create --name webgnome_api_loadbalancer --network
$APP_NETWORK --mount
type=bind,source=$GNOME_DEPLOY_FOLDER/config/haproxy,destination=/usr/local/etc/haproxy
haproxy:2.3
- docker service rm $CONTAINER_NAME || true
- docker service create --name $CONTAINER_NAME --network $APP_NETWORK -p
$PORT_MAPPING1 -p $PORT_MAPPING2 --mount
type=bind,source=$GNOME_DEPLOY_FOLDER/config/nginx,destination=/etc/nginx/
--mount type=bind,source=/etc/ssl/certs,destination=/etc/ssl/certs
$IMAGE_TAG
- docker service ls
stop_proxy_dev:
stage: deploy
rules:
- if:
$CI_COMMIT_BRANCH == "develop" && $CI_PIPELINE_SOURCE =~
/\b(push|merge_request_event|pipeline|schedule|web)\b/
when: manual
tags:
- gnome-dev
- deploy
environment:
name: dev-deployment
action: stop
variables:
GIT_STRATEGY: none
CONTAINER_NAME: webgnome_proxy
script:
- docker service rm $CONTAINER_NAME
- docker service rm webgnome_api_loadbalancer
deploy_api_dev:
stage: deploy
needs: [deploy_redis_dev]
rules:
- if:
$CI_COMMIT_BRANCH == "develop" && $CI_PIPELINE_SOURCE =~
/\b(push|merge_request_event|pipeline|schedule|web)\b/
tags:
- gnome-dev
- deploy
environment:
name: dev-deployment
url: https://gnome-dev.orr.noaa.gov
on_stop: stop_api_dev
variables:
IMAGE_TAG: registry.orr.noaa.gov/gnome/webgnomeapi:$CI_COMMIT_BRANCH
CONTAINER_NAME: webgnome_api
PORT_MAPPING: 80:80
MODELS_VOLUME: webgnome_models
GIT_STRATEGY: none
API_SCALE: 3
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker volume inspect $MODELS_VOLUME >/dev/null 2>&1 || docker volume
create $MODELS_VOLUME
- docker pull $IMAGE_TAG
- docker swarm init || true
- docker service rm $CONTAINER_NAME || true
- docker service create --name $CONTAINER_NAME --network $APP_NETWORK
--mount source=$MODELS_VOLUME,destination=/webgnomeapi/models --network
$APP_NETWORK --endpoint-mode dnsrr --replicas=$API_SCALE $IMAGE_TAG
- docker service ps $CONTAINER_NAME
- docker service logs $CONTAINER_NAME
stop_api_dev:
stage: deploy
rules:
- if:
$CI_COMMIT_BRANCH == "develop" && $CI_PIPELINE_SOURCE =~
/\b(push|merge_request_event|pipeline|schedule|web)\b/
when: manual
tags:
- gnome-dev
- deploy
environment:
name: dev-deployment
action: stop
variables:
CONTAINER_NAME: webgnome_api
GIT_STRATEGY: none
script:
- docker service rm $CONTAINER_NAME
###
###
### Deployment tasks on gnome-stage.orr.noaa.gov
###
### - The deployment for gnome-stage.orr.noaa.gov will be such that any change
### in the main branch will be automatically deployed to this host.
### - In addition, the main branch deployment can be triggered from the
### gnome-deploy project
###
###
deploy_redis_stage:
stage: deploy
rules:
- if:
$CI_COMMIT_BRANCH == "main" && $CI_PIPELINE_SOURCE =~
/\b(push|merge_request_event|pipeline|schedule|web)\b/
tags:
- gnome-stage
- deploy
environment:
name: stage-deployment
url: https://gnome-stage.orr.noaa.gov
on_stop: stop_redis_stage
variables:
IMAGE_TAG: redis:latest
CONTAINER_NAME: redis
DB_VOLUME: redisdata
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- >
docker network inspect $APP_NETWORK >/dev/null 2>&1 || docker network
create -d bridge $APP_NETWORK
- >
docker volume inspect $DB_VOLUME >/dev/null 2>&1 || docker volume create
$DB_VOLUME
- docker pull $IMAGE_TAG
- docker stop $CONTAINER_NAME && docker container rm --volumes
$CONTAINER_NAME
- >
docker run -d --name $CONTAINER_NAME --network $APP_NETWORK -v
$DB_VOLUME:/data --restart unless-stopped $IMAGE_TAG
stop_redis_stage:
stage: deploy
rules:
- if:
$CI_COMMIT_BRANCH == "main" && $CI_PIPELINE_SOURCE =~
/\b(push|merge_request_event|pipeline|schedule|web)\b/
when: manual
tags:
- gnome-stage
- deploy
environment:
name: stage-deployment
action: stop
variables:
CONTAINER_NAME: redis
script:
- docker stop $CONTAINER_NAME && docker container rm --volumes
$CONTAINER_NAME
deploy_proxy_stage:
stage: deploy
rules:
- if:
$CI_COMMIT_BRANCH == "main" && $CI_PIPELINE_SOURCE =~
/\b(push|merge_request_event|pipeline|schedule|web)\b/
tags:
- gnome-stage
- deploy
environment:
name: stage-deployment
url: https://gnome-stage.orr.noaa.gov
on_stop: stop_proxy_stage
variables:
IMAGE_TAG: nginx:latest
CONTAINER_NAME: webgnome_proxy
PORT_MAPPING1: 443:443
PORT_MAPPING2: 80:80
GNOME_DEPLOY_FOLDER: /data/webgnome/gnome-deploy
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- >
docker network inspect $APP_NETWORK >/dev/null 2>&1 || docker network
create -d bridge $APP_NETWORK
- docker pull $IMAGE_TAG
- docker stop $CONTAINER_NAME && docker container rm --volumes
$CONTAINER_NAME
- if [ -d $GNOME_DEPLOY_FOLDER ]; then rm -rf $GNOME_DEPLOY_FOLDER; fi
- git clone --depth 1 -b $CI_COMMIT_BRANCH
https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.orr.noaa.gov/gnome/gnome-deploy.git
$GNOME_DEPLOY_FOLDER
- >
chmod go+rx $GNOME_DEPLOY_FOLDER $GNOME_DEPLOY_FOLDER/config
$GNOME_DEPLOY_FOLDER/config/nginx
- chmod go+rw $GNOME_DEPLOY_FOLDER/config/nginx/*
- ls -la $GNOME_DEPLOY_FOLDER
- ls -la $GNOME_DEPLOY_FOLDER/config/nginx
- ls -la /etc/ssl/certs/*
- >
docker run -d --name $CONTAINER_NAME --network $APP_NETWORK --restart
unless-stopped -p $PORT_MAPPING1 -p $PORT_MAPPING2 -v
$GNOME_DEPLOY_FOLDER/config/nginx:/etc/nginx/ -v
/etc/ssl/certs:/etc/ssl/certs $IMAGE_TAG
stop_proxy_stage:
stage: deploy
rules:
- if:
$CI_COMMIT_BRANCH == "main" && $CI_PIPELINE_SOURCE =~
/\b(push|merge_request_event|pipeline|schedule|web)\b/
when: manual
tags:
- gnome-stage
- deploy
environment:
name: stage-deployment
action: stop
variables:
CONTAINER_NAME: webgnome_proxy
script:
- docker stop $CONTAINER_NAME && docker container rm --volumes
$CONTAINER_NAME
deploy_api_stage:
stage: deploy
rules:
- if:
$CI_COMMIT_BRANCH == "main" && $CI_PIPELINE_SOURCE =~
/\b(push|merge_request_event|pipeline|schedule|web)\b/
tags:
- gnome-stage
- deploy
environment:
name: stage-deployment
url: https://gnome-stage.orr.noaa.gov
on_stop: stop_api_stage
variables:
IMAGE_TAG: registry.orr.noaa.gov/gnome/webgnomeapi:$CI_COMMIT_BRANCH
CONTAINER_NAME: webgnome_api
PORT_MAPPING: 9898:9898
MODELS_VOLUME: webgnome_models
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- >
docker network inspect $APP_NETWORK >/dev/null 2>&1 || docker network
create -d bridge $APP_NETWORK
- >
docker volume inspect $MODELS_VOLUME >/dev/null 2>&1 || docker volume
create $MODELS_VOLUME
- docker pull $IMAGE_TAG
- docker stop $CONTAINER_NAME && docker container rm --volumes
$CONTAINER_NAME
- >
docker run -d --network $APP_NETWORK --name $CONTAINER_NAME -p
$PORT_MAPPING -v $MODELS_VOLUME:/webgnomeapi/models --restart
unless-stopped $IMAGE_TAG
- docker ps
- docker logs $CONTAINER_NAME
stop_api_stage:
stage: deploy
rules:
- if:
$CI_COMMIT_BRANCH == "main" && $CI_PIPELINE_SOURCE =~
/\b(push|merge_request_event|pipeline|schedule|web)\b/
when: manual
tags:
- gnome-stage
- deploy
environment:
name: stage-deployment
action: stop
variables:
CONTAINER_NAME: webgnome_api
script:
- docker stop $CONTAINER_NAME && docker container rm --volumes
$CONTAINER_NAME
###
###
### Deployment tasks on gnome.orr.noaa.gov
###
### - The deployment for gnome.orr.noaa.gov will be such that changes in the
### production branch will *not* be automatically deployed to the host.
### Rather, the deployment will be handled as a multi-project pipeline
### controlled from the CI pipeline of the gnome-deploy project.
###
###
deploy_redis_production:
stage: deploy
rules:
- if: $CI_COMMIT_BRANCH == "production" && $CI_PIPELINE_SOURCE == "pipeline"
tags:
- gnome-prod
- deploy
environment:
name: production-deployment
url: https://gnome.orr.noaa.gov
on_stop: stop_redis_production
variables:
IMAGE_TAG: redis:latest
CONTAINER_NAME: redis
DB_VOLUME: redisdata
GIT_STRATEGY: none
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker pull $IMAGE_TAG
- docker service rm $CONTAINER_NAME || true
- docker service create --name $CONTAINER_NAME --network $APP_NETWORK
$IMAGE_TAG
stop_redis_production:
stage: deploy
rules:
- if: $CI_COMMIT_BRANCH == "production" && $CI_PIPELINE_SOURCE == "pipeline"
when: manual
tags:
- gnome-prod
- deploy
environment:
name: production-deployment
action: stop
variables:
CONTAINER_NAME: redis
GIT_STRATEGY: none
script:
- docker stop $CONTAINER_NAME && docker container rm --volumes
$CONTAINER_NAME
deploy_proxy_production:
stage: deploy
rules:
- if: $CI_COMMIT_BRANCH == "production" && $CI_PIPELINE_SOURCE == "pipeline"
tags:
- gnome-prod
- deploy
environment:
name: production-deployment
url: https://gnome.orr.noaa.gov
on_stop: stop_proxy_production
variables:
IMAGE_TAG: nginx:latest
CONTAINER_NAME: webgnome_proxy
GIT_STRATEGY: none
PORT_MAPPING1: 443:443
PORT_MAPPING2: 80:80
GNOME_DEPLOY_FOLDER: /data/webgnome/gnome-deploy
GNOME_TESTDATA_FOLDER: /data/gnome_testdata
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker pull $IMAGE_TAG
- if [ -d $GNOME_DEPLOY_FOLDER ]; then rm -rf $GNOME_DEPLOY_FOLDER; fi
- git clone --depth 1 -b $CI_COMMIT_BRANCH
https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.orr.noaa.gov/gnome/gnome-deploy.git
$GNOME_DEPLOY_FOLDER
- >
chmod go+rx $GNOME_DEPLOY_FOLDER $GNOME_DEPLOY_FOLDER/config
$GNOME_DEPLOY_FOLDER/config/nginx
- chmod go+rw $GNOME_DEPLOY_FOLDER/config/nginx/*
- ls -la $GNOME_DEPLOY_FOLDER
- ls -la $GNOME_DEPLOY_FOLDER/config/nginx
- ls -la /etc/ssl/certs/*
- docker service rm webgnome_api_loadbalancer || true
- docker service create --name webgnome_api_loadbalancer --network
$APP_NETWORK --mount
type=bind,source=$GNOME_DEPLOY_FOLDER/config/haproxy,destination=/usr/local/etc/haproxy
haproxy:2.3
- docker service rm $CONTAINER_NAME || true
- docker service create --name $CONTAINER_NAME --network $APP_NETWORK -p
$PORT_MAPPING1 -p $PORT_MAPPING2 --mount
type=bind,source=$GNOME_DEPLOY_FOLDER/config/nginx,destination=/etc/nginx/
--mount
type=bind,source=$GNOME_TESTDATA_FOLDER,destination=/usr/share/nginx/html/py_gnome_testdata/
--mount type=bind,source=/etc/ssl/certs,destination=/etc/ssl/certs
$IMAGE_TAG
- docker service ls
stop_proxy_production:
stage: deploy
rules:
- if: $CI_COMMIT_BRANCH == "production" && $CI_PIPELINE_SOURCE == "pipeline"
when: manual
tags:
- gnome-prod
- deploy
environment:
name: production-deployment
action: stop
variables:
GIT_STRATEGY: none
CONTAINER_NAME: webgnome_proxy
script:
- docker service rm $CONTAINER_NAME
- docker service rm webgnome_api_loadbalancer
deploy_api_production:
stage: deploy
needs: [deploy_redis_production]
rules:
- if: $CI_COMMIT_BRANCH == "production" && $CI_PIPELINE_SOURCE == "pipeline"
tags:
- gnome-prod
- deploy
environment:
name: production-deployment
url: https://gnome.orr.noaa.gov
on_stop: stop_api_production
variables:
IMAGE_TAG: registry.orr.noaa.gov/gnome/webgnomeapi:$CI_COMMIT_BRANCH
CONTAINER_NAME: webgnome_api
PORT_MAPPING: 9898:9898
GIT_STRATEGY: none
API_SCALE: 40
MODELS_VOLUME: webgnome_models
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker volume inspect $MODELS_VOLUME >/dev/null 2>&1 || docker volume
create $MODELS_VOLUME
- docker pull $IMAGE_TAG
- docker service rm $CONTAINER_NAME || true
- docker service create --name $CONTAINER_NAME --network $APP_NETWORK
--mount source=$MODELS_VOLUME,destination=/webgnomeapi/models
--endpoint-mode dnsrr --replicas=$API_SCALE $IMAGE_TAG
- docker service ps $CONTAINER_NAME
- docker service logs $CONTAINER_NAME
stop_api_production:
stage: deploy
rules:
- if: $CI_COMMIT_BRANCH == "production" && $CI_PIPELINE_SOURCE == "pipeline"
when: manual
tags:
- gnome-prod
- deploy
environment:
name: production-deployment
action: stop
variables:
CONTAINER_NAME: webgnome_api
GIT_STRATEGY: none
script:
- docker service rm $CONTAINER_NAME
deploy_docs_production:
stage: deploy
rules:
- if: $CI_COMMIT_BRANCH == "production" && $CI_PIPELINE_SOURCE == "pipeline"
tags:
- gnome-prod
- deploy
environment:
name: production-deployment
url: https://gnome.orr.noaa.gov
on_stop: stop_docs_production
variables:
IMAGE_TAG: registry.orr.noaa.gov/gnome/pygnome/docs
CONTAINER_NAME: pygnome_docs
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker pull $IMAGE_TAG
- docker service rm $CONTAINER_NAME
- docker service create --name $CONTAINER_NAME --network $APP_NETWORK
$IMAGE_TAG
stop_docs_production:
stage: deploy
rules:
- if: $CI_COMMIT_BRANCH == "production" && $CI_PIPELINE_SOURCE == "pipeline"
when: manual
tags:
- gnome-prod
- deploy
environment:
name: production-deployment
action: stop
variables:
CONTAINER_NAME: pygnome_docs
GIT_STRATEGY: none
script:
- docker service rm $CONTAINER_NAME
###
###
### Maintenance tasks
###
###
prune_session_folders_dev:
stage: maintenance
image: registry.orr.noaa.gov/erd/centos-conda/centos7-python$PYTHON_VER
rules:
- if: $CI_COMMIT_BRANCH == "develop" && $CI_PIPELINE_SOURCE == "schedule"
environment:
name: dev-deployment
url: https://gnome-dev.orr.noaa.gov
tags:
- gnome-dev
- deploy
variables:
CONTAINER_NAME: webgnome_api
SCRIPT_NAME: ./prune_old_session_folders.sh
script:
- docker exec $(docker ps -q -f name=$CONTAINER_NAME|head -n 1) /bin/bash $SCRIPT_NAME
prune_tmp_files_dev:
stage: maintenance
image: registry.orr.noaa.gov/erd/centos-conda/centos7-python$PYTHON_VER
rules:
- if: $CI_COMMIT_BRANCH == "develop" && $CI_PIPELINE_SOURCE == "schedule"
environment:
name: dev-deployment
url: https://gnome-dev.orr.noaa.gov
tags:
- gnome-dev
- deploy
variables:
CONTAINER_NAME: webgnome_api
SCRIPT_NAME: ./prune_old_tmp_files.sh
script:
- docker exec $(docker ps -q -f name=$CONTAINER_NAME|head -n 1) /bin/bash $SCRIPT_NAME
prune_session_folders_stage:
stage: maintenance
image: registry.orr.noaa.gov/erd/centos-conda/centos7-python$PYTHON_VER
rules:
- if: $CI_COMMIT_BRANCH == "main" && $CI_PIPELINE_SOURCE == "schedule"
environment:
name: stage-deployment
url: https://gnome-stage.orr.noaa.gov
tags:
- gnome-stage
- deploy
variables:
CONTAINER_NAME: webgnome_api
SCRIPT_NAME: ./prune_old_session_folders.sh
script:
- docker exec $(docker ps -q -f name=$CONTAINER_NAME|head -n 1) /bin/bash $SCRIPT_NAME
prune_tmp_files_stage:
stage: maintenance
image: registry.orr.noaa.gov/erd/centos-conda/centos7-python$PYTHON_VER
rules:
- if: $CI_COMMIT_BRANCH == "main" && $CI_PIPELINE_SOURCE == "schedule"
environment:
name: stage-deployment
url: https://gnome-stage.orr.noaa.gov
tags:
- gnome-stage
- deploy
variables:
CONTAINER_NAME: webgnome_api
SCRIPT_NAME: ./prune_old_tmp_files.sh
script:
- docker exec $(docker ps -q -f name=$CONTAINER_NAME|head -n 1) /bin/bash $SCRIPT_NAME
prune_session_folders_production:
stage: maintenance
image: registry.orr.noaa.gov/erd/centos-conda/centos7-python$PYTHON_VER
rules:
- if: $CI_COMMIT_BRANCH == "production" && $CI_PIPELINE_SOURCE == "schedule"
environment:
name: production-deployment
url: https://gnome.orr.noaa.gov
tags:
- gnome-prod
- deploy
variables:
CONTAINER_NAME: webgnome_api
SCRIPT_NAME: ./prune_old_session_folders.sh
script:
- docker exec $(docker ps -q -f name=$CONTAINER_NAME|head -n 1) /bin/bash $SCRIPT_NAME
prune_tmp_files_production:
stage: maintenance
image: registry.orr.noaa.gov/erd/centos-conda/centos7-python$PYTHON_VER
rules:
- if: $CI_COMMIT_BRANCH == "production" && $CI_PIPELINE_SOURCE == "schedule"
environment:
name: production-deployment
url: https://gnome.orr.noaa.gov
tags:
- gnome-prod
- deploy
variables:
CONTAINER_NAME: webgnome_api
SCRIPT_NAME: ./prune_old_tmp_files.sh
script:
- docker exec $(docker ps -q -f name=$CONTAINER_NAME|head -n 1) /bin/bash $SCRIPT_NAME
.docker tidy:
stage: util
when: manual
script:
- docker system prune -f -a --volumes
docker prod tidy:
extends: '.docker tidy'
only:
refs:
- production
tags:
- deploy
- gnome-prod
docker dev tidy:
extends: '.docker tidy'
only:
refs:
- develop
tags:
- deploy
- gnome-dev
docker stage tidy:
extends: '.docker tidy'
only:
refs:
- main
tags:
- deploy
- gnome-stage