Exemple de fichier .gitlab-ci.yml
https://gitlab.com/tonytdj/helloworld
image: docker:latest
services:
- name: docker:dind
alias: docker
stages:
- Build image
- Test image
- Release image
build:
# Official docker image.
stage: Build image
script:
- docker build -t alpinehelloworld .
- docker save alpinehelloworld > alpinehelloworld.tar
artifacts:
paths:
- alpinehelloworld.tar
test image:
# Official docker image.
stage: Test image
script:
- docker load < alpinehelloworld.tar
- docker run -d -p 80:5000 -e PORT=5000 --name webapp alpinehelloworld
- sleep 5
- apk --no-cache add curl
- curl "http://docker" | grep -q "Hello world!"
release image:
stage: Release image
script:
- docker load < alpinehelloworld.tar
- docker tag alpinehelloworld "${IMAGE_NAME}:${CI_COMMIT_REF_NAME}"
- docker tag alpinehelloworld "${IMAGE_NAME}:${CI_COMMIT_SHORT_SHA}"
- docker login -u $CI_DEPLOY_USER -p $CI_DEPLOY_PASSWORD $CI_REGISTRY
- docker push "${IMAGE_NAME}:${CI_COMMIT_REF_NAME}"
- docker push "${IMAGE_NAME}:${CI_COMMIT_SHORT_SHA}"
https://gitlab.com/tonytdj/helloworld/-/settings/ci_cd
CI_DEPLOY_USER : la variable est a créé
CI_DEPLOY_PASSWORD : la variable est a créé et correspond au token (et non au mot de passe)