I have the following “shared.gitlab-ci.yml”:
############################################
# gfuchs/shared-pipeline
#
#
############################################
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 \
-f $DOCKERFILE_BUILD \
--build-arg BRANCH_NAME=$CI_COMMIT_REF_NAME \
--build-arg BUILD_ARGS=$BUILD_ARGS \
-t $BUILD_NAME
- docker push $BUILD_NAME
#rules:
# - exists:
# - $DOCKERFILE_BUILD
which I want to define for several projects. I have in another repo where my code is the following “gitlab-ci.yml”
#################################
# gfuchs-projects/action-mmo/black-knights
# Type: Unity Game
#################################
include:
- project: gfuchs-projects/shared-pipeline
ref: master
file: shared.gitlab-ci.yml
In this repo I also do contain the “Dockerfile” in “./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"
When I now build the pipeline I get the following output:
Initialized empty Git repository in /builds/gfuchs-projects/action-mmo/black-knights/.git/
Created fresh repository.
Checking out 3731ab28 as develop...
Updating/initializing submodules recursively...
Executing "step_script" stage of the job script
00:02
Using docker image sha256:6816f070b2395d750ce78e4fbdb7e9df0af63b7686f3063c09e008c2ef1a0036 for docker:latest with digest docker@sha256:9e13118c8f7b17349e2d350806082fdda135ebf2923376821f3eac23559b9141 ...
$ echo "Project Details:"
Project Details:
$ echo $CI_PROJECT_PATH_SLUG
gfuchs-projects-action-mmo-black-knights
$ echo $CI_COMMIT_REF_NAME
develop
$ echo $CI_COMMIT_SHORT_SHA
3731ab28
$ echo "Build Variables:"
Build Variables:
$ echo $BUILD_NAME
gfuchs-projects-action-mmo-black-knights: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 14 20:43 .
drwxrwxrwx 4 root root 4096 Mar 14 20:43 ..
-rw-rw-rw- 1 root root 1509 Mar 14 20:43 .atomignore
drwxrwxrwx 7 root root 4096 Mar 14 20:44 .git
-rw-rw-rw- 1 root root 1848 Mar 14 20:43 .gitattributes
-rw-rw-rw- 1 root root 1817 Mar 14 20:43 .gitignore
-rw-rw-rw- 1 root root 230 Mar 14 20:43 .gitlab-ci.yml
drwxrwxrwx 13 root root 4096 Mar 14 20:43 Assets
drwxrwxrwx 2 root root 4096 Mar 14 20:43 Packages
drwxrwxrwx 2 root root 4096 Mar 14 20:43 ProjectSettings
-rw-rw-rw- 1 root root 11542 Mar 14 20:43 README.md
-rw-rw-rw- 1 root root 947 Mar 14 20:43 Unity_lic.alf
-rw-rw-rw- 1 root root 2485 Mar 14 20:43 Unity_v2017.x.ulf
drwxrwxrwx 3 root root 4096 Mar 14 20:43 ci
drwxrwxrwx 3 root root 4096 Mar 14 20:43 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
Kernel Version: 5.4.109+
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/
Operating System: Alpine Linux v3.15 (containerized)
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 3.599GiB
Name: 2081a7d65bb1
ID: V7MM:NOII:G6SB:JNWS:TMSU:HAM7:HFVR:OW72:33S5:JRRT:QJXN:V5OJ
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 \ -f $DOCKERFILE_BUILD \ --build-arg BRANCH_NAME=$CI_COMMIT_REF_NAME \ --build-arg BUILD_ARGS=$BUILD_ARGS \ -t $BUILD_NAME
"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
It seems the “docker build” command is wrong and I tried literally anything but it won’t work. How do I accomplish that the “docker build” works?