Skip to content

Define env variables of --build-arg in Dockerfile.master

Achilleas Pipinellis requested to merge ci-commit-ref-name-master-docker into master

Description

There are two changes in the MR.

First, the `Dockerfile.master. This will ensure that https://gitlab.com/gitlab-com/gitlab-docs/blob/48fdcc1639b60d1f4576d0268667cb473c403086/.gitlab-ci.yml#L436 will pick the build arguments.

image:docs-latest:
  <<: *docker_prepare
  stage: pre-deploy
  artifacts: {}
  cache: {}
  dependencies: []
  variables:
    NANOC_ENV: 'production'
    IMAGE_NAME: $CI_REGISTRY_IMAGE:latest
    DOCKERFILE: Dockerfile.$CI_COMMIT_REF_NAME
  script:
    - docker build --build-arg NANOC_ENV=${NANOC_ENV} --build-arg CI_COMMIT_REF_NAME=${CI_COMMIT_REF_NAME} -t $IMAGE_NAME -f $DOCKERFILE .
    - docker push $IMAGE_NAME
  allow_failure: true
  only:
    - schedules

Second, we account for the possibility of CI_COMMIT_REF_NAME being nil (not set) in retrieve_branch.


TL;DR If not defined, CI_COMMIT_REF_NAME is nil and retrieve_branch will fail with NoMethodError: undefined method 'match' for nil:NilClass.

Test locally

Previously, docker build would fail with arguments:

docker build --build-arg NANOC_ENV=production CI_COMMIT_REF_NAME=master -t docs-test -f Dockerfile.master .

or without:

docker build -t docs-test -f Dockerfile.master .

The strange thing is that with a shell inside the Docker image, it worked:

docker run -it --rm -v $PWD:/source registry.gitlab.com/gitlab-com/gitlab-docs:bootstrap /bin/s

bundle exec rake default

Related issues

Closes https://gitlab.com/gitlab-com/gitlab-docs/issues/332.

Edited by Achilleas Pipinellis

Merge request reports