0

I do have the following "shared.gitlab-ci.yml"

variables:
  GIT_SUBMODULE_STRATEGY: recursive
  DOCKERFILE_BUILD: docker/build/Dockerfile
  DOCKERFILE_TEST: docker/test/Dockerfile
  DOCKERFILE_ANALYZE: docker/analyze/Dockerfile
  BUILD_NAME: $CI_PROJECT_PATH_SLUG:$CI_COMMIT_REF_NAME-$CI_COMMIT_SHORT_SHA
  PREPARE_SCRIPT: ""
  BUILD_ARGS: ""

stages:
- build
- test
- analyze

before_script:
  - echo "Project Details:"
  - echo $CI_PROJECT_PATH_SLUG
  - echo $CI_COMMIT_REF_NAME
  - echo $CI_COMMIT_SHORT_SHA
  - echo "Build Variables:"
  - echo $BUILD_NAME
  - echo $DOCKERFILE_BUILD
  - echo $DOCKERFILE_TEST
  - echo $DOCKERFILE_ANALYZE
  - echo "Directory:"
  - ls -la
  - echo "Registry info:"
  - echo $CI_REGISTRY
  - echo $CI_REGISTRY_NAME
  - echo $CI_REGISTRY_USER
  - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
  - docker info

docker-build:
  image: docker:latest
  stage: build
  services:
    - docker:dind
  script:
    - docker build \
      --rm \
      --build-arg BRANCH_NAME=$CI_COMMIT_REF_NAME \
      --build-arg BUILD_ARGS=$BUILD_ARGS \
      -t $BUILD_NAME \
      $DOCKERFILE_BUILD
    - docker push $BUILD_NAME

Which is will be used/included in another repositories "gitlab-ci.yml" like :

include:
  - project: my-group/shared-pipeline
    ref: master
    file: shared.gitlab-ci.yml

The Dockerfile is also in this repository /docker/build/Dockerfile:

FROM unityci/editor:windows-2020.1.16f1-base-0.17.2 as unity 
ARG BRANCH_NAME
ARG BUILD_ARGS

CMD echo "Hello world! This is my first Docker image. Branch: $BRANCH_NAME" 

Somehow when I run the "gitlab" pipeline I'll get the following output:

Fetching changes...
Initialized empty Git repository in /builds/my-group/mygame/unity/.git/
Created fresh repository.
Checking out 3731ab28 as develop...
Updating/initializing submodules recursively...
Executing "step_script" stage of the job script
00:01
Using docker image sha256:6816f070b2395d750ce78e4fbdb7e9df0af63b7686f3063c09e008c2ef1a0036 for docker:latest with digest docker@sha256:9e13118c8f7b17349e2d350806082fdda135ebf2923376821f3eac23559b9141 ...
$ echo "Project Details:"
Project Details:
$ echo $CI_PROJECT_PATH_SLUG
my-group-mygame-unity
$ echo $CI_COMMIT_REF_NAME
develop
$ echo $CI_COMMIT_SHORT_SHA
3731ab28
$ echo "Build Variables:"
Build Variables:
$ echo $BUILD_NAME
my-group-mygame-unity:develop-3731ab28
$ echo $DOCKERFILE_BUILD
docker/build/Dockerfile
$ echo $DOCKERFILE_TEST
docker/test/Dockerfile
$ echo $DOCKERFILE_ANALYZE
docker/analyze/Dockerfile
$ echo "Directory:"
Directory:
$ ls -la
total 68
drwxrwxrwx    8 root     root          4096 Mar 15 05:32 .
drwxrwxrwx    4 root     root          4096 Mar 15 05:32 ..
-rw-rw-rw-    1 root     root          1509 Mar 15 05:32 .atomignore
drwxrwxrwx    7 root     root          4096 Mar 15 05:32 .git
-rw-rw-rw-    1 root     root          1848 Mar 15 05:32 .gitattributes
-rw-rw-rw-    1 root     root          1817 Mar 15 05:32 .gitignore
-rw-rw-rw-    1 root     root           230 Mar 15 05:32 .gitlab-ci.yml
drwxrwxrwx   13 root     root          4096 Mar 15 05:32 Assets
drwxrwxrwx    2 root     root          4096 Mar 15 05:32 Packages
drwxrwxrwx    2 root     root          4096 Mar 15 05:32 ProjectSettings
-rw-rw-rw-    1 root     root         11542 Mar 15 05:32 README.md
-rw-rw-rw-    1 root     root           947 Mar 15 05:32 Unity_lic.alf
-rw-rw-rw-    1 root     root          2485 Mar 15 05:32 Unity_v2017.x.ulf
drwxrwxrwx    3 root     root          4096 Mar 15 05:32 ci
drwxrwxrwx    3 root     root          4096 Mar 15 05:32 docker
$ echo "Registry info:"
Registry info:
$ echo $CI_REGISTRY
registry.gitlab.com
$ echo $CI_REGISTRY_NAME
$ echo $CI_REGISTRY_USER
gitlab-ci-token
$ docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
$ docker info
Client:
 Context:    default
 Debug Mode: false
Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 0
 Server Version: 20.10.13
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 2a1d4dbdb2a1030dc5b01e96fb110a9d9f150ecc
 runc version: v1.0.3-0-gf46b6ba2
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: default
WARNING: API is accessible on http://0.0.0.0:2375 without encryption.
         Access to the remote API is equivalent to root access on the host. Refer
         to the 'Docker daemon attack surface' section in the documentation for
         more information: https://docs.docker.com/go/attack-surface/
 Kernel Version: 5.4.109+
 Operating System: Alpine Linux v3.15 (containerized)
 OSType: linux
 Architecture: x86_64
 CPUs: 1
 Total Memory: 3.599GiB
 Name: b837f980368f
 ID: 6PTR:73WJ:JO7S:UML2:4FCQ:RL3P:6VTY:PV7D:37OL:UXQ2:M33X:3ZCV
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false
 Product License: Community Engine
$ docker build \ --rm \ --build-arg BRANCH_NAME=$CI_COMMIT_REF_NAME \ --build-arg BUILD_ARGS=$BUILD_ARGS \ -t $BUILD_NAME \ $DOCKERFILE_BUILD
"docker build" requires exactly 1 argument.
See 'docker build --help'.
Usage:  docker build [OPTIONS] PATH | URL | -
Build an image from a Dockerfile
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1

I always get: "docker build" requires exactly 1 argument.

I also tried for example:

- docker build --file="$DOCKERFILE_BUILD" 
- docker push $BUILD_NAME

OR

- docker build -f $DOCKERFILE_BUILD
- docker push $BUILD_NAME

The result always stays the same.

1 Answer 1

1

I think that you forgot '.'(dot)

docker build -f $DOCKERFILE_BUILD . 

(In my case) Even with this command, I got the error ...

1
  • you are right. I forgot
    – Pwnstar
    Commented Mar 24, 2022 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.