[英]SSH error when trying to deploy to Digital Ocean via Gitlab CI/CD
[英]"docker pull" requires exactly 1 argument error when using Gitlab Runner to deploy to Digital Ocean
晚上好,我正在嘗試部署我的 nodejs 應用程序並讓它使用 pm2 運行並使用 Docker,但是 Docker 正在拋出“”docker pull”需要恰好 1 個參數。請參閱“docker pull --help”。用法:docker pull [ OPTIONS] NAME[:TAG|@DIGEST] 從注冊表中拉取圖像或存儲庫”錯誤。 感謝您的幫助,感謝您的寶貴時間。
# ssh-keyscan gitlab.com >> authorized_keys: use this command to add gitlab ssh keys to sever. Run on server terminal # cat id_rsa.pub >> authorized_keys Run this command on the sever on the terminal. # Both COMMANDS ABOVE ARE necessary. 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-Node: 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 build-Docker: image: docker:latest stage: build 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: ubuntu:latest stage: deploy tags: - deployment before_script: ## ## Install ssh-agent if not already installed, it is required by Docker. ## (change apt-get to yum if you use an RPM-based image) ## - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client git -y )' ## ## Run ssh-agent (inside the build environment) ## - eval $(ssh-agent -s) ## ## Create the SSH directory and give it the right permissions ## - mkdir -p ~/.ssh - chmod 700 ~/.ssh ## ## Add the SSH key stored in SSH_PRIVATE_KEY variable to the agent store ## We're using tr to fix line endings which makes ed25519 keys work ## without extra base64 encoding. ## https://gitlab.com/gitlab-examples/ssh-private-key/issues/1#note_48526556 ## - echo "$SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_rsa - echo "$SSH_PUBLIC_KEY" | tr -d '\r' > ~/.ssh/id_rsa.pub - chmod 600 ~/.ssh/* - chmod 644 ~/.ssh/*.pub - ssh-add ## ## Use ssh-keyscan to scan the keys of your private server. Replace gitlab.com ## with your own domain name. You can copy and repeat that command if you have ## more than one server to connect to. ## - ssh-keyscan gitlab.com >> ~/.ssh/known_hosts - chmod 644 ~/.ssh/known_hosts - ls -ld ~/.ssh/* - cat ~/.ssh/* ## ## Alternatively, assuming you created the SSH_SERVER_HOSTKEYS variable ## previously, uncomment the following two lines instead. ## #- echo "$SSH_SERVER_HOSTKEYS" > ~/.ssh/known_hosts' #- chmod 644 ~/.ssh/known_hosts ## ## You can optionally disable host key checking. Be aware that by adding that ## you are suspectible to man-in-the-middle attacks. ## WARNING: Use this only with the Docker executor, if you use it with shell ## you will overwrite your user's SSH config. ## #- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config' ## ## Optionally, if you will be using any Git commands, set the user name and ## email. ## script: - ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP "docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY" - ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP 'docker pull $TAG_COMMIT' - ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP 'docker container rm -f my-app || true' - ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP 'docker run -d -p 80:3000 --name my-app $TAG_COMMIT' - ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP '. /etc/profile; pm2 reload all' environment: name: production url: http://167.172.225.124 only: - master
FROM node:12.18.3 # make the starting directory the current one WORKDIR / # COPY Package.json COPY package*.json / # install the dependencines within the app RUN npm install # Install pm2 RUN npm install pm2 -g # Copy Source Code COPY. . # Have docker container use port 3000, that is the port that the node app is set to EXPOSE 3000 # Start the node app CMD ["pm2-runtime", "./bin/www"]
錯誤信息:
"docker pull" requires exactly 1 argument
表示行:
ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP 'docker pull $TAG_COMMIT'
是不正確的。
$TAG_COMMIT
為空(因此沒有參數傳遞給docker pull
)$TAG_COMMIT
中有一個空格(使其成為兩個arguments 傳遞給docker pull
$TAG_COMMIT
未被其值替換,並在ssh 'docker pull $TAG_COMMIT'
session 中保持為空。ssh "docker pull $TAG_COMMIT"
),確保 shell 可以在將$TAG_COMMIT
發送到遠程 shell之前對其進行解釋。我會仔細檢查(回顯)以下值:
TAG_COMMIT: $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_NAME:$CI_COMMIT_SHORT_SHA
$CI_REGISTRY_IMAGE
,...) 這樣,我就能明白為什么傳遞給docker pull
的參數不正確。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.