Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Unable to to use Wrangler in CI (BitBucket Pipeline) #529

Closed
matthew-petrie opened this issue Sep 6, 2019 · 5 comments
Closed

Unable to to use Wrangler in CI (BitBucket Pipeline) #529

matthew-petrie opened this issue Sep 6, 2019 · 5 comments
Assignees

Comments

@matthew-petrie
Copy link

matthew-petrie commented Sep 6, 2019

Is it possible to install Wrangler in a CI/CD environment, spcifically BitBucket Pipelines in our case?

If we do npm i @cloudflare/wrangler -g the installation fails with Error: EACCES: permission denied, mkdir '/root/.wrangler':

npm i @cloudflare/wrangler -g
/usr/local/bin/wrangler -> /usr/local/lib/node_modules/@cloudflare/wrangler/run-wrangler.js
> @cloudflare/wrangler@1.2.0 postinstall /usr/local/lib/node_modules/@cloudflare/wrangler
> node install-wrangler.js
fs.js:126
    throw err;
    ^
Error: EACCES: permission denied, mkdir '/root/.wrangler'
    at mkdirSync (fs.js:764:3)
    at Object.<anonymous> (/usr/local/lib/node_modules/@cloudflare/wrangler/install-wrangler.js:60:3)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:643:32)
    at Function.Module._load (internal/modules/cjs/loader.js:556:12)
    at Function.Module.runMain (internal/modules/cjs/loader.js:839:10)
    at internal/main/run_main_module.js:17:11 {
  errno: -13,
  syscall: 'mkdir',
  code: 'EACCES',
  path: '/root/.wrangler'
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @cloudflare/wrangler@1.2.0 postinstall: `node install-wrangler.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @cloudflare/wrangler@1.2.0 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

If we do npm i @cloudflare/wrangler it installs (installation logs below) but when you try to then run wrangler publish --release we receive bash: wrangler: command not found:

npm i @cloudflare/wrangler
> sleep@6.1.0 install /opt/atlassian/pipelines/agent/build/node_modules/sleep
> node-gyp rebuild
make: Entering directory '/opt/atlassian/pipelines/agent/build/node_modules/sleep/build'
  CXX(target) Release/obj.target/node_sleep/module_init.o
  CXX(target) Release/obj.target/node_sleep/sleep_cpp11.o
  CXX(target) Release/obj.target/node_sleep/sleep_posix.o
  CXX(target) Release/obj.target/node_sleep/sleep_win.o
  SOLINK_MODULE(target) Release/obj.target/node_sleep.node
  COPY Release/node_sleep.node
make: Leaving directory '/opt/atlassian/pipelines/agent/build/node_modules/sleep/build'
> protobufjs@6.8.8 postinstall /opt/atlassian/pipelines/agent/build/node_modules/protobufjs
> node scripts/postinstall
> @cloudflare/wrangler@1.2.0 postinstall /opt/atlassian/pipelines/agent/build/node_modules/@cloudflare/wrangler
> node install-wrangler.js
Downloading release https://github.com/cloudflare/wrangler/releases/download/v1.2.0/wrangler-v1.2.0-x86_64-unknown-linux-musl.tar.gz
Wrangler has been installed!
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
> @cloudflare/wrangler@1.2.0
added 624 packages from 465 contributors and audited 875670 packages in 16.926s
found 0 vulnerabilities

The above is using a Node 12.6.0 container image, I've also tried a Node 8-jessie image too and changing the user the container is running as to no avail.

Thanks very much!

@EverlastingBugstopper
Copy link
Contributor

Hey @Matthew1534 - we recommend installing node/npm with a version manager like nvm. Could you try uninstalling node/npm and reinstalling with nvm and then installing wrangler afterwards? Please update if that works! Thanks for the report

@matthew-petrie
Copy link
Author

Hey @EverlastingBugstopper - thanks for the above super quick reply. I've now managed to get this working using a debian container image and running the below commands:

apt-get update
apt-get -y install wget
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
source ~/.bashrc
nvm install 12.6.0
npm config set user 0
npm config set unsafe-perm true
npm i @cloudflare/wrangler -g
export CF_API_KEY=$CF_API_KEY
export CF_EMAIL=$CF_EMAIL
wrangler publish --release

We get a sh: 1: node: Permission denied error unless we run npm config set unsafe-perm true which doesn't seem so great?

Thanks :)

@EverlastingBugstopper
Copy link
Contributor

You can likely get around this by not running these commands as root. Hope this helps :)

@matthew-petrie
Copy link
Author

thanks!

@jamesnuanez
Copy link

The best way I found to install Wrangler via Bitbucket Pipelines was to set the npm user to root:

script:
- npm -g config set user root
- npm install -g packagename

Source: https://stackoverflow.com/a/54290720/8742362

Full bitbucket-pipelines.yml

image: node:10.15.3

pipelines:
  default:
    - step:
      caches:
        - node
      script:
        - npm -g config set user root
        - npm install -g @cloudflare/wrangler
        - npm install
        - npm run export
        - echo $CLOUDFLARE_API_TOKEN | wrangler config
        - mv wrangler-sample.toml wrangler.toml
        - sed -i "s/account_id = \"\"/account_id = \"${CLOUDFLARE_ACCOUNT_ID}\"/" wrangler.toml
        - sed -i "s/zone_id = \"\"/zone_id = \"${CLOUDFLARE_ZONE_ID}\"/" wrangler.toml
        - wrangler publish

Requires a wrangler-sample.toml file with empty account_id and zone_id, and 3 environment variables:

  • CLOUDFLARE_API_TOKEN
  • CLOUDFLARE_ACCOUNT_ID
  • CLOUDFLARE_ZONE_ID

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants