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 [email protected]$SERVER_IP "docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY"
    - ssh -i $ID_RSA -o StrictHostKeyChecking=no [email protected]$SERVER_IP "docker pull $TAG_COMMIT"
    - ssh -i $ID_RSA -o StrictHostKeyChecking=no [email protected]$SERVER_IP "docker container rm -f my-app || true"
    - ssh -i $ID_RSA -o StrictHostKeyChecking=no [email protected]$SERVER_IP "docker run -d -p 80:3000 --name my-app $TAG_COMMIT"
  environment:
    name: production
    url: http://167.172.225.124
  only:
    - master

Answer

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.

Leave a Reply

Your email address will not be published. Required fields are marked *