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

Publish Yarn to the Alpine Linux package repository (APK) #1326

Closed
ide opened this issue Oct 21, 2016 · 66 comments
Closed

Publish Yarn to the Alpine Linux package repository (APK) #1326

ide opened this issue Oct 21, 2016 · 66 comments
Assignees

Comments

@ide
Copy link
Contributor

ide commented Oct 21, 2016

This is a feature request to publish Yarn to Alpine Linux's package repository. The primary motivation is to be able to more easily use Yarn when building Docker images built on top of Alpine Linux. (Alpine is a distro that's much lighter than Ubuntu and earlier this year there was some discussion that Docker was moving its official images to Alpine: https://www.brianchristner.io/docker-is-moving-to-alpine-linux/.)

Feb 2017 Edit: Following the discussion below, if you are running Alpine in a Docker image that already includes Node (ex: mhart/alpine-node:base-7), you might want to install Yarn by copying the files directly:

ENV YARN_VERSION 0.20.0
ADD https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v${YARN_VERSION}.tar.gz /opt/yarn.tar.gz
RUN yarnDirectory=/opt/yarn && \
    mkdir -p "$yarnDirectory" && \
    tar -xzf /opt/yarn.tar.gz -C "$yarnDirectory" && \
    ln -s "$yarnDirectory/dist/bin/yarn" /usr/local/bin/ && \
    rm /opt/yarn.tar.gz
@Daniel15
Copy link
Member

Hi James! 😄

Looks like fpm added support for Alpine Linux packages. We're already using fpm to build the CentOS/RHEL .rpm, so I should be able to build an Alpine Linux package too.

@SimenB
Copy link
Contributor

SimenB commented Nov 10, 2016

Any news here? There will be official Alpine images for node shortly (docker-library/official-images#2334), being able to install a self-contained yarn into that would be sweet

@Daniel15
Copy link
Member

I'll try to take a look this weekend.

It looks like Alpine only has Node.js 6.7.0 at the moment: https://pkgs.alpinelinux.org/package/v3.4/main/x86_64/nodejs. I guess that's fine, I wonder how well-maintained the Node.js packages are though.

@ide
Copy link
Contributor Author

ide commented Nov 10, 2016

https://github.com/mhart/alpine-node is a popular image that is regularly maintained. These Alpine images already have Node installed, apk add yarn just needs to install Yarn -- if it pulls in an extra copy of Node that defeats the purpose of using a small image like Alpine.

@SimenB
Copy link
Contributor

SimenB commented Nov 10, 2016

I'd prefer it if it just installed yarn yes, as it will only be used where Node is already available

@Daniel15
Copy link
Member

Sure, I can do that. I wonder if Alpine has something like a "recommends" relation between packages. Debian does that - We "recommend" the Node.js package, but people can ignore the recommendation if they have Node.js installed via alternate means (for example, nvm, or compiled from source).

@Daniel15
Copy link
Member

Daniel15 commented Nov 14, 2016

Currently blocked by jordansissel/fpm#1227

As an aside:

Alpine is a distro that's much lighter than Ubuntu

Have you considered using Debian? It's also much lighter than Ubuntu.

Daniel15 added a commit to Daniel15/yarn that referenced this issue Nov 14, 2016
@CpuID
Copy link

CpuID commented Dec 14, 2016

Have you considered using Debian? It's also much lighter than Ubuntu.

$ docker images | grep ubuntu
ubuntu    16.04               42118e3df429        4 months ago        124.8 MB
$ docker images | grep debian
debian     jessie              1b088884749b        6 months ago       125.1 MB
$ docker images | grep alpine
alpine      3.4                 4e38e38c8ce0        5 months ago      4.795 MB

Self explanatory.

@lukasoppermann
Copy link

Any news here?

@Daniel15
Copy link
Member

Daniel15 commented Dec 17, 2016 via email

@errm
Copy link
Contributor

errm commented Jan 13, 2017

I have an open PR to do this alpinelinux/aports#714

@errm
Copy link
Contributor

errm commented Jan 31, 2017

yarn package is now available in the alpine edge/testing repo
https://pkgs.alpinelinux.org/package/edge/testing/x86/yarn

@silverwind
Copy link

Indeed!

echo -e 'http://dl-cdn.alpinelinux.org/alpine/edge/main\nhttp://dl-cdn.alpinelinux.org/alpine/edge/community\nhttp://dl-cdn.alpinelinux.org/alpine/edge/testing' > /etc/apk/repositories
apk add --no-cache yarn

@Daniel15
Copy link
Member

@errm Thanks! is it possible to update the package to also patch the installationMethod in package.json? This key tells Yarn how it was installed, so that we can display the correct command to run if someone runs an outdated version of Yarn and we show an upgrade prompt.

@errm
Copy link
Contributor

errm commented Feb 1, 2017

yes I certainly can add that ...

@Daniel15
Copy link
Member

Daniel15 commented Feb 1, 2017

Cool, thanks. I'm going to close this out since the package exists now. Thank you so much, @errm!

@Daniel15 Daniel15 closed this as completed Feb 1, 2017
errm added a commit to errm/aports that referenced this issue Feb 1, 2017
errm added a commit to errm/aports that referenced this issue Feb 1, 2017
errm added a commit to errm/aports that referenced this issue Feb 1, 2017
errm added a commit to errm/aports that referenced this issue Feb 1, 2017
@amir20
Copy link

amir20 commented Feb 2, 2017

I get a strange behavior when doing

FROM mhart/alpine-node:7

RUN echo -e 'http://dl-cdn.alpinelinux.org/alpine/edge/main\nhttp://dl-cdn.alpinelinux.org/alpine/edge/community\nhttp://dl-cdn.alpinelinux.org/alpine/edge/testing' > /etc/apk/repositories \
    && apk add --no-cache yarn

node -v is now 6.9.5. Does anybody else have this problem?

@Daniel15
Copy link
Member

Daniel15 commented Feb 2, 2017

@amir20 You didn't mention what the strange behaviour actually is 😛

@silverwind
Copy link

silverwind commented Feb 5, 2017

Okay, this should give a pretty small container with yarn available everywhere:

FROM mhart/alpine-node:base

RUN apk add --no-cache curl && \
  mkdir -p /opt && \
  curl -sL https://yarnpkg.com/latest.tar.gz | tar xz -C /opt && \
  mv /opt/dist /opt/yarn && \
  ln -s /opt/yarn/bin/yarn /usr/local/bin && \
  apk del --purge curl

@Daniel15
Copy link
Member

Daniel15 commented Feb 6, 2017

@silverwind I'd suggest locking down the version of Yarn being used (like I did in my example above). Also if you're only using curl to download Yarn, you can instead just use ADD to download it, like in my example.

@silverwind
Copy link

I like using the latest one in this case so I don't have to maintain the version. And I'm not using ADD to avoid additional image layers 😉.

@SimenB
Copy link
Contributor

SimenB commented Feb 6, 2017

@silverwind If you use the latest version of Docker (1.13), you can do docker build -t node-yarn --squash . Which squashes all layers into the FROM. Which means you don't have to do the massive chains anymore 😄

https://github.com/docker/docker/releases/tag/v1.13.0

@errm
Copy link
Contributor

errm commented Feb 15, 2017

If you want node7 you can just install the nodejs-current package with apk

@mhart
Copy link

mhart commented Feb 15, 2017

@errm will that help the situation with yarn depending on nodejs though? Will apk recognize that nodejs-current is a substitute for nodejs?

@mhart
Copy link

mhart commented Feb 15, 2017

@errm oh – indeed it does:

/ # echo -e 'http://dl-cdn.alpinelinux.org/alpine/edge/main\nhttp://dl-cdn.alpinelinux.org/alpine/edge/community\nhttp://dl-cdn.alpinelinux.org/alpine/edge/testing' > /etc/apk/repositories
/ # apk add --no-cache nodejs-current yarn
fetch http://dl-cdn.alpinelinux.org/alpine/edge/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/edge/testing/x86_64/APKINDEX.tar.gz
(1/9) Installing ca-certificates (20161130-r0)
(2/9) Installing libcrypto1.0 (1.0.2k-r0)
(3/9) Installing libgcc (6.3.0-r1)
(4/9) Installing http-parser (2.7.1-r0)
(5/9) Installing libssl1.0 (1.0.2k-r0)
(6/9) Installing libstdc++ (6.3.0-r1)
(7/9) Installing libuv (1.10.2-r0)
(8/9) Installing nodejs-current (7.5.0-r0)
(9/9) Installing yarn (0.20.0-r0)
Executing busybox-1.25.1-r0.trigger
Executing ca-certificates-20161130-r0.trigger
OK: 67 MiB in 20 packages
/ # node --version
v7.5.0
/ # yarn --version
0.20.0

Nice! 👍

@mhart
Copy link

mhart commented Feb 15, 2017

I see, because APKBUILD supports a provides declaration:

http://git.alpinelinux.org/cgit/aports/tree/community/nodejs-current/APKBUILD#n17

@chapati23
Copy link

Still struggling with this one.

  1. Is there any way you can install yarn just once and then cache it on subsequent builds?
  2. Right now the "official" way of installing yarn is slower than my hand-baked one:
# Official way
RUN echo -e 'http://dl-cdn.alpinelinux.org/alpine/edge/main\nhttp://dl-cdn.alpinelinux.org/alpine/edge/community\nhttp://dl-cdn.alpinelinux.org/alpine/edge/testing' > /etc/apk/repositories && \
apk add --no-cache yarn
# Hand-baked
ENV YARN_VERSION 0.22.0
ENV YARN_DIR /opt/yarn
ADD https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v${YARN_VERSION}.tar.gz /opt/yarn.tar.gz
RUN mkdir -p $YARN_DIR && \
    tar -xzf /opt/yarn.tar.gz -C $YARN_DIR && \
    rm /opt/yarn.tar.gz

@Daniel15
Copy link
Member

Daniel15 commented Apr 11, 2017

Is there any way you can install yarn just once and then cache it on subsequent builds?

Depends on how you're running your builds. I'd suggest having a Docker image with everything required for your build, and then use that as part of your build system. That way, all dependencies are already preinstalled.

Right now the "official" way of installing yarn is slower than my hand-baked one

If you're using Docker, you should only need to install your dependencies once, and then all of your builds should use the resulting Docker image. That means that the slowness of installing Yarn should only be an issue once (or rather, once for every time you update the Dockerfile). You'll likely need to publish the Docker image to the Docker Hub to use it.

Also your hand baked once isn't performing any integrity checking via GPG - You should at least add that. The GPG key is available at https://dl.yarnpkg.com/debian/pubkey.gpg and the signature is at https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v${YARN_VERSION}.tar.gz.asc. You can see how the installation script does it for ideas: https://github.com/yarnpkg/website/blob/master/install.sh#L46

@chapati23
Copy link

@Daniel15 thanks, very helpful and good point on integrity checking. i've reverted back to the official way for now.

last 2 things i'm not sure about is handling the yarn.lock file and the yarn cache. is this the way to go: https://hackernoon.com/using-yarn-with-docker-c116ad289d56 ?

seems pretty complex compared to just using good old npm

@Daniel15
Copy link
Member

seems pretty complex compared to just using good old npm

I don't think handling the Yarn cache would be any more difficult than handling the npm cache... I'm not familiar enough with Docker to know the best way to handle Yarn's cache.

@wclr
Copy link
Contributor

wclr commented Apr 23, 2017

I'm running on mhart/alpine-node:7.1.0

/ # echo -e 'http://dl-cdn.alpinelinux.org/alpine/edge/main\nhttp://dl-cdn.alpinelinux.org/alpine/edge/community\nhttp:/
/dl-cdn.alpinelinux.org/alpine/edge/testing' > /etc/apk/repositories
/ # apk add --no-cache yarn
fetch http://dl-cdn.alpinelinux.org/alpine/edge/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/edge/testing/x86_64/APKINDEX.tar.gz
(1/6) Installing libressl2.5-libcrypto (2.5.3-r0)
(2/6) Installing ca-certificates (20161130-r2)
(3/6) Installing http-parser (2.7.1-r1)
(4/6) Installing libuv (1.11.0-r1)
(5/6) Installing nodejs (6.10.1-r0)
(6/6) Installing yarn (0.23.2-r0)
Executing busybox-1.24.2-r13.trigger
Executing ca-certificates-20161130-r2.trigger
OK: 49 MiB in 19 packages
/ # yarn
yarn install v0.23.2
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
Done in 0.38s.
/ # node -v
v6.10.1

Why I yarn installing and replacing node installed?

@Daniel15
Copy link
Member

I think doing apk add nodejs-current yarn will get you 7.x instead of 6.x, but you'll need to ask the maintainer of the Alpine package (see https://pkgs.alpinelinux.org/package/edge/community/x86/yarn)

@mhart
Copy link

mhart commented Apr 23, 2017

@whitecolor because node in the base image wasn't installed using apk – so the yarn apk package knows nothing about it

@mhart
Copy link

mhart commented Apr 23, 2017

@whitecolor you should install yarn manually if you want to use that docker image – see these comments: #1326 (comment) or #1326 (comment)

@ide
Copy link
Contributor Author

ide commented Jun 5, 2017

Thanks to @mhart, Yarn is now included in the alpine-node (v8+) Docker image: mhart/alpine-node#65 (comment). This is especially useful since we've found some issues with npm 5 so having an alternative out of the box is great.

@wclr
Copy link
Contributor

wclr commented Jun 5, 2017

Now images should be updated more often) as Yarn and NPM5 still have a lot of minor bugs

