Skip to content

Instantly share code, notes, and snippets.

@vladget
Created December 13, 2018 22:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vladget/2ed78907c7bd2c54553bcbb2f8778826 to your computer and use it in GitHub Desktop.
Save vladget/2ed78907c7bd2c54553bcbb2f8778826 to your computer and use it in GitHub Desktop.
Пример выпадающих блоков с текстом
Все директивы поддерживаемые в dappfile.yaml
dimg: <dimg_name... || ~>
from: <image>
fromDimg: <dimg_name>
fromDimgArtifact: <artifact_name>
git:
# local git
- as: <custom_name>  
  add: <absolute_path>
  to: <absolute_path>
  includePaths:
  - <relative_path>
  excludePaths:
  - <relative_path>  
  stageDependencies:
    install:
    - <relative_path or glob>
    beforeSetup:
    - <relative_path or glob>
    setup:
    - <relative_path or glob>
# remote git
- url: <git_repo_url>
  branch: <branch_name>
  commit: <commit>
  as: <custom_name>  
  add: <absolute_path>
  to: <absolute_path>
  includePaths:
  - <relative_path>
  excludePaths:
  - <relative_path>  
  stageDependencies:
    install:
    - <relative_path or glob>
    beforeSetup:
    - <relative_path or glob>
    setup:
    - <relative_path or glob>
import:
- artifact: <artifact_name>
  before: <install || setup>
  after: <install || setup>  
  add: <absolute_path>
  to: <absolute_path>
  includePaths:
  - <relative_path>
  excludePaths:
  - <relative_path>
shell:  
  beforeInstall:
  - <cmd>
  install:
  - <cmd>
  beforeSetup:
  - <cmd>
  setup:
  - <cmd>
ansible:  
  beforeInstall:
  - <task>
  install:
  - <task>
  beforeSetup:
  - <task>
  setup:
  - <task>
mount:
- from: build_dir
  to: <absolute_path>
- from: tmp_dir
  to: <absolute_path>
docker:
  VOLUME:
  - <volume>
  EXPOSE:
  - <expose>
  ENV:
    <env_name>: <env_value>
  LABEL:
    <label_name>: <label_value>
  ENTRYPOINT:
  - <entrypoint>
  CMD:
  - <cmd>
  ONBUILD:
  - <onbuild>
  WORKDIR: <workdir>
  USER: <user>
asLayers: <false || true>
---
artifact: <artifact_name>
from: <image>
fromDimg: <dimg_name>
fromDimgArtifact: <artifact_name>
git:
# local git
- as: <custom_name>  
  add: <absolute_path>
  to: <absolute_path>
  includePaths:
  - <relative_path>
  excludePaths:
  - <relative_path>  
  stageDependencies:
    install:
    - <relative_path or glob>
    beforeSetup:
    - <relative_path or glob>
    setup:
    - <relative_path or glob>
    buildArtifact:
    - <relative_path or glob>
# remote git
- url: <git_repo_url>
  branch: <branch_name>
  commit: <commit>
  as: <custom_name>  
  add: <absolute_path>
  to: <absolute_path>
  includePaths:
  - <relative_path>
  excludePaths:
  - <relative_path>  
  stageDependencies:
    install:
    - <relative_path or glob>
    beforeSetup:
    - <relative_path or glob>
    setup:
    - <relative_path or glob>
    buildArtifact:
    - <relative_path or glob>
shell:  
  beforeInstall:
  - <cmd>
  install:
  - <cmd>
  beforeSetup:
  - <cmd>
  setup:
  - <cmd>
  buildArtifact:
  - <cmd>
ansible:  
  beforeInstall:
  - <task>
  install:
  - <task>
  beforeSetup:
  - <task>
  setup:
  - <task>
  buildArtifact:
  - <task>
mount:
- from: build_dir
  to: <absolute_path>
- from: tmp_dir
  to: <absolute_path>
asLayers: <false || true>
Best practice .gitlab-ci.yml
stages:
  - build
  - cleanup-docker-registry
  - cleanup-build-cache
  - deploy

Build:
  stage: build
  script:
    - dapp dimg bp --ssh-key ~/.ssh/id_rsa --tag-ci ${CI_REGISTRY_IMAGE}
  retry: 2
  tags:
    - build
  except:
    - schedules

