I am trying to create a correct .gitlab-ci.yml file. This is for the online gitlab.com not for a self hosted Gitlab. Most (if not all) documentation is about a self hosted gitlab instance.
What I want is to run my Mocha-Chai tests on the built container and when the tests pass I want to build an image and store it in the Gitlab Registry with a tag that matches my latest git tag.
Test part
I cannot get the tests running, whatever I try I always get Mocha not found.
Below is my .yml file. The build section is working. The problem is in the test section and in the docker tag part of the release-image. I got the yml file from the official gitlab documentation the official gitlab documentation
image: docker:latest
services:
- docker:dind
stages:
- build
- test
- release
- deploy
variables:
CONTAINER_TEST_IMAGE: registry.gitlab.com/edelacruz/cloudtrader-microservices:$CI_COMMIT_REF_NAME
CONTAINER_RELEASE_IMAGE: registry.gitlab.com/edelacruz/cloudtrader-microservices:latest
before_script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN registry.gitlab.com/edelacruz/cloudtrader-microservices
build:
stage: build
script:
- docker build --pull -t $CONTAINER_TEST_IMAGE .
- docker push $CONTAINER_TEST_IMAGE
test:
stage: test
script:
- docker pull $CONTAINER_TEST_IMAGE
- docker run $CONTAINER_TEST_IMAGE npm install && npm test
I also tried
test:
stage: test
script:
- docker pull $CONTAINER_TEST_IMAGE
- docker run $CONTAINER_TEST_IMAGE npm test
and
test:
stage: test
script:
- docker pull $CONTAINER_TEST_IMAGE
- docker run $CONTAINER_TEST_IMAGE npm install mocha -g
- docker run $CONTAINER_TEST_IMAGE npm install chai -g
- docker run $CONTAINER_TEST_IMAGE npm test
all the the same result:
sh: mocha: not found
the test script in package.json is
"test": "mocha ./Test",
I tried both putting mocha and chai in the devDependencies and in dependencies.
"devDependencies": {
"chai": "^4.0.2",
"mocha": "^3.4.2"
}
"dependencies": {
"chai": "^4.0.2",
"mocha": "^3.4.2"
},
Tag part
variables:
CONTAINER_TEST_IMAGE: registry.gitlab.com/edelacruz/cloudtrader-microservices:$CI_COMMIT_REF_NAME
CONTAINER_RELEASE_IMAGE: registry.gitlab.com/edelacruz/cloudtrader-microservices:latest
before_script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN registry.gitlab.com/edelacruz/cloudtrader-microservices
release-image:
stage: release
script:
- docker pull $CONTAINER_TEST_IMAGE
- docker tag $CONTAINER_TEST_IMAGE $CONTAINER_RELEASE_IMAGE:$CI_COMMIT_TAG
- docker push $CONTAINER_RELEASE_IMAGE
only:
- master
The release-image works if I leave out the tag part. But I really want to have my image tagged with the git tag, not with latests or master.
$ docker tag $CONTAINER_TEST_IMAGE $CONTAINER_RELEASE_IMAGE:$CI_COMMIT_TAG Error parsing reference: "registry.gitlab.com/edelacruz/cloudtrader-microservices:" is not a valid repository/tag: invalid reference format ERROR: Job failed: exit code 1
