Skip to content

Instantly share code, notes, and snippets.

@m4nu56

m4nu56/.gitlab-ci.yml

Last active Nov 11, 2019
Embed
What would you like to do?
image: docker:19.03.1
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_DRIVER: overlay2
PROJECT_IMAGE: registry.domain.com/project-name
PROJECT_RELEASE_IMAGE: $PROJECT_IMAGE:$CI_COMMIT_REF_NAME
DOCKER_TLS_CERTDIR: ""
services:
- docker:19.03.1-dind
before_script:
# login sur le docker registry
- echo "$CI_JOB_TOKEN" | docker login -u gitlab-ci-token --password-stdin registry.domain.com
stages:
- test
- release
test:
stage: test
script:
# création d'un network pour lier mongo et nodejs
- docker network rm network-project || true && docker network create network-project*
# init et run du container mongo
- docker run -d --name mongo-db --network network-project -v /builds/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js -e MONGO_INITDB_DATABASE='project' -e MONGO_INITDB_ROOT_USERNAME='root' -e MONGO_INITDB_ROOT_PASSWORD='root' mongo:4.0
# build de l'image node (les sources sont copiées et npm install est fait)
- docker build --pull --network network-project -t $PROJECT_RELEASE_IMAGE node/
# démarrage du container avec les variables d'environnement de la ci
- docker run -d --env-file node/.env_tests --network network-project --name nodejs_test $PROJECT_RELEASE_IMAGE
# exécution des tests
- docker exec nodejs_test npm test
# cleanup kill containers and network
- docker stop nodejs_test && docker rm nodejs_test
- docker stop mongo-db || true
- docker network rm network-project
release:
stage: release
script:
# build de l'image
- docker build --pull -t $PROJECT_RELEASE_IMAGE node/
# déploiement de l'image sur le repository
- docker push $PROJECT_RELEASE_IMAGE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.