augdog97
augdog97

Reputation: 267

Gitlab CI/CD pipeline giving Dockerfile error

Good Evening, I am trying to deploy my nodeJS app to my Digital Ocean Server and its saying it cant find my Dockerfile. I did check and the Dockerfile does not have a .txt extension. Any guidance is appreciated. I have my variables set in my Gitlab project. The pipeline throws the below error: "$ chmod og= $ID_RSA chmod: unrecognized option: ---BEGIN BusyBox v1.31.1 () multi-call binary. Usage: chmod [-Rcvf] MODE[,MODE]... FILE... Each MODE is one or more of the letters ugoa, one of the symbols +-= and one or more of the letters rwxst -R Recurse -c List changed files -v List all files -f Hide errors"

stages:
  - build
  - publish
  - deploy

variables:
  TAG_LATEST: $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_NAME:latest
  TAG_COMMIT: $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_NAME:$CI_COMMIT_SHORT_SHA

build:
  image: node:latest
  stage: build
  script:
    - npm install
    - echo   "ACCOUNT_SID=$ACCOUNT_SID" >> .env
    - echo   "AUTH_TOKEN=$AUTH_TOKEN" >> .env
    - echo   "API_KEY=$API_KEY" >> .env
    - echo   "API_SECRET=$API_SECRET" >> .env
    - echo   "PHONE_NUMBER=$PHONE_NUMBER" >> .env
    - echo    "sengrid_api=$sengrid_api" >> .env

publish:
  image: docker:latest
  stage: publish
  services:
    - docker:dind
  script:
    - docker build . -t $TAG_COMMIT -t $TAG_LATEST 
    - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
    - docker push $TAG_COMMIT
    - docker push $TAG_LATEST

deploy:
  image: alpine:latest
  stage: deploy
  tags:
    - deployment
  script:
    - chmod og= $ID_RSA
    - apk update && apk add openssh-client
    - ssh -i $ID_RSA -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP "docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY"
    - ssh -i $ID_RSA -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP "docker pull $TAG_COMMIT"
    - ssh -i $ID_RSA -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP "docker container rm -f my-app || true"
    - ssh -i $ID_RSA -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP "docker run -d -p 80:3000 --name my-app $TAG_COMMIT"
  environment:
    name: production
    url: http://167.172.225.124
  only:
    - master

Upvotes: 11

Views: 6590

Answers (4)

Germán Martinez
Germán Martinez

Reputation: 76

Make sure your ID_RSA variable is Type: file

Upvotes: 5

Romain TAILLANDIER
Romain TAILLANDIER

Reputation: 1995

If you have followed this tutorial as I do (which looks to be the case), It looks the tutorial assumes to run on the master branch, protected.

I was running on another branch not protected. So I had to unprotect all variables to work on unprotected branches. The job succeeds immediately.

Upvotes: 11

Sultan Zhumatayev
Sultan Zhumatayev

Reputation: 555

chmod og= $ID_RSA 

For me it didn't work because i copied key without breakline symbol in the end ,it turned out that is important. Tried many solutions, spent almost a day before i got this /.

Upvotes: 1

VonC
VonC

Reputation: 1324337

Check first if the docker build argument order is correct:

Instead of:

docker build -t $TAG_COMMIT -t $TAG_LATEST .

I would try:

docker build . -t $TAG_COMMIT -t $TAG_LATEST

Check also you are in the right path when you are running this build command.
And that there is a file named Dockerfile (the default name needed by docker build).


Regarding the error:

chmod og= $ID_RSA 
chmod: unrecognized option: ---BEGIN

You need to apply chmod on a file, not on a file content.
The variable ID_RSA includes the key itself, not the key filename.

Use ~/.ssh/id_rsa instead of $ID_RSA.

Upvotes: 4

Related Questions