forked from golaneduard/argocd_sops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
68 lines (62 loc) · 2.25 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
variables:
# ARGOCD_APP_NAME: "fastapi-sqlalchemy"
DOCKER_IMAGE_TAG: ${CI_PIPELINE_IID}-${CI_COMMIT_SHORT_SHA}-$CI_COMMIT_REF_NAME
TIMEOUT_SYNC: 300
# List of stages for jobs, and their order of execution
stages:
- build
- deploy
#Export env vars
.export-vars:
before_script:
- export $(grep -v '^#' ${envVars} | tr -d ' ' | xargs)
#ArgoCD Connect
.argocd: &argocd |
argocd login ${ARGOCD_SERVER_URL} --insecure --grpc-web --username ${ARGOCD_USERNAME} --password ${ARGOCD_PASSWORD}
build:
image: docker:latest
environment: ${CI_COMMIT_REF_NAME}
stage: build
services:
- docker:dind
extends: .export-vars
only:
refs:
- main
- development
script:
- cat ${GCR_SERVICE_KEY} | docker login -u _json_key --password-stdin https://gcr.io
# - echo "$DOCKER_REGISTRY_PASS" | docker login --username $DOCKER_REGISTRY_USER --password-stdin
- docker build -t "${DOCKER_IMAGE_REGISTRY}:${DOCKER_IMAGE_TAG}" -f deployment/Dockerfile .
- docker push "${DOCKER_IMAGE_REGISTRY}:${DOCKER_IMAGE_TAG}"
deploy_dev:
environment: development
image:
name: "argoproj/argocd:v2.6.15"
extends:
- .export-vars
stage: deploy
only:
refs:
- development
script:
- *argocd
# - echo ${ENVIRONMENT} ${DOMAIN} ${NAMESPACE} ${DOCKER_IMAGE_REGISTRY} ${DOCKER_IMAGE_TAG}
- argocd app set fastapi-${ENVIRONMENT} --plugin-env ARGOCD_APP_NAME=fastapi-${ENVIRONMENT} --plugin-env DOMAIN=${DOMAIN} --plugin-env NAMESPACE=${NAMESPACE} --plugin-env ENVIRONMENT=${ENVIRONMENT} --plugin-env DOCKER_IMAGE_REGISTRY=${DOCKER_IMAGE_REGISTRY} --plugin-env DOCKER_IMAGE_TAG=${DOCKER_IMAGE_TAG}
- argocd app sync --timeout ${TIMEOUT_SYNC} fastapi-${ENVIRONMENT}
- argocd app wait fastapi-${ENVIRONMENT}
deploy_staging:
environment: staging
image:
name: "argoproj/argocd:v2.6.15"
extends:
- .export-vars
stage: deploy
only:
refs:
- main
script:
- *argocd
- argocd app set ${ARGOCD_APP_NAME} --plugin-env ARGOCD_APP_NAME=${ARGOCD_APP_NAME} --plugin-env ENVIRONMENT=${ENVIRONMENT} --plugin-env DOCKER_IMAGE_REGISTRY=${DOCKER_IMAGE_REGISTRY} --plugin-env DOCKER_IMAGE_TAG=${DOCKER_IMAGE_TAG}
- argocd app sync --timeout ${TIMEOUT_SYNC} ${ARGOCD_APP_NAME}
- argocd app wait ${ARGOCD_APP_NAME}