Cleanup docker registry:
  stage: cleanup-docker-registry
  script:
    - dapp dimg cleanup repo $CI_REGISTRY_IMAGE
  retry: 2
  only:
    - schedules
  tags:
    - deploy

Cleanup build cache:
  stage: cleanup-build-cache
  script:
    - dapp dimg stages cleanup local --improper-cache-version --improper-git-commit --improper-repo-cache $CI_REGISTRY_IMAGE
  retry: 2
  only:
    - schedules
  tags:
    - build
    
.base_deploy: &base_deploy
  stage: deploy
  script:
    - kubectl get ns "${CI_PROJECT_NAME}-${CI_ENVIRONMENT_CUSTOM_SLUG:-${CI_ENVIRONMENT_SLUG}}" || kubectl create ns "${CI_PROJECT_NAME}-${CI_ENVIRONMENT_CUSTOM_SLUG:-${CI_ENVIRONMENT_SLUG}}"
    - kubectl get secret registrysecret -n kube-system -o json |
                      jq ".metadata.namespace = \"${CI_PROJECT_NAME}-${CI_ENVIRONMENT_CUSTOM_SLUG:-${CI_ENVIRONMENT_SLUG}}\"|
                      del(.metadata.annotations,.metadata.creationTimestamp,.metadata.resourceVersion,.metadata.selfLink,.metadata.uid)" |
                      kubectl apply -f -
    - kubectl get secret ceph-secret -n kube-system -o json |
                      jq ".metadata.namespace = \"${CI_PROJECT_NAME}-${CI_ENVIRONMENT_CUSTOM_SLUG:-${CI_ENVIRONMENT_SLUG}}\"|
                      del(.metadata.annotations,.metadata.creationTimestamp,.metadata.resourceVersion,.metadata.selfLink,.metadata.uid)" |
                      kubectl apply -f -
    - export _RELEASE_NAME=${CI_PROJECT_NAME}-${CI_PROJECT_NAME}-${CI_ENVIRONMENT_CUSTOM_SLUG:-${CI_ENVIRONMENT_SLUG}}
    - export _LAST_DEPLOYED_RELEASE=$(helm list -adr | grep $_RELEASE_NAME | grep DEPLOYED | head -n1 | awk '{print $2}')
    - dapp kube deploy
      --timeout 86400
      --tag-ci
      --namespace ${CI_PROJECT_NAME}-${CI_ENVIRONMENT_CUSTOM_SLUG:-${CI_ENVIRONMENT_SLUG}}
      --set "global.env=${CI_ENVIRONMENT_CUSTOM_SLUG:-${CI_ENVIRONMENT_SLUG}}"
      --set "global.git_rev=${CI_BUILD_REF:-$CI_COMMIT_SHA}"
      --set "global.ci_url=$(ruby -r 'uri' -e  "p URI('$CI_ENVIRONMENT_URL').host")"
      $CI_REGISTRY_IMAGE || export _DEPLOY_FAILED=1
    - if [ "$_DEPLOY_FAILED" == "1" ] && [ "x$_LAST_DEPLOYED_RELEASE" != "x" ] ; then helm rollback $_RELEASE_NAME $_LAST_DEPLOYED_RELEASE ; fi
    - if [ "$_DEPLOY_FAILED" == "1" ] ; then exit 1 ; fi
  dependencies:
    - Build
  tags:
    - deploy

Deploy to Test:
  <<: *base_deploy
  environment:
    name: test
    url: https://${CI_PROJECT_NAME}.${CI_ENVIRONMENT_SLUG}.<domain>
  only:
    - branches
  except:
    - schedules
  when: manual

Deploy to Stage:
  <<: *base_deploy
  environment:
    name: stage
    url: https://${CI_PROJECT_NAME}.${CI_ENVIRONMENT_SLUG}.<domain>
  only:
    - tags
  except:
    - schedules

Deploy to Production:
  <<: *base_deploy
  environment:
    name: production
    url: https://${CI_PROJECT_NAME}.<domain>
  only:
    - tags
  except:
    - schedules
  when: manual
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment