部署到 DigitalOcean 时 GitHub 操作失败

Posted

技术标签:

【中文标题】部署到 DigitalOcean 时 GitHub 操作失败【英文标题】:GitHub action fails when deploying to DigitalOcean 【发布时间】:2021-02-05 21:14:09 【问题描述】:

我在尝试通过 github 操作部署到 DigitalOcean 时遇到错误,我不确定它为什么对 python 大喊大叫。是因为我使用的 docker 图像吗?我已经尝试在 droplet 上安装 python 版本,尽管这可能与它无关。

这里是有问题的 dockerfile:

FROM node:alpine3.12 as build

WORKDIR /usr/src/app
COPY package*.json ./
RUN yarn cache clean && yarn --update-checksums
COPY . ./
RUN yarn && yarn build

# Stage - Production
FROM nginx:1.17-alpine
COPY --from=build /usr/src/app/build /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

这是用于操作的 deploy.yml 文件:

name: build

on:
  push:
    branches:
      - master

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - name: Use Node.js 13.10
        uses: actions/setup-node@v1
        with:
          node-version: '13.10'
      - name: Install yarn and run unittest
        run: |
          yarn
          yarn test
        env:
          CI: true
      - name: Publish to Github Packages Registry
        uses: elgohr/Publish-Docker-Github-Action@master
        with:
          name: fanzypantz/onepole/onepole
          registry: docker.pkg.github.com
          username: $ secrets.USERNAME 
          password: $ secrets.GITHUB_TOKEN 
          dockerfile: Dockerfile-prod
          tags: latest
      - name: Deploy package to digitalocean
        uses: appleboy/ssh-action@master
        env:
          GITHUB_USERNAME: $ secrets.USERNAME 
          GITHUB_TOKEN: $ secrets.GITHUB_TOKEN 
        with:
          host: $ secrets.HOST 
          username: $ secrets.USERNAME 
          password: $ secrets.PASSWORD 
          port: $ secrets.PORT 
          envs: GITHUB_USERNAME, GITHUB_TOKEN
          script: |
            docker stop $(docker ps -a -q)
            docker login docker.pkg.github.com -u $GITHUB_USERNAME -p $GITHUB_TOKEN
            docker pull docker.pkg.github.com/fanzypantz/onepole/onepole:latest
            docker run -dit -p 80:80 docker.pkg.github.com/fanzypantz/onepole/onepole:latest

来自 github 操作的错误

Step 1/10 : FROM node:alpine3.12 as build
alpine3.12: Pulling from library/node
188c0c94c7c5: Pulling fs layer
9e35e0178777: Pulling fs layer
90f5366a8ab8: Pulling fs layer
39095b5b3547: Pulling fs layer
39095b5b3547: Waiting
188c0c94c7c5: Verifying Checksum
188c0c94c7c5: Download complete
188c0c94c7c5: Pull complete
90f5366a8ab8: Download complete
9e35e0178777: Verifying Checksum
9e35e0178777: Download complete
39095b5b3547: Verifying Checksum
39095b5b3547: Download complete
9e35e0178777: Pull complete
90f5366a8ab8: Pull complete
39095b5b3547: Pull complete
Digest: sha256:96683bc4c05c2cb2c3bee957cdf7b967051323dafb937301d4b9fac30e529d7a
Status: Downloaded newer image for node:alpine3.12
 ---> 8f99f65ba94a
Step 2/10 : WORKDIR /usr/src/app
 ---> Running in 8fa7d7cacf45
Removing intermediate container 8fa7d7cacf45
 ---> 9d3dddf518f7
Step 3/10 : COPY package*.json ./
 ---> ee091cf8a93a
Step 4/10 : RUN yarn cache clean && yarn --update-checksums
 ---> Running in d03b8ed6e52a
yarn cache v1.***.5
success Cleared cache.
Done in 0.04s.
yarn install v1.***.5
info No lockfile found.
[1/4] Resolving packages...
warning @testing-library/jest-dom > css > urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
warning @testing-library/jest-dom > css > source-map-resolve > urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
warning @testing-library/jest-dom > css > source-map-resolve > resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
warning @testing-library/react > @types/testing-library__react > @types/testing-library__dom@7.5.0: This is a stub types definition. testing-library__dom provides its own type definitions, so you do not need this installed.
warning node-sass > request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
warning node-sass > node-gyp > request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
warning node-sass > request > har-validator@5.1.5: this library is no longer supported
warning react-scripts > eslint-loader@3.0.3: This loader has been deprecated. Please use eslint-webpack-plugin
warning react-scripts > jest-environment-jsdom-fourteen > jsdom > request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
warning react-scripts > webpack-dev-server > chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
warning react-scripts > webpack-dev-server > chokidar > fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
warning react-scripts > babel-jest > @jest/transform > jest-haste-map > fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
warning react-scripts > jest-environment-jsdom-fourteen > jsdom > request-promise-native@1.0.9: request-promise-native has been deprecated because it extends the now deprecated request package, see https://github.com/request/request/issues/3142
warning react-scripts > workbox-webpack-plugin > workbox-build > @hapi/joi@15.1.1: joi is leaving the @hapi organization and moving back to 'joi' (https://github.com/sideway/joi/issues/2411)
warning react-scripts > webpack > watchpack > watchpack-chokidar2 > chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
warning react-scripts > jest > jest-cli > jest-config > jest-environment-jsdom > jsdom > request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
warning react-scripts > jest > jest-cli > jest-config > jest-environment-jsdom > jsdom > request-promise-native@1.0.9: request-promise-native has been deprecated because it extends the now deprecated request package, see https://github.com/request/request/issues/3142
warning react-scripts > workbox-webpack-plugin > workbox-build > @hapi/joi > @hapi/topo@3.1.6: This version has been deprecated and is no longer supported or maintained
warning react-scripts > workbox-webpack-plugin > workbox-build > @hapi/joi > @hapi/hoek@8.5.1: This version has been deprecated and is no longer supported or maintained
warning react-scripts > workbox-webpack-plugin > workbox-build > @hapi/joi > @hapi/topo > @hapi/hoek@8.5.1: This version has been deprecated and is no longer supported or maintained
warning react-scripts > workbox-webpack-plugin > workbox-build > @hapi/joi > @hapi/bourne@1.3.2: This version has been deprecated and is no longer supported or maintained
warning react-scripts > workbox-webpack-plugin > workbox-build > @hapi/joi > @hapi/address@2.1.4: This version has been deprecated and is no longer supported or maintained
warning react-scripts > jest > jest-cli > jest-config > jest-environment-jsdom > jsdom > left-pad@1.3.0: use String.prototype.padStart()
warning react-scripts > workbox-webpack-plugin > workbox-build > strip-comments > babel-plugin-transform-object-rest-spread > babel-runtime > core-js@2.6.11: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
[2/4] Fetching packages...
info fsevents@2.1.2: The platform "linux" is incompatible with this module.
info "fsevents@2.1.2" is an optional dependency and failed compatibility check. Excluding it from installation.
info fsevents@1.2.13: The platform "linux" is incompatible with this module.
info "fsevents@1.2.13" is an optional dependency and failed compatibility check. Excluding it from installation.
info fsevents@2.1.3: The platform "linux" is incompatible with this module.
info "fsevents@2.1.3" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning " > @testing-library/user-event@7.2.1" has unmet peer dependency "@testing-library/dom@>=5".
warning "react-scripts > @typescript-eslint/eslint-plugin > tsutils@3.17.1" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta".
[4/4] Building fresh packages...
error /usr/src/app/node_modules/node-sass: Command failed.
Exit code: 1
Command: node scripts/build.js
Arguments: 
Directory: /usr/src/app/node_modules/node-sass
Output:
Building: /usr/local/bin/node /usr/src/app/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
gyp info it worked if it ends with ok
gyp verb cli [
gyp verb cli   '/usr/local/bin/node',
gyp verb cli   '/usr/src/app/node_modules/node-gyp/bin/node-gyp.js',
gyp verb cli   'rebuild',
gyp verb cli   '--verbose',
gyp verb cli   '--libsass_ext=',
gyp verb cli   '--libsass_cflags=',
gyp verb cli   '--libsass_ldflags=',
gyp verb cli   '--libsass_library='
gyp verb cli ]
gyp info using node-gyp@3.8.0
gyp info using node@15.0.0 | linux | x64
gyp verb command rebuild []
gyp verb command clean []
gyp verb clean removing "build" directory
gyp verb command configure []
gyp verb check python checking for Python executable "python2" in the PATH
gyp verb `which` failed Error: not found: python2
gyp verb `which` failed     at getNotFoundError (/usr/src/app/node_modules/which/which.js:13:12)
gyp verb `which` failed     at F (/usr/src/app/node_modules/which/which.js:68:19)
gyp verb `which` failed     at E (/usr/src/app/node_modules/which/which.js:80:29)
gyp verb `which` failed     at /usr/src/app/node_modules/which/which.js:89:16
gyp verb `which` failed     at /usr/src/app/node_modules/isexe/index.js:42:5
gyp verb `which` failed     at /usr/src/app/node_modules/isexe/mode.js:8:5
gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:183:21)
gyp verb `which` failed  python2 Error: not found: python2
gyp verb `which` failed     at getNotFoundError (/usr/src/app/node_modules/which/which.js:13:12)
gyp verb `which` failed     at F (/usr/src/app/node_modules/which/which.js:68:19)
gyp verb `which` failed     at E (/usr/src/app/node_modules/which/which.js:80:29)
gyp verb `which` failed     at /usr/src/app/node_modules/which/which.js:89:16
gyp verb `which` failed     at /usr/src/app/node_modules/isexe/index.js:42:5
gyp verb `which` failed     at /usr/src/app/node_modules/isexe/mode.js:8:5
gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:183:21) 
gyp verb `which` failed   code: 'ENOENT'
gyp verb `which` failed 
gyp verb check python checking for Python executable "python" in the PATH
gyp verb `which` failed Error: not found: python
gyp verb `which` failed     at getNotFoundError (/usr/src/app/node_modules/which/which.js:13:12)
gyp verb `which` failed     at F (/usr/src/app/node_modules/which/which.js:68:19)
gyp verb `which` failed     at E (/usr/src/app/node_modules/which/which.js:80:29)
gyp verb `which` failed     at /usr/src/app/node_modules/which/which.js:89:16
gyp verb `which` failed     at /usr/src/app/node_modules/isexe/index.js:42:5
gyp verb `which` failed     at /usr/src/app/node_modules/isexe/mode.js:8:5
gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:183:21)
gyp verb `which` failed  python Error: not found: python
gyp verb `which` failed     at getNotFoundError (/usr/src/app/node_modules/which/which.js:13:12)
gyp verb `which` failed     at F (/usr/src/app/node_modules/which/which.js:68:19)
gyp verb `which` failed     at E (/usr/src/app/node_modules/which/which.js:80:29)
gyp verb `which` failed     at /usr/src/app/node_modules/which/which.js:89:16
gyp verb `which` failed     at /usr/src/app/node_modules/isexe/index.js:42:5
gyp verb `which` failed     at /usr/src/app/node_modules/isexe/mode.js:8:5
gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:183:21) 
gyp verb `which` failed   code: 'ENOENT'
gyp verb `which` failed 
gyp ERR! configure error 
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
gyp ERR! stack     at PythonFinder.failNoPython (/usr/src/app/node_modules/node-gyp/lib/configure.js:484:19)
gyp ERR! stack     at PythonFinder.<anonymous> (/usr/src/app/node_modules/node-gyp/lib/configure.js:406:16)
gyp ERR! stack     at F (/usr/src/app/node_modules/which/which.js:68:16)
gyp ERR! stack     at E (/usr/src/app/node_modules/which/which.js:80:29)
gyp ERR! stack     at /usr/src/app/node_modules/which/which.js:89:16
gyp ERR! stack     at /usr/src/app/node_modules/isexe/index.js:42:5
gyp ERR! stack     at /usr/src/app/node_modules/isexe/mode.js:8:5
gyp ERR! stack     at FSReqCallback.oncomplete (node:fs:183:21)
gyp ERR! System Linux 5.4.0-1031-azure
gyp ERR! command "/usr/local/bin/node" "/usr/src/app/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /usr/src/app/node_modules/node-sass
gyp ERR! node -v v15.0.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 
Build failed with error code: 1
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
The command '/bin/sh -c yarn cache clean && yarn --update-checksums' returned a non-zero code: 1

