Created
April 11, 2022 06:51
-
-
Save sajjadG/49bb0795b288b8b05cd10d5a18e0185c to your computer and use it in GitHub Desktop.
.gitlab-ci.yml example1
This file contains 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:19.03.12 | |
# services: | |
# - docker:19.03.12-dind | |
variables: | |
# DOCKER_DRIVER: overlay2 | |
# DOCKER_TLS_CERTDIR: "" | |
PROJECT_NAME: my-project | |
stages: | |
- build | |
- deploy | |
######################################################################### | |
build_staging: | |
stage: build | |
variables: | |
IMAGE_NAME: "registry.mysite.com/sajjadg/${PROJECT_NAME}_snapshot" | |
script: | |
- now=$(date '+%Y-%m-%d-%H-%M') | |
- echo "$DOCKER_REGISTRY_PASS" | docker login $DOCKER_REGISTRY --username $DOCKER_REGISTRY_USER --password-stdin | |
- docker build -t $IMAGE_NAME:$now -t $IMAGE_NAME:latest . | |
- docker push $IMAGE_NAME | |
only: | |
- test | |
tags: | |
- staging | |
deploy_staging: | |
stage: deploy | |
before_script: | |
- eval $(ssh-agent -s) | |
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > /etc/ssh/ssh_config' | |
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null | |
script: | |
- ssh -p $STAGING_SERVER_PORT $STAGING_SERVER_IP -l $STAGING_SERVER_USER "cd /srv/$PROJECT_NAME;/usr/bin/docker-compose up -d;sleep 5;/usr/bin/docker-compose ps" | |
only: | |
- test | |
tags: | |
- staging | |
######################################################################### | |
build_prod: | |
stage: build | |
variables: | |
IMAGE_NAME: "sajjadg/${PROJECT_NAME}" | |
script: | |
- now=$(date '+%Y-%m-%d-%H-%M') | |
- echo "$DOCKER_REGISTRY_PASS" | docker login $DOCKER_REGISTRY --username $DOCKER_REGISTRY_USER --password-stdin | |
- docker build -t $IMAGE_NAME:$now -t $IMAGE_NAME:latest . | |
- docker push $IMAGE_NAME | |
only: | |
- master | |
tags: | |
- builder-runner | |
deploy_prod: | |
stage: deploy | |
script: | |
- cd /srv/$PROJECT_NAME;/usr/bin/docker-compose up -d;/usr/bin/docker-compose ps | |
only: | |
- master | |
tags: | |
- shell-runner-prod | |
when: manual |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment