diff --git a/.circleci/config.yml b/.circleci/config.yml index 7d65e065..7b720897 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -18,7 +18,6 @@ jobs: docker version docker info - - restore_cache: keys: - cache-{{ .Branch }} @@ -39,19 +38,25 @@ jobs: - run: name: Build docker image command: | - docker build --cache-from=${IMAGE_NAME} -t ${IMAGE_NAME} -t ${IMAGE_NAME}:$(cat VERSION) . + docker build \ + --pull \ + --cache-from=${IMAGE_NAME} \ + --build-arg BUILD_DATE="$(date +"%Y-%m-%d %H:%M:%S%:z")" \ + --build-arg VCS_REF=$(git rev-parse --short HEAD) \ + --build-arg VERSION=$(cat VERSION) \ + -t ${IMAGE_NAME}:$(cat VERSION) . - run: name: Launching container for testing command: | docker-compose up -d - sleep 10 + sleep 120 - run: name: Testing image command: | docker run --network container:$(docker-compose ps -q gitlab) \ - appropriate/curl --retry 12 --retry-delay 5 --retry-connrefused http://localhost/explore + appropriate/curl --retry 15 --retry-delay 5 --retry-connrefused http://localhost/explore - run: name: Generate docker build image cache diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 07ba61db..8f1c35ff 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,60 @@ -image: docker:dind +image: docker:18-git -deploy: +stages: + - build + +before_script: + - export VERSION=$(cat VERSION) + - export CI_REGISTRY=${CI_REGISTRY:-hub.docker.com} + - export CI_REGISTRY_USER=${CI_REGISTRY_USER:-gitlab-ci-token} + - export CI_REGISTRY_PASS=${CI_REGISTRY_PASS:-${CI_JOB_TOKEN}} + - export DOCKER_IMAGE=${DOCKER_IMAGE:-${CI_REGISTRY}/${CI_PROJECT_PATH}} + - | + if [ "${DOCKER_IMAGE}" = "/" ]; then + export DOCKER_IMAGE=sameersbn/gitlab + fi + +docker:build: + stage: build + only: + - master script: - - ci/gitlab + - docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASS} ${CI_REGISTRY} + - docker build + --pull + --cache-from=${DOCKER_IMAGE} + --build-arg=VCS_REF=$(git rev-parse --short HEAD) + --build-arg=BUILD_DATE="$(date +"%Y-%m-%d %H:%M:%S%:z")" + --build-arg=VERSION=${VERSION} + --tag ${DOCKER_IMAGE} . + - docker push ${DOCKER_IMAGE} + +docker:build:branches: + stage: build + only: + - branches + script: + - docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASS} ${CI_REGISTRY} + - docker build + --pull + --cache-from=${DOCKER_IMAGE}:${CI_COMMIT_REF_SLUG} + --build-arg=VCS_REF=$(git rev-parse --short HEAD) + --build-arg=BUILD_DATE="$(date +"%Y-%m-%d %H:%M:%S%:z")" + --build-arg=VERSION=${VERSION} + --tag ${DOCKER_IMAGE}:${CI_COMMIT_REF_SLUG} . + - docker push ${DOCKER_IMAGE}:${CI_COMMIT_REF_SLUG} + +docker:build:release: + stage: build + only: + - tags + script: + - docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASS} ${CI_REGISTRY} + - docker build + --pull + --cache-from=${DOCKER_IMAGE}:${VERSION} + --build-arg=VCS_REF=$(git rev-parse --short HEAD) + --build-arg=BUILD_DATE="$(date +"%Y-%m-%d %H:%M:%S%:z")" + --build-arg=VERSION=${VERSION} + --tag ${DOCKER_IMAGE}:${VERSION} . + - docker push ${DOCKER_IMAGE}:${VERSION} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..bd8fd424 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,12 @@ +# Gitlab-CI Configuration + +When using your own gitlab instance, the provided .gitlab-ci.yml will be automatically be using the settings provided by the Gitlab Instance. If needed several options can be overriden. + +Overrides for these values can be set within the project, under `Settings` -> `CI/CD` -> `Variables`. + +| Variable | Default Value | Description | +| ------------------ | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| `CI_REGISTRY` | `hub.docker.com` | If available this will be automatically overriden by registry address which is configured within the Gitlab instance | +| `CI_REGISTRY_USER` | `gitlab-ci-token` | Username for the registry | +| `CI_REGISTRY_PASS` | `${CI_JOB_TOKEN}` | Password for the registry | +| `DOCKER_IMAGE` | `sameersbn/gitlab` | Docker image name, will be automatically be overriden by the running Gitlab instance with the `${CI_PROJECT_PATH}` variable. This will case the image to be uploaded to the local registry of the project within Gitlab. | diff --git a/Dockerfile b/Dockerfile index ac7ea6e3..ba3d24e5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,21 @@ FROM ubuntu:xenial-20181005 -LABEL maintainer="sameer@damagehead.com" +ARG BUILD_DATE +ARG VCS_REF +ARG VERSION=11.4.5 -ENV GITLAB_VERSION=11.4.5 \ +LABEL \ + maintainer="sameer@damagehead.com" \ + org.label-schema.schema-version="1.0" \ + org.label-schema.build-date=${BUILD_DATE} \ + org.label-schema.name=gitlab \ + org.label-schema.vendor=damagehead \ + org.label-schema.url="https://github.com/sameersbn/docker-gitlab" \ + org.label-schema.vcs-url="https://github.com/sameersbn/docker-gitlab.git" \ + org.label-schema.vcs-ref=${VCS_REF} \ + com.damagehead.gitlab.license=MIT + +ENV GITLAB_VERSION=${VERSION} \ RUBY_VERSION=2.4 \ GOLANG_VERSION=1.10.4 \ GITLAB_SHELL_VERSION=8.3.3 \ diff --git a/ci/gitlab b/ci/gitlab deleted file mode 100755 index 1b8736d5..00000000 --- a/ci/gitlab +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh - -set -e - -VERSION=$(cat VERSION) -DOCKER_REGISTRY_HOST=${DOCKER_REGISTRY_HOST:-hub.docker.com} -DOCKER_IMAGE=${DOCKER_IMAGE:-sameersbn/gitlab} - -docker build -t $DOCKER_IMAGE . - -docker tag $DOCKER_IMAGE $DOCKER_REGISTRY_HOST/$DOCKER_IMAGE:latest -docker tag $DOCKER_IMAGE $DOCKER_REGISTRY_HOST/$DOCKER_IMAGE:$VERSION - -docker push $DOCKER_REGISTRY_HOST/$DOCKER_IMAGE:latest -docker push $DOCKER_REGISTRY_HOST/$DOCKER_IMAGE:$VERSION diff --git a/hooks/build b/hooks/build new file mode 100644 index 00000000..e0e2f7bc --- /dev/null +++ b/hooks/build @@ -0,0 +1,12 @@ +!/bin/bash + +# Docker Daemon Build Hook +# $IMAGE_NAME var is injected into the build so the tag is correct. + +docker build \ + --pull \ + --cache-from=${IMAGE_NAME} \ + --build-arg=BUILD_DATE="$(date +"%Y-%m-%d %H:%M:%S%:z")" \ + --build-arg=VCS_REF=$(git rev-parse --short HEAD) \ + --build-arg=VERSION=$(cat VERSION) \ + -t ${IMAGE_NAME} .