Required environment variables in my-gitlab.tld/group/project/settings/ci_cd
- DOCKER_HOST
- DOCKER_DRIVER
- DOCKER_TLS_VERIFY
- DOCKER_CERT_PATH
- SERVICE_PORT
image: docker:latest | |
services: | |
- docker:dind | |
stages: | |
- build | |
- deploy | |
before_script: | |
- echo $DOCKER_HOST | |
- echo $DOCKER_DRIVER | |
- echo $DOCKER_TLS_VERIFY | |
- find $DOCKER_CERT_PATH -type f | |
- docker info | |
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY | |
build_image: | |
stage: build | |
script: | |
- docker build --pull -t ${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_NAME} -f Dockerfile.build . | |
- docker push ${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_NAME} | |
only: | |
- staging | |
- master | |
deploy_staging: | |
stage: deploy | |
script: | |
- docker rm -f ${CI_PROJECT_PATH_SLUG}_${CI_ENVIRONMENT_SLUG} || true | |
- docker run --cidfile /tmp/${CI_PROJECT_PATH_SLUG}_${CI_ENVIRONMENT_SLUG}.cid -d -p $SERVICE_PORT:80 --name ${CI_PROJECT_PATH_SLUG}_${CI_ENVIRONMENT_SLUG} ${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_NAME} | |
- export CONTAINER_ID=$(cat /tmp/${CI_PROJECT_PATH_SLUG}_${CI_ENVIRONMENT_SLUG}.cid) | |
- export CONTAINER_STATUS=$(docker inspect -f {{.State.Running}} $CONTAINER_ID) | |
- if [ $CONTAINER_STATUS = "false" ]; then (docker logs $CONTAINER_ID; false); else true; fi | |
environment: | |
name: staging1 | |
only: | |
- staging |
[[runners]] | |
[runners.docker] | |
image = "docker:latest" | |
disable_cache = false | |
volumes = ["/cache", "/etc/docker/certs.d:/etc/docker/certs.d", "/etc/docker/client-certs.d:/etc/docker/client-certs.d"] |