Source
(317) GitLab CI CD Tutorial for Beginners [Crash Course] - YouTube
.gitlab-ci.yml · main · Nana Janashia / gitlab-cicd-crash-course · GitLab
Main idea:
1. .gitlab-ci.yml will host the classical 3 stages which are
a. test
b. build
c. deploy
2. build will use a docker image and service to build and push the docker image to docker hub
3. deploy will ssh to the target machine, kill existing docker image, run the specific docker image
variables:
IMAGE_NAME: nanajanashia/demo-app
IMAGE_TAG: python-app-1.0
stages:
- test
- build
- deploy
run_tests:
stage: test
image: python:3.9-slim-buster
before_script:
- apt-get update && apt-get install make
script:
- make test
build_image:
stage: build
image: docker:20.10.16
services:
- docker:20.10.16-dind
variables:
DOCKER_TLS_CERTDIR: "/certs"
before_script:
- docker login -u $REGISTRY_USER -p $REGISTRY_PASS
script:
- docker build -t $IMAGE_NAME:$IMAGE_TAG .
- docker push $IMAGE_NAME:$IMAGE_TAG
deploy:
stage: deploy
before_script:
- chmod 400 $SSH_KEY
script:
- ssh -o StrictHostKeyChecking=no -i $SSH_KEY root@161.35.223.117 "
docker login -u $REGISTRY_USER -p $REGISTRY_PASS &&
docker ps -aq | xargs docker stop | xargs docker rm &&
docker run -d -p 5000:5000 $IMAGE_NAME:$IMAGE_TAG"
No comments:
Post a Comment