0

I have installes gitlab-runner on my staging-server and in my project I have this gitlab-ci.yml:

image: upmcedlp/gitlab-dind-node-java

services:
  - docker:dind

stages:
  - ver
  - init
  - tests
  - deploy

before_script:    
  - echo "---------- DOCKER LOGIN"      
  - docker login -u myusername -p "mypwd" registry.gitlab.com 

ver:
  stage: ver
  script:    
    - whoami

init:
  stage: init
  script:
- npm install

testing:
  stage: tests
  script:
    - npm test

deploy_staging:
  stage: deploy
  script:
    - echo "---------- START DEPLOYING STAGING SERVER"
    - echo "-> 1) build image"  
    - docker build -t registry.gitlab.com/admiralcrunch/portal_ci .
    - echo "-> 2) push image to registry"
    - docker push registry.gitlab.com/admiralcrunch/portal_ci          
    - echo "-> 3) kill old container"
    - docker kill $(docker ps -q) || true
    - docker rm $(docker ps -a -q) || true
    - echo "-> 4) start new container"
    - docker run -dt -p 3000:3000 --name portal registry.gitlab.com/admiralcrunch/portal_ci
    - echo "########## END DEPLOYING DOCKER IMAGE"
  environment:
    name: staging
    url: https://stage.latronic.com
  only:
    - master

deploy_production_1:
  stage: deploy
  script:
    - echo "Deployed to production server 1"
  environment:
  when: manual
  only:
    - master

deploy_production_2:
  stage: deploy
  script:
    - echo "Deployed to production server 2"
  environment:
  when: manual
  only:
    - master    

It is running and I can see how - in the deploy_staging the processes got killed and the docker run -dt -p 3000:3000 --name portal admiralcrunch/portal_ci gots executed without no error. Also I can see the "worker"-container that the gitlab-runner creates on the staging-server.

but when all is finished, there is absolutely no container running(?). Why is that? What am I doing wrong? did I miss sometging?

CaptnHirni
  • 137
  • 3
  • 12
  • What kind of runner are you using? – Mihai May 03 '19 at 07:03
  • what do you mean by "kind" ? I didn't know there is a number of them? oO .. I installed gitlab-runner via apt and registered it (I chose docker as executor, you mean this?) – CaptnHirni May 03 '19 at 07:11
  • yes, you should use a "shell" gitlab-runner. Create a runner with executor shell and tag it as "shell". Then in your pipeline for job deploy_stagging mention the tag shell so that the runner can pickup this job. If you still have issues let me know – Mihai May 03 '19 at 07:22
  • now i can't login to docker. I get a `WARNING! Using --password via the CLI is insecure. Use --password-stdin. Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.39/auth: dial unix /var/run/docker.sock: connect: permission denied` .. when I change the login-line in the gitlab-ci.yaml to `echo | set /p="mypassword" | docker login --username mylogin --password-stdin`, I get a `Error: Cannot perform an interactive login from a non TTY device` – CaptnHirni May 03 '19 at 07:52
  • It is better to set 2 environment variables: DOCKER_PASSWORD and DOCKER_USER in your environment. Then use those on the command line: docker login -u $DOCKER_USER -p $DOCKER_PASSWORD – Mihai May 03 '19 at 08:02
  • This answer might be of some help: https://stackoverflow.com/a/50684269/7786148 – gcharbon May 03 '19 at 08:30
  • @Mihai.. yes, but that does not solve my problem. I got the login now working, but `npm install` now makes errors. I changed it to `sudo apt-get update -qy` but with no effort. – CaptnHirni May 03 '19 at 10:01
  • @gcharbon ,, thanks fpr the link,... I already have those steps running, the only thing is, that the command `docker run... ` is beeing executed but no running container appears on stage-server – CaptnHirni May 03 '19 at 10:03
  • @CaptnHirni It looks to me that now you are running everything in the shell executor. Please make sure to use the TAG so that you only use the shell executor for the deploy job. All the other ones should run as before. Because of that there should be no influence between the jobs – Mihai May 03 '19 at 10:47
  • @Minhai Another way to use docker in gitlab-ci is to set a known private SSH key as CI secret in Gitlab (let's say `PRIVATE_SSH_KEY`), and then start a container with `docker:latest`. Define `DOCKER_HOST` environment variable to `ssh://@` and run `echo "$PRIVATE_SSH_KEY" > ~/.ssh/id_rsa`. You can now run `docker run` command against your remote docker daemon assuming your key is authorized. We use this for CD, and we keep using docker executors with `docker:dind` service for CI (but this needs mounting the `/var/run/docker.socket` file into our gitlab-runner container – gcharbon May 03 '19 at 12:03
  • Thanks to both of you I got it somehow working now :D .. the key was in fact to seperate the jobs which the docker- and the shell-executor run. – CaptnHirni May 04 '19 at 00:25

0 Answers0