.gitlab-ci.yml 1.66 KB
Newer Older
collaboration's avatar
collaboration 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
image: docker:latest

stages:
  - build
  - release
  - deploy

#services:
#  - docker:dind

variables:
#  DOCKER_HOST: tcp://docker:2375
  DOCKER_HOST: unix:///var/run/docker.sock

#before_script:
#  - docker login -u gitlab-ci-token -p ${CI_BUILD_TOKEN} ${CI_REGISTRY}

pre:
  stage: build
  tags:
#    - dind
    - socket
  script:
    - docker login -u gitlab-ci-token -p ${CI_BUILD_TOKEN} ${CI_REGISTRY}
    - docker version
    - docker info

build:
  stage: build
  tags:
#    - dind
    - socket
  script:
    - docker login -u gitlab-ci-token -p ${CI_BUILD_TOKEN} ${CI_REGISTRY}
    - cd docker/
    - docker build --pull -t ${CI_REGISTRY_IMAGE}:${CI_BUILD_REF} .
    - docker push ${CI_REGISTRY_IMAGE}:${CI_BUILD_REF}

release-image:
  stage: release
  only:
    - tags
  tags:
#    - dind
    - socket
  script:
    - docker login -u gitlab-ci-token -p ${CI_BUILD_TOKEN} ${CI_REGISTRY}
    - echo "pull previous build"
    - docker pull ${CI_REGISTRY_IMAGE}:${CI_BUILD_REF}
    - echo "push tagged image"
    - docker tag ${CI_REGISTRY_IMAGE}:${CI_BUILD_REF} ${CI_REGISTRY_IMAGE}:${CI_BUILD_TAG}
    - docker push ${CI_REGISTRY_IMAGE}:${CI_BUILD_TAG}
    - echo "push latest image"
    - docker tag ${CI_REGISTRY_IMAGE}:${CI_BUILD_REF} ${CI_REGISTRY_IMAGE}:latest
    - docker push ${CI_REGISTRY_IMAGE}:latest
    
deploy-container:
  stage: deploy
  when: manual
#  only:
#    - tags
  image: debian:jessie
  tags:
    - socket
  variables:
    DOCKER_HOST: unix:///var/run/docker.sock
  script:
    - ./docker-install
    - docker login -u gitlab-ci-token -p ${CI_BUILD_TOKEN} ${CI_REGISTRY}
    - docker-compose up -d
#    - docker run -dit ${CI_REGISTRY_IMAGE}:${CI_BUILD_TAG} sh