azure-function.yml 2.84 KB
Newer Older
Daniel Scholl's avatar
Daniel Scholl committed
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
# EXPECTED PIPELINE INHERITED GROUP VARIABLES
# --------------------------------------------------------------------------------
# AZURE                     (Protected Branch)
# AZURE_APP_ID              (Protected Branch)
# AZURE_APP_ID_OTHER        (Protected Branch)
# AZURE_BASE                (Protected Branch)
# AZURE_BASENAME            (Protected Branch)
# AZURE_BASENAME_21         (Protected Branch)
# AZURE_ELASTIC_HOST        (Protected Branch)
# AZURE_ELASTIC_PASSWORD    (Protected Branch/Masked Variable)
# AZURE_INVALID_JWT         (Protected Branch)
# AZURE_NO_ACCESS_ID        (Protected Branch)
# AZURE_NO_ACCESS_SECRET    (Protected Branch/Masked Variable)
# AZURE_PRINCIPAL_ID        (Protected Branch)
# AZURE_PRINCIPAL_SECRET    (Protected Branch/Masked Variable)
# AZURE_SERVICEBUS_KEY      (Protected Branch/Masked Variable)
# AZURE_STORAGE_KEY         (Protected Branch/Masked Variable)
# AZURE_SUBSCRIPTION_ID     (Protected Branch)
# AZURE_SUBSCRIPTION_NAME   (Protected Branch)
# AZURE_TENANT_ID           (Protected Branch)



# JOBS
# --------------------------------------------------------------------------------
azure_containerize:
  tags: ["docker-runner"]
  image: docker:latest
  services:
    - docker:dind
  stage: containerize
  needs: ["compile-and-unit-test"]
  variables:
    IMAGE: ${CI_PROJECT_NAME}-${CI_COMMIT_REF_SLUG}
  before_script:
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
    - apk add bash make py-pip
    - apk add --virtual=build gcc libffi-dev musl-dev openssl-dev python3-dev
    - pip3 install azure-cli
    - az --version
    - az login --service-principal -u $AZURE_PRINCIPAL_ID -p $AZURE_PRINCIPAL_SECRET --tenant $AZURE_TENANT_ID
  script:
    - docker build -f $AZURE_BUILD_SUBDIR/Dockerfile -t ${CI_REGISTRY_IMAGE}/$IMAGE .
    - docker tag ${CI_REGISTRY_IMAGE}/$IMAGE ${CI_REGISTRY_IMAGE}/$IMAGE:${CI_BUILD_ID}
    - docker push ${CI_REGISTRY_IMAGE}/$IMAGE:${CI_BUILD_ID}

    # Azure Container Registry
    - az acr login -n ${AZURE_BASE}cr
    - docker tag ${CI_REGISTRY_IMAGE}/$IMAGE ${AZURE_BASE}cr.azurecr.io/$IMAGE:${CI_BUILD_ID}
    - docker push ${AZURE_BASE}cr.azurecr.io/$IMAGE:${CI_BUILD_ID}
  only:
    variables:
      - $AZURE == 'true'
  except:
    variables:
      - $AZURE_DEBUG == 'true'

azure_deploy:
  image: microsoft/azure-cli
  stage: deploy
  needs: ["azure_containerize"]
  variables:
    AZURE_RESOURCE_GROUP: ${AZURE_BASENAME}-osdu-r2-app-rg
    AZURE_FUNCTIONAPP_NAME: ${AZURE_BASENAME_21}-enque
  before_script:
    - az login --service-principal -u $AZURE_PRINCIPAL_ID -p $AZURE_PRINCIPAL_SECRET --tenant $AZURE_TENANT_ID
  script:
    - |
      az functionapp config container set \
      --docker-custom-image-name ${AZURE_BASE}cr.azurecr.io/$IMAGE:${CI_BUILD_ID} \
      --name $AZURE_FUNCTIONAPP_NAME \
      --resource-group $AZURE_RESOURCE_GROUP \
      -ojsonc