CV/.gitlab/ci/docker-gitlab-ci.yml
Dan Anglin 84b29f0467
feat: build the magefile into a binary
This commit builds the magefile into a binary during the docker build
stage.
The Dockerfile is updated to include a multi-stage build where the first
stage compiles the binary and the second stage builds the final
cv-builder image.
The final image is now based on debian:buster instead of
golang:<VERSION>-buster which significantly reduces the image's size.
2020-09-13 22:50:17 +01:00

66 lines
1.6 KiB
YAML

---
#--------------------------------------------------------#
# Hidden job templates for Docker build/publish pipeline #
#--------------------------------------------------------#
.docker-build-setup:
image: docker:19.03.12
services:
- docker:19.03.12-dind
before_script:
- apk add --no-cache go
.dockerfile-lint:
stage: test
image: hadolint/hadolint:v1.18.0-alpine
script:
- "hadolint docker/Dockerfile"
.dockerbuild-test:
stage: test
extends: .docker-build-setup
.docker-test-rules:
rules:
- changes:
- "docker/Dockerfile"
- "*.go"
when: always
- if: '$CI_COMMIT_REF_NAME =~ /^[0-9]{4}(.[0-9]{2}){2}$/'
when: never
.docker-publish-pre-post:
stage: publish
extends: .docker-build-setup
before_script:
- apk add --no-cache go
- docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY}
after_script:
- docker logout ${CI_REGISTRY}
.docker-publish-rules:
rules:
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PROJECT_PATH == "dananglin/cv" && $CI_PIPELINE_SOURCE == "web" && $BUILD_DOCKER_IMAGE == "true"'
when: always
#------------------------------------------------#
# Visible jobs for Docker build/publish pipeline #
#------------------------------------------------#
test:dockerfile:lint:
extends:
- .dockerfile-lint
- .docker-test-rules
test:docker:build:
extends:
- .dockerbuild-test
- .docker-test-rules
script:
- go run mage.go image
publish:docker-image:
extends:
- .docker-publish-pre-post
- .docker-publish-rules
script:
- go run mage.go publishImage