.gitlab-ci.yml 2.6 KB
Newer Older
Tom Käsler's avatar
Tom Käsler committed
1
stages:
2
  - build
Tom Käsler's avatar
Tom Käsler committed
3 4
  - deploy

Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
5
.build-template: &build-template
Tom Käsler's avatar
Tom Käsler committed
6
  stage: build
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
7 8 9 10 11
  services:
    - name: docker:19.03.1-dind
      alias: docker
  variables:
    DOCKER_TLS_CERTDIR: ""
Tom Käsler's avatar
Tom Käsler committed
12
  tags:
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
13
    - docker-compose
14
  artifacts:
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
15
    expire_in: 2 mins
16
    paths:
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30
      - variables
      - private_key

.docker-push-template: &docker-push |
  docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
  docker-compose build $CI_COMMIT_REF_NAME
  docker-compose up --no-deps -d $CI_COMMIT_REF_NAME
  docker push "$CI_IMAGE_NAME:$VERSION"

.staging-server-env-template: &staging-server-env |
  echo "export CI_CONTAINER_INSTANCE_NAME=$CI_CONTAINER_INSTANCE_NAME" >> variables
  echo "export SSH_URL=$STAGING_FRONTEND_URL" >> variables
  echo "export SSH_CMD=$STAGING_SSH" >> variables
  echo "export VERSION=$VERSION" >> variables
31
  echo "export SERVICE_NAME=$SERVICE_NAME" >> variables
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
32
  echo "$STAGING_SSH_PRIVATE_KEY" >> private_key
33

Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
34 35 36 37 38
.production-server-env-template: &production-server-env |
  echo "export CI_CONTAINER_INSTANCE_NAME=$CI_CONTAINER_INSTANCE_NAME" >> variables
  echo "export SSH_URL=$PRODUCTION_FRONTEND_URL" >> variables
  echo "export SSH_CMD=$PRODUCTION_SSH" >> variables
  echo "export VERSION=$VERSION" >> variables
39
  echo "export SERVICE_NAME=$SERVICE_NAME" >> variables
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
40 41 42 43
  echo "$PRODUCTION_SSH_PRIVATE_KEY" >> private_key

build-master:
  <<: *build-template
44 45
  only:
    - master
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
46 47 48 49
  environment:
    name: Master
  variables:
    VERSION: 2.0.0
50
    SERVICE_NAME: master
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
51
    CI_CONTAINER_INSTANCE_NAME: arsnova-click-frontend
52
  script:
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
53 54
    - *production-server-env
    - *docker-push
Tom Käsler's avatar
Tom Käsler committed
55

Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
56 57
build-staging:
  <<: *build-template
Tom Käsler's avatar
Tom Käsler committed
58
  only:
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
59
    - staging
60
  environment:
61
    name: Staging
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
62 63
  variables:
    VERSION: 2.0.0-staging
64
    SERVICE_NAME: staging
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
65
    CI_CONTAINER_INSTANCE_NAME: arsnova-click-frontend-staging
Tom Käsler's avatar
Tom Käsler committed
66
  script:
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
67 68
    - *staging-server-env
    - *docker-push
69

70
build-beta:
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
71
  <<: *build-template
72
  only:
73
    - beta
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
74 75 76 77
  environment:
    name: Beta
  variables:
    VERSION: 2.0.0-beta
78
    SERVICE_NAME: beta
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
79
    CI_CONTAINER_INSTANCE_NAME: arsnova-click-frontend-beta
80
  script:
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
81 82
    - *staging-server-env
    - *docker-push
83

Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
84 85
deploy:
  stage: deploy
86
  only:
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
87 88
    - master
    - staging
89
    - beta
90
  tags:
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
91
    - ssh
92
  script:
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
93
    - source variables
94 95
    - eval $(ssh-agent -s)
    - mkdir ~/.ssh
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
96 97
    - ssh-keyscan "$SSH_URL" >> ~/.ssh/known_hosts
    - ssh-add <(cat private_key)
98
    - ssh $SSH_CMD "docker pull $CI_IMAGE_NAME:$VERSION && docker rm -f $CI_CONTAINER_INSTANCE_NAME ; docker-compose -f /home/arsnova/arsnova-click-docker/docker-compose-frontend.yml -p arsnova-click-frontend up --no-deps -d $SERVICE_NAME && docker image prune -af"