Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make yarn available as an alternative package manager or provide a way to install it. #42

Closed
phawxby opened this issue May 23, 2018 · 16 comments

Comments

@phawxby
Copy link

phawxby commented May 23, 2018

We use Yarn as the package manager of choice on all our applications. We're now trying to deploy our first application to Azure and have found Yarn is not available and there seems to be no easy way to install it.

Our application references other repo's via git submodules which also use Yarn so we cannot just switch back to npm and I don't think maintaining npm lock and a yarn lock files in parallel is a sensible idea.

Your competitors already support Yarn or provide an easy path to installing it.
https://devcenter.heroku.com/changelog-items/1065
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/ebextensions.html

@shaunakv1
Copy link

+1 on that request.

@xt0rted
Copy link

xt0rted commented May 25, 2018

This was brought up awhile back in projectkudu/kudu#2176 but unfortunately their response was to use npm to install yarn 😕

In the end I moved all of my stuff over to build & package on appveyor and then deploy it via a zip file containing the ready to go site or functions. Azure/azure-functions-pack also helped simplify things a bit.

@phawxby
Copy link
Author

phawxby commented May 25, 2018

Yep, I knew it had come up before but rather than poke at a long dead thread I thought I'd create a new one. Although npm 5 did drastically improve things yarn is still significantly better in terms of performance.

Although I cannot find any numbers as to usage levels the github numbers suggest that yarn is just as popular, perhaps even more popular than NPM now.
https://github.com/npm/npm
https://github.com/yarnpkg/yarn

As for deployment I've taken a similar path to you using CircleCI, build everything there and zip deploy. I hadn't heard of the azure functions pack so thanks for that, I'll have a poke around. Although I must admit the engagement in the issues doesn't give me a feeling that it'll be part of long term support.

@tony-gutierrez
Copy link

Yarn is even more desirable on app services due to the frequent failure of npm on app services. For some reason it sometimes fails to install all packages, yet says "up to date". You have to manually force it to reinstall. I think its something to do with the local cache getting corrupted due to the slow storage.

@tony-gutierrez
Copy link

Was able to use yarn by following the code from this issue, combined with the repo it is in. "
stefangordon/kudu-yarn#1

@pure180
Copy link

pure180 commented May 28, 2019

This is an approach using Linux App Services.
projectkudu/kudu#2176 (comment)

@phawxby
Copy link
Author

phawxby commented Jul 18, 2019

@patricklee2 I created the PR above as we had an incident last week where the binaries installed via CircleCI and those required by Azure were different and our site broke. My thinking was lets get Yarn installed on Azure by default then I don't have to do that anymore.

I started working on a branch in anticipation of the PR being merged in and got this.
image

When did Yarn get added to the base image and why wasn't this thread updated?

Edit
Ok, it's there but broken.

image

@tony-gutierrez
Copy link

tony-gutierrez commented Jul 18, 2019

I switched to yarn a while back, and eventually had to abandon it. The multi threaded downloads and installs overwhelmed the app service. It would lose all network ability and the install would time out.

Edit: exactly what was posted above... Network timeouts.

@phawxby
Copy link
Author

phawxby commented Jul 18, 2019

sigh Ok, lets see if we can get an official word from Microsoft on the matter.

Edit. For any support people reading this, I've got ticket 119071822001841 open.

@tony-gutierrez
Copy link

If you're doing node on Windows app service, I'd recommend you jump ship early. Yarn is going to be the least of your problems. If you stay, make sure you log http errors in your CLIENTS, as they will get 500 errors that your server will never clue you in to, even with app insights.

@phawxby
Copy link
Author

phawxby commented Jul 18, 2019

We're using Linux, and we're logging extensively via NewRelic and Loggly. We know every response leaving the host.

In other news, I got it working!

  1. Add this to the deploy.sh script in place of npm install
  yarn config delete proxy
  yarn install --production --network-timeout 300000
  1. Do not include any archives (like yarn offline cache) within your application. If Azure sees any archives it assumes it must a compressed node_modules file. Why that is not node_modules.zip I do not know.
2019-07-18T16:25:22.290936765Z echo "Checking if node_modules was compressed..."
2019-07-18T16:25:22.290941366Z case $compressedNodeModulesFile in 
2019-07-18T16:25:22.290945966Z     *".zip")
2019-07-18T16:25:22.290950366Z         echo "Found zip-based node_modules."
2019-07-18T16:25:22.290954966Z         extractionCommand="unzip -q $compressedNodeModulesFile -d /node_modules"
2019-07-18T16:25:22.290959566Z         ;;
2019-07-18T16:25:22.290963966Z     *".tar.gz")
2019-07-18T16:25:22.290968467Z         echo "Found tar.gz based node_modules."
2019-07-18T16:25:22.290972867Z         extractionCommand="tar -xzf $compressedNodeModulesFile -C /node_modules"
2019-07-18T16:25:22.290977467Z          ;;

@appsvc can I rely on this undocumented bit of yarn-ness?

@sanchitmehta
Copy link
Contributor

sanchitmehta commented Jul 18, 2019

@phawxby @tony-gutierrez for AppService on Linux, we use Oryx Build System. Oryx now supports yarn.

You could also try the default yarn builds on Kudu. For node based installations on Linux, we compress the node_modules after a build and store the name of this compressed archive as node_modules.zip in a manifest. This archive is then extracted during the run-time, we changed this behavior to ensure faster build times and optimize app start-up time as well. So the runtime images check for node_modules.zip in wwwroot but if it's any other archive in your app having a name other than this reserved name it should just work fine. Let us know if you face any issues.

