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/
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
'[AWS] > GITLAB' 카테고리의 다른 글
sed 명령어 (0) | 2022.03.02 |
---|---|
65장. Assignment solution (오류 해결) (0) | 2022.03.02 |
63장. AWS CLI를 사용하여 AWS Elastic Beanstalk에 Java 애플리케이션을 배포하는 방법 (0) | 2022.03.02 |
62장. GitLab CI에서 AWS S3로 파일을 업로드하는 방법 (0) | 2022.03.01 |
[AWS] GitLab CICD Pipelines with AWS EC2 and S3 (0) | 2022.02.28 |
댓글