@wclr
Copy link
Contributor

wclr commented Jul 1, 2017

Isn't there automatic publishing in alipne repo? https://pkgs.alpinelinux.org/packages?name=yarn&branch=&repo=&arch=&maintainer=

The latest available version is still 0.24

@Daniel15
Copy link
Member

Daniel15 commented Jul 1, 2017

The Alpine repo is community maintained; it's not maintained by the Yarn team. You'd need to contact its maintainer to get the package updated.

@andregomars
Copy link

RUN apk update
RUN apk add yarn

@errm
Copy link
Contributor

errm commented Jan 16, 2018

Hi I am the maintainer of the alpine package... I have been tracking the stable version of yarn. Feel free to ping me if I miss an update.

The latest release of alpine linux (3.7) includes yarn 1.3.2

Note that unless there is a security issue, the version included in 3.7 won't be updated... to get newer versions (when they become stable) you will need to wait for a new release of alpine (roughly every 6 months) or use the edge version (not recommended for a production system).

@deadhexagon
Copy link

For those coming here from search results and are looking to install yarn from Alpine repos, it is indeed included in v3.7. Since it wasn't mentioned here, you need to enable the community repo in /etc/apk/repositories. Just uncomment that line, then run: apk update and apk add yarn as root.

NodeJS is already available in the main repo and is v8.9.3, so no worries there.

Thank you @errm for maintaining this.

@damien-roche
Copy link

Having a lot of fun between this and Webpack 4! :P

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

No branches or pull requests