@phawxby
Copy link
Author

phawxby commented Jul 18, 2019

@sanchitmehta does this mean we're safe to use Yarn on app service? It's not going to disappear and break things?

@phawxby
Copy link
Author

phawxby commented Jul 19, 2019

Working deploy.sh

#!/bin/bash

# ----------------------
# KUDU Deployment Script
# Version: 1.0.15
# ----------------------

# Helpers
# -------

exitWithMessageOnError () {
  if [ ! $? -eq 0 ]; then
    echo "An error has occurred during web site deployment."
    echo $1
    exit 1
  fi
}

# Prerequisites
# -------------

# Verify node.js installed
hash node 2>/dev/null
exitWithMessageOnError "Missing node.js executable, please install node.js, if already installed make sure it can be reached from current environment."

# Setup
# -----

SCRIPT_DIR="${BASH_SOURCE[0]%\\*}"
SCRIPT_DIR="${SCRIPT_DIR%/*}"
ARTIFACTS=$SCRIPT_DIR/../artifacts
KUDU_SYNC_CMD=${KUDU_SYNC_CMD//\"}

if [[ ! -n "$DEPLOYMENT_SOURCE" ]]; then
  DEPLOYMENT_SOURCE=$SCRIPT_DIR
fi

if [[ ! -n "$NEXT_MANIFEST_PATH" ]]; then
  NEXT_MANIFEST_PATH=$ARTIFACTS/manifest

  if [[ ! -n "$PREVIOUS_MANIFEST_PATH" ]]; then
    PREVIOUS_MANIFEST_PATH=$NEXT_MANIFEST_PATH
  fi
fi

if [[ ! -n "$DEPLOYMENT_TARGET" ]]; then
  DEPLOYMENT_TARGET=$ARTIFACTS/wwwroot
else
  KUDU_SERVICE=true
fi

if [[ ! -n "$KUDU_SYNC_CMD" ]]; then
  # Install kudu sync
  echo Installing Kudu Sync
  npm install kudusync -g --silent
  exitWithMessageOnError "npm failed"

  if [[ ! -n "$KUDU_SERVICE" ]]; then
    # In case we are running locally this is the correct location of kuduSync
    KUDU_SYNC_CMD=kuduSync
  else
    # In case we are running on kudu service this is the correct location of kuduSync
    KUDU_SYNC_CMD=$APPDATA/npm/node_modules/kuduSync/bin/kuduSync
  fi
fi

# Node Helpers
# ------------
selectNodeVersion () {
  if [[ -n "$KUDU_SELECT_NODE_VERSION_CMD" ]]; then
    SELECT_NODE_VERSION="$KUDU_SELECT_NODE_VERSION_CMD \"$DEPLOYMENT_SOURCE\" \"$DEPLOYMENT_TARGET\" \"$DEPLOYMENT_TEMP\""
    eval $SELECT_NODE_VERSION
    exitWithMessageOnError "select node version failed"

    if [[ -e "$DEPLOYMENT_TEMP/__nodeVersion.tmp" ]]; then
      NODE_EXE=`cat "$DEPLOYMENT_TEMP/__nodeVersion.tmp"`
      exitWithMessageOnError "getting node version failed"
    fi

    if [[ -e "$DEPLOYMENT_TEMP/__npmVersion.tmp" ]]; then
      NPM_JS_PATH=`cat "$DEPLOYMENT_TEMP/__npmVersion.tmp"`
      exitWithMessageOnError "getting npm version failed"
    fi

    if [[ ! -n "$NODE_EXE" ]]; then
      NODE_EXE=node
    fi

    NPM_CMD="\"$NODE_EXE\" \"$NPM_JS_PATH\""
  else
    NPM_CMD=npm
    NODE_EXE=node
  fi
}

# Install dependencies
# ------------
installDependencies () {
  cd "$DEPLOYMENT_TARGET"

  if [ -e "$DEPLOYMENT_TARGET/yarn.lock" ]; then
    echo "Running yarn install --production"
    eval yarn config delete proxy
    eval yarn install --production --network-timeout 300000
    exitWithMessageOnError "yarn install failed"
  else
    echo "Running $NPM_CMD install --production"
    eval $NPM_CMD install --production
    exitWithMessageOnError "$NPM_CMD install failed"
  fi
}

##################################################################################################################################
# Deployment
# ----------

echo Handling node.js deployment.

echo "# 1. KuduSync"
if [[ "$IN_PLACE_DEPLOYMENT" -ne "1" ]]; then
  "$KUDU_SYNC_CMD" -v 50 -f "$DEPLOYMENT_SOURCE" -t "$DEPLOYMENT_TARGET" -n "$NEXT_MANIFEST_PATH" -p "$PREVIOUS_MANIFEST_PATH" -i ".git;.hg;.deployment;deploy.sh"
  exitWithMessageOnError "Kudu Sync failed"
fi

echo "# 2. Select node version"
selectNodeVersion

echo "# 3. Install dependencies"
installDependencies

##################################################################################################################################
echo "Finished successfully."

@patricklee2
Copy link
Contributor

added

@phawxby
Copy link
Author

phawxby commented Dec 2, 2019

For those that stumble into my deployment script above and/or using their own Yarn deployment script, please be aware of this environment problem which could cause your deployments to misbehave.

projectkudu/KuduScript#113 (comment)

FreakinWard added a commit to FreakinWard/nextjs-boilerplate that referenced this issue Jun 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants