.gitlab-ci.yml 1.64 KB
Newer Older
Daniel Widerin's avatar
Daniel Widerin committed
1 2 3 4
stages:
  - build
  - test

5
.build: &build_template
Daniel Widerin's avatar
Daniel Widerin committed
6
  image: docker:latest
Daniel Widerin's avatar
Daniel Widerin committed
7
  stage: build
Daniel Widerin's avatar
Daniel Widerin committed
8 9
  services:
    - docker:dind
Daniel Widerin's avatar
Daniel Widerin committed
10
  tags:
Daniel Widerin's avatar
Daniel Widerin committed
11
    - dind
Daniel Widerin's avatar
Daniel Widerin committed
12
  script:
Daniel Widerin's avatar
Daniel Widerin committed
13
    - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN ${DOCKER_TAG}
14 15
    - docker build -t ${CONTAINER_BUILD_IMAGE} -f ${APP_DIRECTORY}/Dockerfile .
    - docker push ${CONTAINER_BUILD_IMAGE}
Daniel Widerin's avatar
Daniel Widerin committed
16

17 18
build-example-1:
  <<: *build_template
Daniel Widerin's avatar
Daniel Widerin committed
19
  variables:
20 21 22 23 24 25 26 27 28 29
    APP_DIRECTORY: example-1
    CONTAINER_BUILD_IMAGE: ${DOCKER_TAG}:${APP_DIRECTORY}

build-example-2:
  <<: *build_template
  variables:
    APP_DIRECTORY: example-2
    CONTAINER_BUILD_IMAGE: ${DOCKER_TAG}:${APP_DIRECTORY}

.test: &test_template
Daniel Widerin's avatar
Daniel Widerin committed
30
  image: docker:latest
31
  stage: test
Daniel Widerin's avatar
Daniel Widerin committed
32 33
  services:
    - docker:dind
Daniel Widerin's avatar
Daniel Widerin committed
34
  tags:
Daniel Widerin's avatar
Daniel Widerin committed
35
    - dind
Daniel Widerin's avatar
Daniel Widerin committed
36
  script:
Daniel Widerin's avatar
Daniel Widerin committed
37
    - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN ${DOCKER_TAG}
38 39 40 41 42 43 44 45 46 47 48 49
    - docker pull ${CONTAINER_TEST_IMAGE}
    - docker run ${CONTAINER_TEST_IMAGE} pytest

test-example-1:
  <<: *test_template
  variables:
    CONTAINER_TEST_IMAGE: ${DOCKER_TAG}:example-1

test-example-2:
  <<: *test_template
  variables:
    CONTAINER_TEST_IMAGE: ${DOCKER_TAG}:example-2
Daniel Widerin's avatar
Daniel Widerin committed
50
  script:
Daniel Widerin's avatar
Daniel Widerin committed
51
    - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN ${DOCKER_TAG}
Daniel Widerin's avatar
Daniel Widerin committed
52
    - docker run -d --name redis-${CI_BUILD_ID} redis
Daniel Widerin's avatar
Daniel Widerin committed
53
    - docker pull ${CONTAINER_TEST_IMAGE}
Daniel Widerin's avatar
Daniel Widerin committed
54
    - docker run --link redis-${CI_BUILD_ID}:redis ${CONTAINER_TEST_IMAGE} pytest
Daniel Widerin's avatar
Daniel Widerin committed
55 56 57

non-dockerized-build-and-test-example-2:
  image: centos
Daniel Widerin's avatar
typo  
Daniel Widerin committed
58
  services:
Daniel Widerin's avatar
Daniel Widerin committed
59 60 61 62 63 64 65 66 67 68 69
    - redis
  stage: build
  script:
    - yum install -y python-devel python-virtualenv
    - virtualenv .
    - source bin/activate
    - pip install --upgrade pip
    - cd example-2
    - pip install -r requirements.txt
    - env
    - pytest