A
A
Aristarchus2019-07-21 00:44:53
Debian
Aristarchus, 2019-07-21 00:44:53

.gitlab-ci.yml and trouble with it .?

Hello.
I got tired of trying to adequately configure .gitlab-ci.yml (I googled everything I could)
I configured SSH keys, I did everything, I configured everything and it remains to configure this file.
You need to delete all files from /home/webserver and upload new ones there during the deployment process ( CI / CD)
How many tried to configure - fails

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Edward, 2019-07-21
@kalter1808

Let's say your runner is set to default. In this case, building in docker containers is used. About other executors here: https://docs.gitlab.com/runner/#selecting-the-executor

stages:
  - deploy

deploy_master:
  image: alpine
  stage: deploy  
  script:
    - apk update && apk upgrade
    - apk add openssh bash rsync
    - echo "====== Deploy to production server ======"
    - echo "====== Add target servers secret key ======"
    - mkdir ~/.ssh
    - echo $TARGET_SERVER_SECRET_KEY > ~/.ssh/id_rsa
    - chmod 700 ~/.ssh && chmod 600 ~/.ssh/*
    - echo "====== Test ssh connection ======"
    - ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -T "[email protected]_server"
    - echo "====== Sync local and remote directory ======"
    - rsync -av -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --delete ./ "[email protected]_server:/home/webserver/"

only:
  - master

For this to work, in the CI / CD settings in gitlab, you need to set the TARGET_SERVER_SECRET_KEY variable, writing your full private ssh key into it

K
ky0, 2019-07-21
@ky0

Something like this:

stages:
 - build

build:
    stage: build
    script:
- rm -rf /home/webserver/*
- cp -r * /home/webserver/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question