본문 바로가기
[AWS]/GITLAB

15: GitLab CI Deploy to Remote Server over SSH

by SAMSUNG CLOUD-OKY 2022. 3. 4.
반응형

 

15:GitLab CI Deploy to Remote Server over SSH |Deploy Code to AWS EC2 Instance using SSH with GitLab

 
 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

https://www.fosstechnix.com/gitlab-ci-deploy-to-ec2-using-ssh/

 

GitLab CI Deploy to EC2 using SSH

GitLab CI Deploy to EC2 using SSH | GitLab CI Deploy to Remote Server | Deploy Code to AWS EC2 Instance using SSH with GitLab CI/CD Pipeline

www.fosstechnix.com

 

stages:
- deploy
#In this we have only one stage deploy
Deploy:
stage: deploy
before_script:
- command -v ssh-agent >/dev/null || ( apk add --update openssh )'
#The ssh-agent command outputs commands to set ce - cp -r * .public
rtain environment variables in the shell
- eval $(ssh-agent -s)
#The eval command tells the shell to run the output of ssh-agent as shell commands
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
#"$SSH_PRIVATE_KEY" in this we added private key in variable
- mkdir -p ~/.ssh
#create a directory
- chmod 700 ~/.ssh
# usually the tools which use that directory will ask you to assign permissions to it:
- ssh-keyscan $EC2_IPADDRESS >> ~/.ssh/known_hosts
#"$EC2_IPADDRESS" in this we added our instance ip_address in variable
- chmod 644 ~/.ssh/known_hosts
#this is key file permission
script:
- mkdir .public
#create public directory
- cp -r * .public
- mv .public public
- zip -r public.zip public
- scp -o StrictHostKeyChecking=no public.zip ubuntu@3.108.55.172:/var/www/html
- ssh -o StrictHostKeyChecking=no ubuntu@3.108.55.172 "cd /var/www/html; touch foo.txt; unzip public.zip"
#fristly you need to inside /var/www/html/ this file
#with touch command create foo.txt and unzip public.zip

 

 

 

 

 

 

 

 

 

 

https://www.youtube.com/watch?v=mFHnaTZUQgA 

 

 

반응형

댓글