image: docker:latest
services:
    - docker:dind

variables:
    NAME: dev-el6
    CONTAINER_TEST_IMAGE: ${CI_REGISTRY_IMAGE}:$CI_COMMIT_REF_SLUG
    CONTAINER_RELEASE_IMAGE: ${CI_REGISTRY_IMAGE}:latest

stages:
    - build
    - test
    - release

before_script:
    - echo "${CI_REGISTRY_PASSWORD}" | docker login -u ${CI_REGISTRY_USER} --password-stdin ${CI_REGISTRY}

build:
    stage: build
    script:
        - docker build --pull -t ${CONTAINER_TEST_IMAGE} .
        - docker push ${CONTAINER_TEST_IMAGE}

test:
    stage: test
    script:
        - docker run --rm ${CONTAINER_TEST_IMAGE} cat /etc/centos-release | grep "CentOS release 6"
        - docker run --rm ${CONTAINER_TEST_IMAGE} gcc --version | grep "gcc (GCC) 4\.4"
        - docker run --rm ${CONTAINER_TEST_IMAGE} uname -m | grep "x86_64"

release:
    stage: release
    script:
        - docker pull ${CONTAINER_TEST_IMAGE}
        - docker tag ${CONTAINER_TEST_IMAGE} ${CONTAINER_RELEASE_IMAGE}
        - docker push ${CONTAINER_RELEASE_IMAGE}
