Last active
February 21, 2018 20:28
-
-
Save ronalddddd/d402ec6f81647ab3db651136997a7a74 to your computer and use it in GitHub Desktop.
Template .gitlab-ci.yml for automating docker image build, test, release
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
image: docker:1.11.2-git | |
stages: | |
- build | |
- test | |
- release | |
#- deploy | |
variables: | |
CONTAINER_IMAGE_NAME: myImage | |
CONTAINER_REGISTRY_NAMESPACE: myNamespace | |
CONTAINER_REGISTRY_DOMAIN: registry.gitlab.com | |
CONTAINER_RELEASE_IMAGE: $CONTAINER_REGISTRY_DOMAIN/$CONTAINER_REGISTRY_NAMESPACE/$CONTAINER_IMAGE_NAME:latest | |
before_script: | |
# Generate the test image tag from branch name, e.g. | |
# branch `feature/amazeballs-thing` becomes the docker image tag `feature-amazeballs-thing` | |
- CONTAINER_TEST_IMAGE=$CONTAINER_REGISTRY_DOMAIN/$CONTAINER_REGISTRY_NAMESPACE/$CONTAINER_IMAGE_NAME:`echo $CI_BUILD_REF_NAME | sed -e 's/[\/|.]/-/g'` | |
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CONTAINER_REGISTRY_DOMAIN | |
build: | |
stage: build | |
script: | |
# optional meta data to shove into your app image | |
- echo $CI_BUILD_REF > ./meta/hash | |
- echo $CI_BUILD_REF_NAME > ./meta/branch | |
# builds and push the test image | |
- docker build -t $CONTAINER_TEST_IMAGE . | |
- docker push $CONTAINER_TEST_IMAGE | |
test: | |
stage: test | |
script: | |
# your CI test script -- exit 0 for success or exit > 0 for failure, optionally output coverage info here | |
- ./scripts/test.sh $CONTAINER_TEST_IMAGE | |
release-image: | |
stage: release | |
script: | |
# finally, if this is the master branch, tag and push the image to `latest` | |
- docker pull $CONTAINER_TEST_IMAGE | |
- docker tag $CONTAINER_TEST_IMAGE $CONTAINER_RELEASE_IMAGE | |
- docker push $CONTAINER_RELEASE_IMAGE | |
only: | |
- master | |
#deploy: | |
# stage: deploy | |
# script: | |
# - echo "deploy script should run here..." | |
## - ./deploy.sh | |
# only: | |
# - master |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment