Created
January 7, 2026 04:31
-
-
Save Nurlan199206/90d054b3436005de1b89e501d02dd0b4 to your computer and use it in GitHub Desktop.
Docker + SSH deploy gitlab
This file contains hidden or 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
| variables: | |
| # GIT_STRATEGY: clone | |
| SRV: '8111111' | |
| PORT: '22022' | |
| image: docker:stable | |
| stages: | |
| - dockerize | |
| - deploy | |
| before_script: | |
| - export TAG="$CI_PIPELINE_ID-$CI_COMMIT_SHORT_SHA" | |
| docker-build: | |
| stage: dockerize | |
| image: docker:29.0.0 | |
| when: on_success | |
| tags: [crocos-docker] | |
| script: | |
| - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY | |
| - docker build -t $CI_REGISTRY_IMAGE:$TAG . | |
| - docker push $CI_REGISTRY_IMAGE:$TAG | |
| - docker rmi $CI_REGISTRY_IMAGE:$TAG | |
| deploy-prod: | |
| stage: deploy | |
| tags: | |
| - shell | |
| before_script: | |
| - 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )' | |
| - eval $(ssh-agent -s) | |
| - echo "$PRIVATE_KEY" | tr -d '\r' | ssh-add - | |
| - mkdir -p ~/.ssh | |
| - chmod 700 ~/.ssh | |
| - echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config | |
| - export TAG="$CI_PIPELINE_ID-$CI_COMMIT_SHORT_SHA" | |
| script: | |
| - ssh -p$PORT -tt crocos@$SRV "docker pull $CI_REGISTRY_IMAGE:$TAG" | |
| - ssh -p$PORT -tt crocos@$SRV "docker stop res2026-prod" || true | |
| - ssh -p$PORT -tt crocos@$SRV "docker rm res2026-prod" || true | |
| - ssh -p$PORT -tt crocos@$SRV "docker run -d --name res2026-prod --network http_default $CI_REGISTRY_IMAGE:$TAG" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment