Has anyone used the gitlab.com and public gitlab runners to compile, build, docker build and push to the gitlab repo's using gitlabs public CI runners?

I’m looking for an example .gitlab-ci.yml which lets me run the following build/production cycle using the public gitlab-ci runners.
Here’s the Insufficient documentation that I’ve found so far.

Pipelines

Master

  • Git commit & push to master ( development branch GitLab Flow )
  • Unit Test and Benchmarking at the same time
  • Compile GoLang application
    • Archive and Cache compiled binary
  • Build Dockerfile with latest Archived/Cache’d binary.
    • Docker Push to private GitLab registry with $CI_COMMIT_REF_NAME or MASTER tag
    • Deploy via Kubernetes to GCE or some variant to staging for live review/testing.

Production

  • Submit a Merge Request with latest fully tested stable Master branch code to PRODUCTION branch.
  • Unit Test and Benchmarking at the same time
  • Compile GoLang application
    • Archive and Cache compiled binary
  • Build Dockerfile with latest Archived/Cache’d binary.
    • Docker Push to private GitLab registry with MASTER tag
    • Deploy via Kubernetes to GCE or some variant to the PRODUCTION Kubernetes GCE cluster.

Current .gitlab-ci.yml

I’m looking for any working examples or adjustments to be made to this as this is so far what I’m using for my .gitlab-ci.yml

stages:
  - build
  - stage
  - production

variables:
  CONTAINER_TEST_IMAGE: registry.gitlab.com/username/appname:$CI_BUILD_REF_NAME
  CONTAINER_RELEASE_IMAGE: registry.gitlab.com/username/appname:latest

compile-appname-go-1.8-alpine:
  image: golang:1.8-alpine
  stage: build
  script:
# Dumb workaround because I'm too lazy to mess with the $GOPATH
  - export BUILDPATH=$(pwd)
  - mkdir -pv /go/src/gitlab.com/username/AppName
  - cp -Rv ./* /go/src/gitlab.com/username/AppName
  - cd /go/src/gitlab.com/username/AppName
  - apk update && apk add git
  - go get -v .
  - go build main.go
# Dumb workaround pt2
  - cp -v /go/bin/AppName $BUILDPATH/
  artifacts:
    when: on_success
    paths:
    - ./AppName
  cache:
    paths:
    - ./AppName

stage-appname-alpine:
  image: docker:dind
  stage: stage
  when: on_success
  only:
  - master
  script:
    - ./run.sh appname build
    ## This section is what is run when ./run.sh appname build is executed.
    # - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.gitlab.com
    # - docker build -t registry.gitlab.com/username/appname:$3 .
    # - docker push registry.gitlab.com/username/appname:$3
    # - docker rm -f appname-staging
    # - ./run.sh appname run

# production-appname-alpine:
#   image: alpine
#   stage: production
#   when: on_success
#   only:
#   - production
#   script:
#     - echo "Replace me with deploy scripts!"

## Build Me Now!!

Current failing build log

The stage stage-webfund-alpine succeeds but the docker steps aren’t executed due to docker not being mounted regardless of what I’ve set for my gitlab container --privileged and docker.sock binds. It doesn’t work with one or the other either it just fails for no reason and I don’t know how to debug this.

Running with gitlab-ci-multi-runner 9.0.0 (08a9e6f)
  on domain.redacted.com (2c3ca68a)
Using Docker executor with image docker:dind ...
Using docker image sha256:b2b6c39b28a8b6135c7d9fb86531feb9a6880613be933c051c7e8f517c3127a7 ID=sha256:b2b6c39b28a8b6135c7d9fb86531feb9a6880613be933c051c7e8f517c3127a7 for predefined container...
Pulling docker image docker:dind ...
Using docker image docker:dind ID=sha256:4d0da1be773f9c6ff3573257870be1db867b1008c4c1c773a3091fa7c49726db for build container...
Running on runner-2c3ca68a-project-2673423-concurrent-0 via 70038e5bc088...
Cloning repository...
Cloning into '/builds/username/AppName'...
Checking out fa00387c as master...
Skipping Git submodules setup
Downloading artifacts for compile-go-1.8-alpine (13084665)...
Downloading artifacts from coordinator... ok        id=13084665 responseStatus=200 OK token=B9G6RV7b
$ ./run.sh appname build
Warning: failed to get default registry endpoint from daemon (Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?). Using system default: https://index.docker.io/v1/
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
invalid argument "registry.gitlab.com/username/appname:" for t: Error parsing reference: "registry.gitlab.com/username/appname:" is not a valid repository/tag: invalid reference format
See 'docker build --help'.
Error parsing reference: "registry.gitlab.com/username/appname:" is not a valid repository/tag: invalid reference format
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Job succeeded

Edit: Updated YAML that’s still failing.

Edit2: Added job output.

Hi, I had a similar goal, and was likewise unable to find an example .gitlab-ci.yml.

After some trial and error I was able to get it working. Here is a generalized version with some extra debugging output that built successfully in my project. The second step assumes a rails project with rspec and postgresql, but could be replaced for whatever your project needs.

image: "ruby"

stages:
  - build
  - test

build_docker_image:
  stage: build
  image: docker
  services:
    - name: docker:dind
      alias: docker-dind
  variables:
    DOCKER_HOST: "tcp://docker-dind:2375"
  before_script:
    - docker version
    - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.gitlab.com
  after_script:
    - docker logout registry.gitlab.com
  script:
    - printenv
    - docker info
    - docker images
    - docker run --rm hello-world
    - echo "building docker iamge registry.gitlab.com/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}:${CI_BUILD_REF_NAME}"
    - docker build -t registry.gitlab.com/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}:${CI_BUILD_REF_NAME} .
    - docker push registry.gitlab.com/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}:${CI_BUILD_REF_NAME}
    - docker images

test:
  stage: test
  image: registry.gitlab.com/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}:${CI_BUILD_REF_NAME}
  services:
    - postgres:latest
  variables:
    DATABASE_URL: "postgresql://postgres:postgres@postgres:5432/${CI_PROJECT_NAME}_test"
    RAILS_ENV: test
  script:
    - which ruby
    - ruby -v
    - bundle check || bundle install --jobs $(nproc) --path vendor/bundle
    - bundle exec rails db:create
    - bundle exec rails db:schema:load
    - bundle exec rails db:migrate
    - bundle exec rspec spec