【问题讨论】:

【参考方案1】:

您在sass/node-sass issue 2447 中遇到了同样的错误,作为解决方案:

我upgraded to the latest webpacker gem 并且错误消失了

bundle update webpacker
rails webpacker:binstubs
yarn upgrade @rails/webpacker --latest
yarn upgrade webpack-dev-server --latest

但那是因为,对于那个问题,链接步骤开始时的问题涉及webpacker

在你的情况下,你会看到

[3/4] Linking dependencies...
warning " > @testing-library/user-event@7.2.1" has unmet peer dependency "@testing-library/dom@>=5".
warning "react-scripts > @typescript-eslint/eslint-plugin > tsutils@3.17.1" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta".

所以先尝试升级你的 Docker 镜像:

testing-library/user-event react-scripts

检查更新这些依赖项后问题是否仍然存在。

最后,考虑到错误“check python checking for Python executable "python2" in the PATH”,确保所有进程使用Python2,而不是Python3。

【讨论】:

确实删除了 3/4 警告。 4/4 仍然发生完全相同的错误。 @AndreasHalvorsenTollånes“检查 Python 检查 PATH 中的 Python 可执行文件“python2””:也许您的图像默认只有 Python3,而缺少 Python2? 这似乎是使用 node:alpine3.12 的情况,试图在容器上手动安装它。但在一个图像上出现 apt-get 不可用和另一个找不到 python2 等问题。 我设法使用其他一些图像使其工作,即 node:14:13.1-slim 因此它与我的节点版本匹配,服务器部分使用 nginx 1.18.0-alpine。【参考方案2】:

问题是 docker 图像没有我需要的一切。

这是帮助 med 启动它的项目的更新后的 dockerfile-prod

FROM node:14.13.1-slim as build

WORKDIR /usr/src/app
COPY package*.json ./
RUN yarn cache clean && yarn --update-checksums
COPY . ./
RUN yarn && yarn build

# Stage - Production
FROM nginx:1.18.0-alpine
COPY --from=build /usr/src/app/build /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

【讨论】:

以上是关于部署到 DigitalOcean 时 GitHub 操作失败的主要内容,如果未能解决你的问题,请参考以下文章

使用 Django 和 Mailchimp 的电子邮件订阅表单在部署后不起作用 (DigitalOcean)

设置 GitLab CI/CD 以将多个存储库部署到 DigitalOcean Droplet 上的 Docker 容器

如何在 Live Server (Digital Ocean) 中部署 Angular App?

如何在 digitalocean 中显示 laravel api 错误?

在 DigitalOcean ubuntu 服务器上托管闪亮的应用程序时出错

在 digitalocean 上部署后未加载静态文件