Merge ~peppepetra/grafana-snap:lp1999071 into grafana-snap:master

Proposed by Giuseppe Petralia
Status: Merged
Merged at revision: a14d21ed8f7978641eeefecbd39f36c97a131914
Proposed branch: ~peppepetra/grafana-snap:lp1999071
Merge into: grafana-snap:master
Diff against target: 49 lines (+25/-10)
1 file modified
snapcraft.yaml (+25/-10)
Reviewer Review Type Date Requested Status
Erhan Sunar (community) Approve
Gabriel Cocenza Approve
Eric Chen Pending
BootStack Reviewers Pending
Review via email: mp+434261@code.launchpad.net

Commit message

Install nodejs/npm from official repo

Closes-Bug: #1999071

To post a comment you must log in.
Revision history for this message
Giuseppe Petralia (peppepetra) wrote :
Revision history for this message
Gabriel Cocenza (gabrielcocenza) wrote :

LGTM

review: Approve
Revision history for this message
Erhan Sunar (esunar) :
review: Approve
Revision history for this message
Martin Kalcok (martin-kalcok) wrote :

I have just one observation, I don't think it's blocker.
I was recently working on a snap that was building a js app with yarn and it was enough to include "node" in "stage-snaps" so maybe there's no need to have this complicated manual installation in "override-build".

Also, if this snap is meant to be installed in environment with proxy (for example launchpad's snap farm) the yarn needs to have proxy settings explicitly configured (just something to consider.)

This snippet is an example that worked for me:
```
  web-interface:
    plugin: dump
    source: ./<path_to_js_app>/
    override-build: |
      npm install --global yarn
      set +u
      if [[ -n $http_proxy ]]; then yarn config set httpProxy $http_proxy; fi
      if [[ -n $https_proxy ]]; then yarn config set httpsProxy $https_proxy; fi
      set -u
      yarn install
      yarn build
      cp -r dist $SNAPCRAFT_PART_INSTALL/
    organize:
      dist: web-ui
    stage-snaps:
      - node
```

Revision history for this message
Eric Chen (eric-chen) wrote :

After confirm with Giuseppe, he wants to revisit this with Martin suggestions
Change the status to WIP

Revision history for this message
Giuseppe Petralia (peppepetra) wrote (last edit ):

I looked at Martin suggestion, unfortunately grafana 7.5.17 requires node 14 to build [1] and the snap 14/stable is not available for all the archs supported by the charm so I can't use stage-snaps.

1. https://github.com/grafana/grafana/blob/v7.5.17/contribute/developer-guide.md

2. https://snapcraft.io/node

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/snapcraft.yaml b/snapcraft.yaml
2index 97d5228..edcbf60 100644
3--- a/snapcraft.yaml
4+++ b/snapcraft.yaml
5@@ -55,19 +55,34 @@ parts:
6 source: https://github.com/grafana/grafana.git
7 source-tag: v${SNAPCRAFT_PROJECT_VERSION}
8 build-packages: [curl,python2-minimal,python2-dev]
9+ build-environment:
10+ - NODE_VERSION: "14.15.5"
11 override-build: |
12 set -x
13- curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
14- apt install -y nodejs
15+ # install the official nodejs
16+ if [ $SNAP_ARCH == "amd64" ]; then
17+ ARCH=x64
18+ elif [ $SNAP_ARCH == "armhf" ]; then
19+ ARCH=armv7l
20+ elif [ $SNAP_ARCH == "ppc64el" ]; then
21+ ARCH=ppc64le
22+ else
23+ ARCH=$SNAP_ARCH
24+ fi
25+
26+ NODE_URI="https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-${ARCH}.tar.gz"
27+ echo Fetching: $NODE_URI
28+ if [ ! -f "${SNAPCRAFT_PART_BUILD}/bin/node" ]; then
29+ curl $NODE_URI | tar xzf - -C $SNAPCRAFT_PART_BUILD/ --no-same-owner --strip-components=1
30+ fi
31+
32+ # Add nodejs/npm to the path
33+ export PATH=${SNAPCRAFT_PART_BUILD}/bin:${PATH}
34+
35+ npm config set unsafe-perm true
36+
37 npm install --global yarn patch-package
38- # on arm, s390x, and ppc systems remove phantomjs as required from the
39- # package.json and yarn lock as it's not available from npm on those
40- # architectures
41- ARCH=$(uname -m)
42- case $ARCH in
43- arm*|s390*|ppc*)
44- yarn remove phantomjs-prebuilt --ignore-workspace-root-check;;
45- esac
46+
47 export PYTHON=/usr/bin/python2
48 PATH="$PATH:$SNAPCRAFT_PART_BUILD/node_modules/.bin:$SNAPCRAFT_PART_INSTALL/bin"
49 NODE_ENV="production"

Subscribers

People subscribed via source and target branches

to all changes: