4

So I'm trying to setup my Gitlab CI to trigger a job on git push to build and deploy my Docker. This is the .gitlab-ci.yml file I'm using based on an example from Gitlab docs (Elixir yml).

stages: - build build: before_script: - docker build -f Dockerfile.build -t ci-project-build-$CI_PROJECT_ID:$CI_BUILD_REF . - docker create -v /build/deps -v /build/_build -v /build/rel -v /root/.cache/aceapp/ --name build_data_$CI_PROJECT_ID_$CI_BUILD_REF busybox /bin/true tags: - docker stage: build script: - docker run --volumes-from build_data_$CI_PROJECT_ID_$CI_BUILD_REF --rm -t ci-project-build-$CI_PROJECT_ID:$CI_BUILD_REF 

The output when pushing to GitLab instance is this:

Running with gitlab-runner 10.7.2 (b5e03c94) on my.host.rhel.runner 8f724ea7 Using Shell executor... Running on my.host.local... Fetching changes... HEAD is now at 14351c4 Merge branch 'Development' into 'master' From https://my.host.example/zalmosc/ace-app 14351c4..9fa2d43 master -> origin/master Checking out 9fa2d435 as master... Skipping Git submodules setup $ # Auto DevOps variables and functions # collapsed multi-line command $ setup_docker $ build Logging to GitLab Container Registry with CI credentials... Login Succeeded Building Dockerfile-based application... invalid argument "/master:9fa2d4358e6c426b882e2251aa5a49880013614b" for t: Error parsing reference: "/master:9fa2d4358e6c426b882e2251aa5a49880013614b" is not a valid repository/tag: invalid reference format See 'docker build --help'. ERROR: Job failed: exit status 1 

I understand the docker tag is not valid (is the before_script: really triggered based on the name?), and I'm looking for help regarding a) a solution b) how I can learn more about the requirements for a pipeline that builds docker based on default settings. Do I need to tag my docker image locally and then somehow add this to my git commit?

3 Answers 3

1

The thing is -t is to tag your Docker image. See the docs here.

The tag should be formated like name:version, and you giving it /master:9fa2d4358e6c426b882e2251aa5a49880013614b which is not a valid tag. You could try to delete the / before master

Sign up to request clarification or add additional context in comments.

4 Comments

So the default build script for Docker images in Gitlab CI isn't doing a correct -t implementation? Thanks, I'll have a further look.
It does. It is not related to Docker, but to the arguments you pass in gitlab.ci.yml to your Docker command. These are wrong. Feel free to ask more questions, or to accept my answer so that the other are also helped :)
Most likely in the .gitlab-ci.yml file.
@Mornor where to edit it for gitlab's "auto devops" script?
1

Your tag cannot begin with '/':

$ docker build -f Dockerfile.build -t /master:9fa2d4358e6c426b882e2251aa5a49880013614b . invalid argument "/master:9fa2d4358e6c426b882e2251aa5a49880013614b" for "-t, --tag" flag: invalid reference format See 'docker build --help'. # remove '/' $ docker build -f Dockerfile.build -t master:9fa2d4358e6c426b882e2251aa5a49880013614b . Sending build context to Docker daemon 3.584kB Step 1/3 : FROM ubuntu:16.04 ---> 14f60031763d ... 

Comments

0

If you are not using the built in registry, you might have to set the CI_REGISTRY_IMAGE value to something. It seems that if you don't se this it gets set to /master and causes this error. you can set this in the CI setting page, or when making a new pipeline. e.g CI_REGISTRY_IMAGE gitlab.com/user/project

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.