-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
27 lines (26 loc) · 907 Bytes
/
Copy path.gitlab-ci.yml
File metadata and controls
27 lines (26 loc) · 907 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
docker-build:
# Use the official docker image.
image: docker:cli
stage: build
services:
- docker:dind
variables:
DOCKER_IMAGE_NAME: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
LATEST_IMAGE_NAME: $CI_REGISTRY_IMAGE:latest
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
# Build and push the Docker image only if a tag is pushed
script:
- docker build --pull -t "$DOCKER_IMAGE_NAME" .
- docker push "$DOCKER_IMAGE_NAME"
- |
if [[ -n "$CI_COMMIT_TAG" ]]; then
docker tag "$DOCKER_IMAGE_NAME" "$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG"
docker push "$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG"
# Update the latest tag
docker tag "$DOCKER_IMAGE_NAME" "$LATEST_IMAGE_NAME"
docker push "$LATEST_IMAGE_NAME"
fi
# Run this job only if a tag is present
rules:
- if: $CI_COMMIT_TAG