templates/tpl/docker-build.yml
Frank Villaro-Dixon 0be2082ab8 poc v1
2022-02-27 17:36:00 +01:00

50 lines
1.8 KiB
YAML

variables:
DOCKERFILE_LOCATION: '.'
DOCKERFILE_NAME: 'Dockerfile'
dockerfile_lint:
stage: .pre
tags:
- docker-runner
image: hadolint/hadolint:latest-debian
allow_failure: true
before_script:
- 'cd $DOCKERFILE_LOCATION'
script:
- hadolint --ignore DL3008 --ignore DL3059 $DOCKERFILE_NAME
.docker_build:
stage: build
tags:
- docker-build
variables:
GIT_SUBMODULE_STRATEGY: recursive
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
docker-build-tags:
extends: .docker_build
script:
- docker build --pull --build-arg CACHEBUST=$(date +%s) --build-arg CI_COMMIT_SHORT_SHA=$CI_COMMIT_SHORT_SHA -t "$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG" -f $DOCKERFILE_LOCATION/$DOCKERFILE_NAME $DOCKERFILE_LOCATION
- docker push "$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG"
# Below is a nasty hack to also publish registry/xxxx/master:TAG
# because else it's a shit show do deal with it on helm releases
- docker tag "$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG" "$CI_REGISTRY_IMAGE/master:$CI_COMMIT_TAG"
- docker push "$CI_REGISTRY_IMAGE/master:$CI_COMMIT_TAG"
- docker tag "$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG" "$CI_REGISTRY_IMAGE/main:$CI_COMMIT_TAG"
- docker push "$CI_REGISTRY_IMAGE/main:$CI_COMMIT_TAG"
only:
- tags
docker-build:
extends: .docker_build
script:
- docker build --pull --build-arg CACHEBUST=$(date +%s) --build-arg CI_COMMIT_SHORT_SHA=$CI_COMMIT_SHORT_SHA -t "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_NAME:$CI_COMMIT_SHORT_SHA" -f $DOCKERFILE_LOCATION/$DOCKERFILE_NAME $DOCKERFILE_LOCATION
- docker push "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_NAME:$CI_COMMIT_SHORT_SHA"
- docker tag $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_NAME:$CI_COMMIT_SHORT_SHA $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_NAME:latest
- docker push "$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_NAME:latest"
except:
- tags