image: jsrjsr0040/centos-apm-ssh
variables:
STAGING_SERVER: 123.123.123.123
DEPLOY_SERVER: 123.123.123.123
STAGING_TAGS: 'staging-'
DEPLOY_TAGS: 'real-'
GITID: 'gitid'
GITPASS: 'gitpath'
stages:
- build
- test
- deploy
before_script:
- echo "Before Script"
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- eval $(ssh-agent -s)
- echo "$SSH_KEY"| ssh-add -
- ssh-keyscan -p 9022 $STAGING_SERVER > ~/.ssh/known_hosts
- ssh-keyscan -p 9122 $DEPLOY_SERVER > ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- '[[ -f /.dockerenv ]] \
&& echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
MyBuild:
stage: build
script:
- echo "Do Build"
MyTest:
stage: test
script:
- echo "Do Test"
Staging:
stage: deploy
script:
- LATEST=$(git describe --tags --abbrev=0 --match $STAGING_TAGS'*')
- echo $LATEST
- ssh -tt root@$STAGING_SERVER -p 9022 "mkdir -p ~/.ssh \
&& echo -e '$SSH_KEY' | tr -d '\r' > ~/.ssh/id_rsa \
&& chmod 600 ~/.ssh/id_rsa \
&& [[ ! -d $HOME_PATH/$LATEST ]] \
&& cd $HOME_PATH
&& git clone -b $LATEST git@gitlab.com/[group]/[repository].git $LATEST \
|| echo 'Exists' \
&& rm -rf html \
&& ln -s $HOME_PATH/$LATEST html"
environment:
name: staging
url: https://staging.gitlab.com
when: manual
only:
- /^staging-.*$/
except:
- branches
Deploy:stage: deployscript:- LATEST=$(git describe --tags --abbrev=0 --match $DEPLOY_TAGS'*')- echo $LATEST- ssh -tt root@$DEPLOY_SERVER -p 9122 "mkdir -p ~/.ssh \&& echo -e '$SSH_KEY' | tr -d '\r' > ~/.ssh/id_rsa \&& chmod 600 ~/.ssh/id_rsa \&& [[ ! -d $HOME_PATH/$LATEST ]] \&& cd $HOME_PATH&& git clone -b $LATEST git@gitlab.com/[group]/[repository].git $LATEST \|| echo 'Exists' \&& rm -rf html && ln -s $HOME_PATH/$LATEST html"environment:name: deployurl: https://www.gitlab.comwhen: manualonly:- /^real-.*$/except:- branches
기본적인 배포 시스템에 사용해줄 yml 설정 파일.
SSH_KEY와 HOME_PATH 의 경우 gitlab CI/CD setting에서 변수로 추가해줬음.
SSH_KEY의 경우 private key를 넣어줌.
사전에 배포하려는 서버의 authorized_key에 public key가 추가된 상태임.
'Develop > GitLab' 카테고리의 다른 글
Make runner jobs with another job (0) | 2018.04.20 |
---|---|
GitLab Runner (0) | 2018.01.08 |
GitLab 간편 설치하기 (0) | 2018.01.08 |